niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
ajm@google.com | b5c49ff | 2011-08-01 17:04:04 +0000 | [diff] [blame] | 11 | #ifndef WEBRTC_SYSTEM_WRAPPERS_SOURCE_EVENT_POSIX_H_ |
| 12 | #define WEBRTC_SYSTEM_WRAPPERS_SOURCE_EVENT_POSIX_H_ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 13 | |
Henrik Kjellander | 98f5351 | 2015-10-28 18:17:40 +0100 | [diff] [blame] | 14 | #include "webrtc/system_wrappers/include/event_wrapper.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 15 | |
| 16 | #include <pthread.h> |
| 17 | #include <time.h> |
| 18 | |
pbos | 12411ef | 2015-11-23 14:47:56 -0800 | [diff] [blame] | 19 | #include "webrtc/base/platform_thread.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 20 | |
| 21 | namespace webrtc { |
phoglund@webrtc.org | 5bbe069 | 2012-12-10 10:44:37 +0000 | [diff] [blame] | 22 | |
| 23 | enum State { |
| 24 | kUp = 1, |
| 25 | kDown = 2 |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 26 | }; |
| 27 | |
Peter Boström | 64c0366 | 2015-04-08 11:24:19 +0200 | [diff] [blame] | 28 | class EventTimerPosix : public EventTimerWrapper { |
phoglund@webrtc.org | 5bbe069 | 2012-12-10 10:44:37 +0000 | [diff] [blame] | 29 | public: |
Peter Boström | 64c0366 | 2015-04-08 11:24:19 +0200 | [diff] [blame] | 30 | EventTimerPosix(); |
| 31 | ~EventTimerPosix() override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 32 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 33 | EventTypeWrapper Wait(unsigned long max_time) override; |
| 34 | bool Set() override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 35 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 36 | bool StartTimer(bool periodic, unsigned long time) override; |
| 37 | bool StopTimer() override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 38 | |
phoglund@webrtc.org | 5bbe069 | 2012-12-10 10:44:37 +0000 | [diff] [blame] | 39 | private: |
sprang | 53cf346 | 2016-03-22 01:51:39 -0700 | [diff] [blame] | 40 | friend class EventTimerPosixTest; |
| 41 | |
tommi@webrtc.org | 27c0be9 | 2015-03-19 14:35:58 +0000 | [diff] [blame] | 42 | static bool Run(void* obj); |
phoglund@webrtc.org | 5bbe069 | 2012-12-10 10:44:37 +0000 | [diff] [blame] | 43 | bool Process(); |
sprang | 53cf346 | 2016-03-22 01:51:39 -0700 | [diff] [blame] | 44 | EventTypeWrapper Wait(timespec* end_at, bool reset_state); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 45 | |
sprang | 53cf346 | 2016-03-22 01:51:39 -0700 | [diff] [blame] | 46 | virtual rtc::PlatformThread* CreateThread(); |
| 47 | |
phoglund@webrtc.org | 5bbe069 | 2012-12-10 10:44:37 +0000 | [diff] [blame] | 48 | pthread_cond_t cond_; |
| 49 | pthread_mutex_t mutex_; |
pbos@webrtc.org | a846371 | 2015-03-17 13:11:15 +0000 | [diff] [blame] | 50 | bool event_set_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 51 | |
Peter Boström | 8c38e8b | 2015-11-26 17:45:47 +0100 | [diff] [blame] | 52 | // TODO(pbos): Remove scoped_ptr and use PlatformThread directly. |
| 53 | rtc::scoped_ptr<rtc::PlatformThread> timer_thread_; |
Peter Boström | 64c0366 | 2015-04-08 11:24:19 +0200 | [diff] [blame] | 54 | rtc::scoped_ptr<EventTimerPosix> timer_event_; |
phoglund@webrtc.org | 5bbe069 | 2012-12-10 10:44:37 +0000 | [diff] [blame] | 55 | timespec created_at_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 56 | |
phoglund@webrtc.org | 5bbe069 | 2012-12-10 10:44:37 +0000 | [diff] [blame] | 57 | bool periodic_; |
sprang | 53cf346 | 2016-03-22 01:51:39 -0700 | [diff] [blame] | 58 | unsigned long time_ms_; |
phoglund@webrtc.org | 5bbe069 | 2012-12-10 10:44:37 +0000 | [diff] [blame] | 59 | unsigned long count_; |
sprang | 53cf346 | 2016-03-22 01:51:39 -0700 | [diff] [blame] | 60 | bool is_stopping_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 61 | }; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 62 | |
phoglund@webrtc.org | 5bbe069 | 2012-12-10 10:44:37 +0000 | [diff] [blame] | 63 | } // namespace webrtc |
| 64 | |
| 65 | #endif // WEBRTC_SYSTEM_WRAPPERS_SOURCE_EVENT_POSIX_H_ |