2011-07-07 08:21:25 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
2011-08-01 17:04:04 +00:00
|
|
|
#ifndef WEBRTC_SYSTEM_WRAPPERS_SOURCE_EVENT_POSIX_H_
|
|
|
|
|
#define WEBRTC_SYSTEM_WRAPPERS_SOURCE_EVENT_POSIX_H_
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-10-28 18:17:40 +01:00
|
|
|
#include "webrtc/system_wrappers/include/event_wrapper.h"
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-04-26 03:13:22 -07:00
|
|
|
#include <memory>
|
|
|
|
|
|
2011-07-07 08:21:25 +00:00
|
|
|
#include <pthread.h>
|
|
|
|
|
#include <time.h>
|
|
|
|
|
|
2015-11-23 14:47:56 -08:00
|
|
|
#include "webrtc/base/platform_thread.h"
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
2012-12-10 10:44:37 +00:00
|
|
|
enum State {
|
|
|
|
|
kUp = 1,
|
|
|
|
|
kDown = 2
|
|
|
|
|
};
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-04-08 11:24:19 +02:00
|
|
|
class EventTimerPosix : public EventTimerWrapper {
|
2012-12-10 10:44:37 +00:00
|
|
|
public:
|
2015-04-08 11:24:19 +02:00
|
|
|
EventTimerPosix();
|
|
|
|
|
~EventTimerPosix() override;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-03-04 12:58:35 +00:00
|
|
|
EventTypeWrapper Wait(unsigned long max_time) override;
|
|
|
|
|
bool Set() override;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-03-04 12:58:35 +00:00
|
|
|
bool StartTimer(bool periodic, unsigned long time) override;
|
|
|
|
|
bool StopTimer() override;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2012-12-10 10:44:37 +00:00
|
|
|
private:
|
2016-03-22 01:51:39 -07:00
|
|
|
friend class EventTimerPosixTest;
|
|
|
|
|
|
2015-03-19 14:35:58 +00:00
|
|
|
static bool Run(void* obj);
|
2012-12-10 10:44:37 +00:00
|
|
|
bool Process();
|
2016-03-22 01:51:39 -07:00
|
|
|
EventTypeWrapper Wait(timespec* end_at, bool reset_state);
|
|
|
|
|
|
|
|
|
|
virtual rtc::PlatformThread* CreateThread();
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2012-12-10 10:44:37 +00:00
|
|
|
pthread_cond_t cond_;
|
|
|
|
|
pthread_mutex_t mutex_;
|
2015-03-17 13:11:15 +00:00
|
|
|
bool event_set_;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-04-26 03:13:22 -07:00
|
|
|
// TODO(pbos): Remove unique_ptr and use PlatformThread directly.
|
|
|
|
|
std::unique_ptr<rtc::PlatformThread> timer_thread_;
|
|
|
|
|
std::unique_ptr<EventTimerPosix> timer_event_;
|
2012-12-10 10:44:37 +00:00
|
|
|
timespec created_at_;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2012-12-10 10:44:37 +00:00
|
|
|
bool periodic_;
|
2016-03-22 01:51:39 -07:00
|
|
|
unsigned long time_ms_;
|
2012-12-10 10:44:37 +00:00
|
|
|
unsigned long count_;
|
2016-03-22 01:51:39 -07:00
|
|
|
bool is_stopping_;
|
2011-07-07 08:21:25 +00:00
|
|
|
};
|
|
|
|
|
|
2012-12-10 10:44:37 +00:00
|
|
|
} // namespace webrtc
|
|
|
|
|
|
|
|
|
|
#endif // WEBRTC_SYSTEM_WRAPPERS_SOURCE_EVENT_POSIX_H_
|