File tree Expand file tree Collapse file tree 1 file changed +28
-1
lines changed
Expand file tree Collapse file tree 1 file changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -23,10 +23,37 @@ namespace std {
2323
2424}
2525
26+ #if defined(_WIN32) || defined(WIN32)
27+ static inline LARGE_INTEGER GetFrequency ()
28+ {
29+ LARGE_INTEGER frequency;
30+ QueryPerformanceFrequency (&frequency);
31+ return frequency;
32+ }
33+
34+ static uint32_t GetCurrentSysTime ()
35+ {
36+ HANDLE current_thread = GetCurrentThread ();
37+ DWORD_PTR previous_mask = SetThreadAffinityMask (current_thread, 1 );
38+
39+ static const LARGE_INTEGER frequency = GetFrequency ();
40+
41+ // Get the current time
42+ LARGE_INTEGER time;
43+ QueryPerformanceCounter (&time);
44+
45+ // Restore the thread affinity
46+ SetThreadAffinityMask (current_thread, previous_mask);
47+
48+ // Return the current time as miliseconds
49+ return static_cast <uint32_t >(1000000LL * time.QuadPart / frequency.QuadPart );
50+ }
51+ #else
2652static uint32_t GetCurrentSysTime ()
2753{
2854 // POSIX implementation
2955 timespec time;
3056 clock_gettime (CLOCK_MONOTONIC, &time);
3157 return static_cast <uint32_t >(uint64_t (time.tv_sec ) * 1000000 + time.tv_nsec / 1000 );
32- }
58+ }
59+ #endif
You can’t perform that action at this time.
0 commit comments