Branch data Line data Source code
1 : : // This file is a part of Julia. License is MIT: https://julialang.org/license 2 : : 3 : : #include <assert.h> 4 : : 5 : : #include "dtypes.h" 6 : : 7 : : #if defined(_OS_WINDOWS_) 8 : : #include <sys/timeb.h> 9 : : #else 10 : : #include <sys/time.h> 11 : : #include <sys/select.h> 12 : : #endif 13 : : 14 : : #include "timefuncs.h" 15 : : 16 : : #ifdef __cplusplus 17 : : extern "C" { 18 : : #endif 19 : : 20 : 1958 : JL_DLLEXPORT int jl_gettimeofday(struct jl_timeval *jtv) 21 : : { 22 : : #if defined(_OS_WINDOWS_) 23 : : struct __timeb64 tb; 24 : : errno_t code = _ftime64_s(&tb); 25 : : jtv->sec = tb.time; 26 : : jtv->usec = tb.millitm * 1000; 27 : : #else 28 : : struct timeval tv; 29 : 1958 : int code = gettimeofday(&tv, NULL); 30 : 1958 : jtv->sec = tv.tv_sec; 31 : 1958 : jtv->usec = tv.tv_usec; 32 : : #endif 33 : 1958 : return code; 34 : : } 35 : : 36 : 1890 : JL_DLLEXPORT double jl_clock_now(void) 37 : : { 38 : : struct jl_timeval now; 39 : 1890 : jl_gettimeofday(&now); 40 : 1890 : return now.sec + now.usec * 1e-6; 41 : : } 42 : : 43 : 0 : void sleep_ms(int ms) 44 : : { 45 [ # # ]: 0 : if (ms == 0) 46 : 0 : return; 47 : : 48 : : #if defined(_OS_WINDOWS_) 49 : : Sleep(ms); 50 : : #else 51 : : struct timeval timeout; 52 : : 53 : 0 : timeout.tv_sec = ms / 1000; 54 : 0 : timeout.tv_usec = (ms % 1000) * 1000; 55 : : 56 : 0 : select(0, NULL, NULL, NULL, &timeout); 57 : : #endif 58 : : } 59 : : 60 : : #ifdef __cplusplus 61 : : } 62 : : #endif