@@ -6118,12 +6118,17 @@ LibraryManager.library = {
6118
6118
}
6119
6119
return _usleep((seconds * 1e6) + (nanoseconds / 1000));
6120
6120
},
6121
- // TODO: Implement these for real.
6121
+ clock_gettime__deps: ['emscripten_get_now'],
6122
6122
clock_gettime: function(clk_id, tp) {
6123
6123
// int clock_gettime(clockid_t clk_id, struct timespec *tp);
6124
- var now = Date.now();
6124
+ var now;
6125
+ if (clk_id === {{{ cDefine('CLOCK_REALTIME') }}}) {
6126
+ now = Date.now();
6127
+ } else {
6128
+ now = _emscripten_get_now();
6129
+ }
6125
6130
{{{ makeSetValue('tp', C_STRUCTS.timespec.tv_sec, 'Math.floor(now/1000)', 'i32') }}}; // seconds
6126
- {{{ makeSetValue('tp', C_STRUCTS.timespec.tv_nsec, '( now % 1000) * 1000 * 1000', 'i32') }}}; // nanoseconds (really milliseconds)
6131
+ {{{ makeSetValue('tp', C_STRUCTS.timespec.tv_nsec, 'Math.floor(( now % 1000)* 1000* 1000) ', 'i32') }}}; // nanoseconds
6127
6132
return 0;
6128
6133
},
6129
6134
clock_settime: function(clk_id, tp) {
@@ -8672,6 +8677,24 @@ LibraryManager.library = {
8672
8677
return func ( ) ;
8673
8678
} ,
8674
8679
8680
+ emscripten_get_now : function ( ) {
8681
+ if ( ! _emscripten_get_now . actual ) {
8682
+ if ( ENVIRONMENT_IS_NODE ) {
8683
+ _emscripten_get_now . actual = function _emscripten_get_now_actual ( ) {
8684
+ var t = process [ 'hrtime' ] ( ) ;
8685
+ return t [ 0 ] * 1e3 + t [ 1 ] / 1e6 ;
8686
+ }
8687
+ } else if ( typeof dateNow !== 'undefined' ) {
8688
+ _emscripten_get_now . actual = dateNow ;
8689
+ } else if ( ENVIRONMENT_IS_WEB && window [ 'performance' ] && window [ 'performance' ] [ 'now' ] ) {
8690
+ _emscripten_get_now . actual = function _emscripten_get_now_actual ( ) { return window [ 'performance' ] [ 'now' ] ( ) ; } ;
8691
+ } else {
8692
+ _emscripten_get_now . actual = Date . now ;
8693
+ }
8694
+ }
8695
+ return _emscripten_get_now . actual ( ) ;
8696
+ } ,
8697
+
8675
8698
//============================
8676
8699
// emscripten vector ops
8677
8700
//============================
0 commit comments