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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef SYSTEM_WRAPPERS_SOURCE_EVENT_POSIX_H_ |
| 12 | #define SYSTEM_WRAPPERS_SOURCE_EVENT_POSIX_H_ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 13 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 14 | #include "system_wrappers/include/event_wrapper.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 15 | |
jbauch | 555604a | 2016-04-26 03:13:22 -0700 | [diff] [blame] | 16 | #include <memory> |
| 17 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 18 | #include <pthread.h> |
| 19 | #include <time.h> |
| 20 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 21 | #include "rtc_base/platform_thread.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 22 | |
| 23 | namespace webrtc { |
phoglund@webrtc.org | 5bbe069 | 2012-12-10 10:44:37 +0000 | [diff] [blame] | 24 | |
Karl Wiberg | 79eb1d9 | 2017-11-08 12:26:07 +0100 | [diff] [blame^] | 25 | enum State { kUp = 1, kDown = 2 }; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 26 | |
Peter Boström | 64c0366 | 2015-04-08 11:24:19 +0200 | [diff] [blame] | 27 | class EventTimerPosix : public EventTimerWrapper { |
phoglund@webrtc.org | 5bbe069 | 2012-12-10 10:44:37 +0000 | [diff] [blame] | 28 | public: |
Peter Boström | 64c0366 | 2015-04-08 11:24:19 +0200 | [diff] [blame] | 29 | EventTimerPosix(); |
| 30 | ~EventTimerPosix() override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 31 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 32 | EventTypeWrapper Wait(unsigned long max_time) override; |
| 33 | bool Set() override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 34 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 35 | bool StartTimer(bool periodic, unsigned long time) override; |
| 36 | bool StopTimer() override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 37 | |
phoglund@webrtc.org | 5bbe069 | 2012-12-10 10:44:37 +0000 | [diff] [blame] | 38 | private: |
sprang | 53cf346 | 2016-03-22 01:51:39 -0700 | [diff] [blame] | 39 | friend class EventTimerPosixTest; |
| 40 | |
tommi@webrtc.org | 27c0be9 | 2015-03-19 14:35:58 +0000 | [diff] [blame] | 41 | static bool Run(void* obj); |
phoglund@webrtc.org | 5bbe069 | 2012-12-10 10:44:37 +0000 | [diff] [blame] | 42 | bool Process(); |
sprang | 53cf346 | 2016-03-22 01:51:39 -0700 | [diff] [blame] | 43 | EventTypeWrapper Wait(timespec* end_at, bool reset_state); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 44 | |
sprang | 53cf346 | 2016-03-22 01:51:39 -0700 | [diff] [blame] | 45 | virtual rtc::PlatformThread* CreateThread(); |
| 46 | |
Karl Wiberg | 79eb1d9 | 2017-11-08 12:26:07 +0100 | [diff] [blame^] | 47 | pthread_cond_t cond_; |
phoglund@webrtc.org | 5bbe069 | 2012-12-10 10:44:37 +0000 | [diff] [blame] | 48 | pthread_mutex_t mutex_; |
pbos@webrtc.org | a846371 | 2015-03-17 13:11:15 +0000 | [diff] [blame] | 49 | bool event_set_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 50 | |
jbauch | 555604a | 2016-04-26 03:13:22 -0700 | [diff] [blame] | 51 | // TODO(pbos): Remove unique_ptr and use PlatformThread directly. |
| 52 | std::unique_ptr<rtc::PlatformThread> timer_thread_; |
| 53 | std::unique_ptr<EventTimerPosix> timer_event_; |
Karl Wiberg | 79eb1d9 | 2017-11-08 12:26:07 +0100 | [diff] [blame^] | 54 | timespec created_at_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 55 | |
Karl Wiberg | 79eb1d9 | 2017-11-08 12:26:07 +0100 | [diff] [blame^] | 56 | bool periodic_; |
sprang | 53cf346 | 2016-03-22 01:51:39 -0700 | [diff] [blame] | 57 | unsigned long time_ms_; |
phoglund@webrtc.org | 5bbe069 | 2012-12-10 10:44:37 +0000 | [diff] [blame] | 58 | unsigned long count_; |
sprang | 53cf346 | 2016-03-22 01:51:39 -0700 | [diff] [blame] | 59 | bool is_stopping_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 60 | }; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 61 | |
phoglund@webrtc.org | 5bbe069 | 2012-12-10 10:44:37 +0000 | [diff] [blame] | 62 | } // namespace webrtc |
| 63 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 64 | #endif // SYSTEM_WRAPPERS_SOURCE_EVENT_POSIX_H_ |