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 11 #ifndef WEBRTC_SYSTEM_WRAPPERS_SOURCE_EVENT_POSIX_H_ 12 #define WEBRTC_SYSTEM_WRAPPERS_SOURCE_EVENT_POSIX_H_ 13 14 #include "webrtc/system_wrappers/interface/event_wrapper.h" 15 16 #include <pthread.h> 17 #include <time.h> 18 19 #include "webrtc/system_wrappers/interface/thread_wrapper.h" 20 21 namespace webrtc { 22 23 enum State { 24 kUp = 1, 25 kDown = 2 26 }; 27 28 class EventPosix : public EventWrapper { 29 public: 30 static EventWrapper* Create(); 31 32 virtual ~EventPosix(); 33 34 virtual EventTypeWrapper Wait(unsigned long max_time) OVERRIDE; 35 virtual bool Set() OVERRIDE; 36 virtual bool Reset() OVERRIDE; 37 38 virtual bool StartTimer(bool periodic, unsigned long time) OVERRIDE; 39 virtual bool StopTimer() OVERRIDE; 40 41 private: 42 EventPosix(); 43 int Construct(); 44 45 static bool Run(ThreadObj obj); 46 bool Process(); 47 EventTypeWrapper Wait(timespec& wake_at); 48 49 private: 50 pthread_cond_t cond_; 51 pthread_mutex_t mutex_; 52 53 ThreadWrapper* timer_thread_; 54 EventPosix* timer_event_; 55 timespec created_at_; 56 57 bool periodic_; 58 unsigned long time_; // In ms 59 unsigned long count_; 60 State state_; 61 }; 62 63 } // namespace webrtc 64 65 #endif // WEBRTC_SYSTEM_WRAPPERS_SOURCE_EVENT_POSIX_H_ 66