blob: 17d193f2be91ad239e9f4197eba83f4c71e8f934 [file] [log] [blame]
niklase@google.comf0779a22011-05-30 11:39:38 +00001/*
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_LINUX_H_
12#define WEBRTC_SYSTEM_WRAPPERS_SOURCE_EVENT_LINUX_H_
13
14#include "event_wrapper.h"
15
16#include <pthread.h>
17#include <time.h>
18
19#include "thread_wrapper.h"
20
21namespace webrtc {
22enum State
23{
24 kUp = 1,
25 kDown = 2
26};
27
28class EventLinux : public EventWrapper
29{
30public:
31 static EventWrapper* Create();
32
33 virtual ~EventLinux();
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
42private:
43 EventLinux();
44 int Construct();
45
46 static bool Run(ThreadObj obj);
47 bool Process();
48 EventTypeWrapper Wait(timespec& tPulse);
49
50
51private:
52 pthread_cond_t cond;
53 pthread_mutex_t mutex;
54
55 ThreadWrapper* _timerThread;
56 EventLinux* _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_LINUX_H_