@@ -74,24 +74,45 @@ os_thread_t * os_thread_create (
7474 return handle ;
7575}
7676
77- uint32_t os_get_current_time_us (void )
77+ static uint64_t os_get_frequency_tick (void )
7878{
79- static LARGE_INTEGER performanceFrequency = {0 };
80- LARGE_INTEGER currentCount ;
81- uint64_t currentTime ;
82-
83- if (performanceFrequency .QuadPart == 0 )
79+ static uint64_t frequency ;
80+ if (frequency == 0 )
8481 {
82+ LARGE_INTEGER performanceFrequency ;
8583 timeBeginPeriod (URESOLUTION );
8684 QueryPerformanceFrequency (& performanceFrequency );
87- performanceFrequency . QuadPart = performanceFrequency .QuadPart / ( 1000 * 1000 ) ;
85+ frequency = performanceFrequency .QuadPart ;
8886 }
87+ return frequency ;
88+ }
8989
90+ uint32_t os_get_current_time_us (void )
91+ {
92+ LARGE_INTEGER currentCount ;
93+ uint64_t currentTime ;
9094 QueryPerformanceCounter (& currentCount );
91- currentTime = currentCount .QuadPart / performanceFrequency . QuadPart ;
95+ currentTime = 1000000 * currentCount .QuadPart / os_get_frequency_tick () ;
9296 return (uint32_t )(currentTime & UINT32_MAX );
9397}
9498
99+ os_tick_t os_tick_current (void )
100+ {
101+ LARGE_INTEGER currentCount ;
102+ QueryPerformanceCounter (& currentCount );
103+ return currentCount .QuadPart ;
104+ }
105+
106+ os_tick_t os_tick_from_us (uint32_t us )
107+ {
108+ return os_get_frequency_tick () * us / 1000000 ;
109+ }
110+
111+ void os_tick_sleep (os_tick_t tick )
112+ {
113+ Sleep (1000u * tick / os_get_frequency_tick ());
114+ }
115+
95116os_sem_t * os_sem_create (size_t count )
96117{
97118 os_sem_t * sem ;
0 commit comments