-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathabstracer.cpp
96 lines (87 loc) · 1.94 KB
/
abstracer.cpp
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include "abstracer.h"
#include <assert.h>
//A windows implementation of posix gettimeofday() from GroupsockHelper.cpp in live555 project
static int gettimeofday(struct timeval* tp, int* /*tz*/) {
LARGE_INTEGER tickNow;
static LARGE_INTEGER tickFrequency;
static BOOL tickFrequencySet = FALSE;
if (tickFrequencySet == FALSE) {
QueryPerformanceFrequency(&tickFrequency);
tickFrequencySet = TRUE;
}
QueryPerformanceCounter(&tickNow);
tp->tv_sec = (long) (tickNow.QuadPart / tickFrequency.QuadPart);
tp->tv_usec = (long) (((tickNow.QuadPart % tickFrequency.QuadPart) * 1000000L) / tickFrequency.QuadPart);
return 0;
}
abstracer::abstracer(void)
{
has_msg = false;
has_frame = false;
m_loglevel = LL_REPORT;
}
abstracer::~abstracer(void)
{
}
void abstracer::wait( int millisec )
{
timeval timer_start;
gettimeofday(&timer_start, NULL);
yield();
for(;;){
timeval now;
gettimeofday(&now, NULL);
int msdiff = (int)(((double)now.tv_sec - timer_start.tv_sec)*1000.+((double)now.tv_usec - timer_start.tv_usec)/1000.0);
if (msdiff < millisec) {
Sleep(1);
yield();
}
else {
break;
}
}
}
void abstracer::wait()
{
yield();
}
bool abstracer::wait( HANDLE hevent, int timeout_millisec )
{
timeval timer_start;
gettimeofday(&timer_start, NULL);
yield();
for(;;){
timeval now;
gettimeofday(&now, NULL);
int msdiff = (int)(((double)now.tv_sec - timer_start.tv_sec)*1000.+((double)now.tv_usec - timer_start.tv_usec)/1000.0);
if (msdiff < timeout_millisec) {
if (WaitForSingleObject(hevent, 1) == WAIT_OBJECT_0) {
return true;
}
yield();
}
else {
return false;
}
}
}
bool abstracer::peek_logmsg( std::string& msg, log_level& ll )
{
if (has_msg) {
msg = m_logmsg;
ll = m_loglevel;
has_msg = false;
return true;
}
else {
return false;
}
}
void abstracer::logmsg( std::string& msg, log_level ll )
{
assert(has_msg == false && "logmsg unpeeked");
m_logmsg = msg;
m_loglevel = ll;
has_msg = true;
yield();
}