forked from Haivision/srt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsync_timer.h
More file actions
44 lines (35 loc) · 980 Bytes
/
sync_timer.h
File metadata and controls
44 lines (35 loc) · 980 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "sync.h" // Requires CEvent
namespace srt
{
namespace sync
{
class CTimer
{
public:
CTimer();
~CTimer();
public:
/// Causes the current thread to block until
/// the specified time is reached.
/// Sleep can be interrupted by calling interrupt()
/// or woken up to recheck the scheduled time by tick()
/// @param tp target time to sleep until
///
/// @return true if the specified time was reached
/// false should never happen
bool sleep_until(steady_clock::time_point tp);
/// Resets target wait time and interrupts waiting
/// in sleep_until(..)
void interrupt();
/// Wakes up waiting thread (sleep_until(..)) without
/// changing the target waiting time to force a recheck
/// of the current time in comparison to the target time.
void tick();
private:
CEvent m_event;
sync::AtomicClock<steady_clock> m_tsSchedTime;
void wait_busy();
void wait_stalled();
};
}
}