blob: 593e8a4600b951a0179fa1493e14db2aad72bb42 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +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
ajm@google.comb5c49ff2011-08-01 17:04:04 +000011#ifndef WEBRTC_SYSTEM_WRAPPERS_SOURCE_EVENT_POSIX_H_
12#define WEBRTC_SYSTEM_WRAPPERS_SOURCE_EVENT_POSIX_H_
niklase@google.com470e71d2011-07-07 08:21:25 +000013
phoglund@webrtc.org5bbe0692012-12-10 10:44:37 +000014#include "webrtc/system_wrappers/interface/event_wrapper.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000015
16#include <pthread.h>
17#include <time.h>
18
phoglund@webrtc.org5bbe0692012-12-10 10:44:37 +000019#include "webrtc/system_wrappers/interface/thread_wrapper.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000020
21namespace webrtc {
phoglund@webrtc.org5bbe0692012-12-10 10:44:37 +000022
23enum State {
24 kUp = 1,
25 kDown = 2
niklase@google.com470e71d2011-07-07 08:21:25 +000026};
27
Peter Boström64c03662015-04-08 11:24:19 +020028class EventTimerPosix : public EventTimerWrapper {
phoglund@webrtc.org5bbe0692012-12-10 10:44:37 +000029 public:
Peter Boström64c03662015-04-08 11:24:19 +020030 EventTimerPosix();
31 ~EventTimerPosix() override;
niklase@google.com470e71d2011-07-07 08:21:25 +000032
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000033 EventTypeWrapper Wait(unsigned long max_time) override;
34 bool Set() override;
niklase@google.com470e71d2011-07-07 08:21:25 +000035
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000036 bool StartTimer(bool periodic, unsigned long time) override;
37 bool StopTimer() override;
niklase@google.com470e71d2011-07-07 08:21:25 +000038
phoglund@webrtc.org5bbe0692012-12-10 10:44:37 +000039 private:
tommi@webrtc.org27c0be92015-03-19 14:35:58 +000040 static bool Run(void* obj);
phoglund@webrtc.org5bbe0692012-12-10 10:44:37 +000041 bool Process();
pbos@webrtc.orga8463712015-03-17 13:11:15 +000042 EventTypeWrapper Wait(timespec* end_at);
niklase@google.com470e71d2011-07-07 08:21:25 +000043
phoglund@webrtc.org5bbe0692012-12-10 10:44:37 +000044 private:
45 pthread_cond_t cond_;
46 pthread_mutex_t mutex_;
pbos@webrtc.orga8463712015-03-17 13:11:15 +000047 bool event_set_;
niklase@google.com470e71d2011-07-07 08:21:25 +000048
tommi@webrtc.org361981f2015-03-19 14:44:18 +000049 rtc::scoped_ptr<ThreadWrapper> timer_thread_;
Peter Boström64c03662015-04-08 11:24:19 +020050 rtc::scoped_ptr<EventTimerPosix> timer_event_;
phoglund@webrtc.org5bbe0692012-12-10 10:44:37 +000051 timespec created_at_;
niklase@google.com470e71d2011-07-07 08:21:25 +000052
phoglund@webrtc.org5bbe0692012-12-10 10:44:37 +000053 bool periodic_;
54 unsigned long time_; // In ms
55 unsigned long count_;
niklase@google.com470e71d2011-07-07 08:21:25 +000056};
niklase@google.com470e71d2011-07-07 08:21:25 +000057
phoglund@webrtc.org5bbe0692012-12-10 10:44:37 +000058} // namespace webrtc
59
60#endif // WEBRTC_SYSTEM_WRAPPERS_SOURCE_EVENT_POSIX_H_