@@ -5783,13 +5783,13 @@ LibraryManager.library = {
5783
5783
}
5784
5784
return _usleep ( ( seconds * 1e6 ) + ( nanoseconds / 1000 ) ) ;
5785
5785
} ,
5786
- clock_gettime__deps: [ 'emscripten_get_now' , 'emscripten_get_now_monotonic' , '$ERRNO_CODES' , '__setErrNo' ] ,
5786
+ clock_gettime__deps: [ 'emscripten_get_now' , 'emscripten_get_now_is_monotonic' , '$ERRNO_CODES' , '__setErrNo' ] ,
5787
5787
clock_gettime : function ( clk_id , tp ) {
5788
5788
// int clock_gettime(clockid_t clk_id, struct timespec *tp);
5789
5789
var now ;
5790
5790
if ( clk_id === { { { cDefine ( 'CLOCK_REALTIME' ) } } } ) {
5791
5791
now = Date . now ( ) ;
5792
- } else if ( clk_id === { { { cDefine ( 'CLOCK_MONOTONIC' ) } } } && _emscripten_get_now_monotonic ( ) ) {
5792
+ } else if ( clk_id === { { { cDefine ( 'CLOCK_MONOTONIC' ) } } } && _emscripten_get_now_is_monotonic ( ) ) {
5793
5793
now = _emscripten_get_now ( ) ;
5794
5794
} else {
5795
5795
___setErrNo ( ERRNO_CODES . EINVAL ) ;
@@ -5803,23 +5803,24 @@ LibraryManager.library = {
5803
5803
clock_settime : function ( clk_id , tp ) {
5804
5804
// int clock_settime(clockid_t clk_id, const struct timespec *tp);
5805
5805
// Nothing.
5806
- ___setErrNo ( ERRNO_CODES . EPERM ) ;
5806
+ ___setErrNo ( clk_id === { { { cDefine ( 'CLOCK_REALTIME' ) } } } ? ERRNO_CODES . EPERM
5807
+ : ERRNO_CODES . EINVAL ) ;
5807
5808
return - 1 ;
5808
5809
} ,
5809
- clock_getres__deps : [ 'emscripten_get_now_res' , 'emscripten_get_now_monotonic' , '$ERRNO_CODES' , '__setErrNo' ] ,
5810
+ clock_getres__deps: [ 'emscripten_get_now_res' , 'emscripten_get_now_is_monotonic' , '$ERRNO_CODES' , '__setErrNo' ] ,
5810
5811
clock_getres : function ( clk_id , res ) {
5811
5812
// int clock_getres(clockid_t clk_id, struct timespec *res);
5812
5813
var nsec ;
5813
5814
if ( clk_id === { { { cDefine ( 'CLOCK_REALTIME' ) } } } ) {
5814
- nsec = 1000 * 1000 ;
5815
- } else if ( clk_id === { { { cDefine ( 'CLOCK_MONOTONIC' ) } } } && _emscripten_get_now_monotonic ( ) ) {
5816
- now = _emscripten_get_now_res ( ) ;
5815
+ nsec = 1000 * 1000 ; // educated guess that it's milliseconds
5816
+ } else if ( clk_id === { { { cDefine ( 'CLOCK_MONOTONIC' ) } } } && _emscripten_get_now_is_monotonic ( ) ) {
5817
+ nsec = _emscripten_get_now_res ( ) ;
5817
5818
} else {
5818
5819
___setErrNo ( ERRNO_CODES . EINVAL ) ;
5819
5820
return - 1 ;
5820
5821
}
5821
- { { { makeSetValue ( 'res' , C_STRUCTS . timespec . tv_sec , '1 ' , 'i32' ) } } } ;
5822
- { { { makeSetValue ( 'res' , C_STRUCTS . timespec . tv_nsec , 'nsec' , 'i32' ) } } } // resolution is milliseconds
5822
+ { { { makeSetValue ( 'res' , C_STRUCTS . timespec . tv_sec , '(nsec/1000000000)|0 ' , 'i32' ) } } } ;
5823
+ { { { makeSetValue ( 'res' , C_STRUCTS . timespec . tv_nsec , 'nsec' , 'i32' ) } } } // resolution is nanoseconds
5823
5824
return 0 ;
5824
5825
} ,
5825
5826
@@ -8502,11 +8503,12 @@ LibraryManager.library = {
8502
8503
}
8503
8504
} ,
8504
8505
8505
- emscripten_get_now_monotonic__deps : [ 'emscripten_get_now' ] ,
8506
- emscripten_get_now_monotonic : function ( ) {
8506
+ emscripten_get_now_is_monotonic__deps : [ 'emscripten_get_now' ] ,
8507
+ emscripten_get_now_is_monotonic : function ( ) {
8507
8508
// return whether emscripten_get_now is guaranteed monotonic; the Date.now
8508
8509
// implementation is not :(
8509
- return ( _emscripten_get_now ( ) == Date . now ) | 0 ;
8510
+ return ENVIRONMENT_IS_NODE || ( typeof dateNow !== 'undefined' ) ||
8511
+ ( ENVIRONMENT_IS_WEB && window [ 'performance' ] && window [ 'performance' ] [ 'now' ] ) ;
8510
8512
} ,
8511
8513
8512
8514
// Returns [parentFuncArguments, functionName, paramListName]
0 commit comments