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 "event_wrapper.h" 15 16 #include <pthread.h> 17 #include <time.h> 18 19 #include "thread_wrapper.h" 20 21 namespace webrtc { 22 enum State 23 { 24 kUp = 1, 25 kDown = 2 26 }; 27 28 class EventPosix : public EventWrapper 29 { 30 public: 31 static EventWrapper* Create(); 32 33 virtual ~EventPosix(); 34 35 virtual EventTypeWrapper Wait(unsigned long maxTime); 36 virtual bool Set(); 37 virtual bool Reset(); 38 39 virtual bool StartTimer(bool periodic, unsigned long time); 40 virtual bool StopTimer(); 41 42 private: 43 EventPosix(); 44 int Construct(); 45 46 static bool Run(ThreadObj obj); 47 bool Process(); 48 EventTypeWrapper Wait(timespec& tPulse); 49 50 51 private: 52 pthread_cond_t cond; 53 pthread_mutex_t mutex; 54 55 ThreadWrapper* _timerThread; 56 EventPosix* _timerEvent; 57 timespec _tCreate; 58 59 bool _periodic; 60 unsigned long _time; // In ms 61 unsigned long _count; 62 State _state; 63 }; 64 } // namespace webrtc 65 66 #endif // WEBRTC_SYSTEM_WRAPPERS_SOURCE_EVENT_POSIX_H_ 67