-
Notifications
You must be signed in to change notification settings - Fork 26
/
win_utils.c
63 lines (55 loc) · 1.17 KB
/
win_utils.c
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
#include "common.h"
#include "controller.h"
#ifdef _WIN32
static int duration_ms;
void timer_thread(void *parg)
{
MSG Msg;
UINT_PTR TimerId = SetTimer(NULL, 0, duration_ms, (TIMERPROC)timer_fired);
while(GetMessage(&Msg, NULL, 0, 0))
DispatchMessage(&Msg);
_endthread();
}
void run_test_timer(int duration)
{
duration_ms = 1000*duration;
_beginthread(timer_thread, 0, NULL);
}
double time_in_usec(void)
{
LARGE_INTEGER Time, Frequency;
QueryPerformanceFrequency(&Frequency);
QueryPerformanceCounter(&Time);
return ((Time.QuadPart * 1000000)/Frequency.QuadPart);
}
static int vasprintf(char **strp, const char *format, va_list ap)
{
int len = _vscprintf(format, ap);
if (len == -1)
return -1;
char *str = (char*)malloc((size_t) len + 1);
if (!str)
return -1;
int rv = vsnprintf(str, len + 1, format, ap);
if (rv == -1) {
free(str);
return -1;
}
*strp = str;
return rv;
}
int asprintf(char **strp, const char *format, ...)
{
va_list ap;
va_start(ap, format);
int rv = vasprintf(strp, format, ap);
va_end(ap);
return rv;
}
int set_affinity(int cpuid)
{
if (0 == SetProcessAffinityMask(GetCurrentProcess(), (UINT_PTR)1 << cpuid))
return 0;
return 1;
}
#endif