-
Notifications
You must be signed in to change notification settings - Fork 0
/
Platform.cpp
62 lines (50 loc) · 1.18 KB
/
Platform.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
#include "Platform.h"
#ifdef __PLATFORM_LINUX__
//#include <atomic.h>
#include <sys/select.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#include <pthread.h>
void Sleep(long long nMiniSecods)
{
#if 0
struct timeval delay;
delay.tv_sec = 0;
delay.tv_usec = nMiniSecods * 1000; // 20 ms
select(0, NULL, NULL, NULL, &delay);
#endif
if (nMiniSecods > 1800*1000)
{
sleep(nMiniSecods/1000);
}
else
{
usleep(nMiniSecods*1000);
}
}
// static atomic_t atomic_number;
#else
#include <windows.h>
void gettimeofday(struct timeval* tp)
{
#ifdef NGX_WIN32
DWORD dt = timeGetTime(); // ´íÎó´úÂëÏî
tp->tv_sec = (long) (dt / 1000);
tp->tv_usec = (long) (dt*1000);
#else
ULONGLONG usec;
FILETIME ft;
SYSTEMTIME st;
GetSystemTime(&st);
SystemTimeToFileTime(&st, &ft);
usec = ft.dwHighDateTime;
usec <<= 32;
usec |= ft.dwLowDateTime;
usec /= 10;
usec -= 11644473600000000LL;
tp->tv_sec = (long) (usec / 1000000);
tp->tv_usec = (long) (usec % 1000000);
#endif // NGX_WIN32
}
#endif