diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/library.js | 29 | ||||
-rw-r--r-- | src/library_browser.js | 18 | ||||
-rw-r--r-- | src/struct_info.json | 3 |
3 files changed, 28 insertions, 22 deletions
diff --git a/src/library.js b/src/library.js index 48acf6ac..6d821bfc 100644 --- a/src/library.js +++ b/src/library.js @@ -6118,12 +6118,17 @@ LibraryManager.library = { } return _usleep((seconds * 1e6) + (nanoseconds / 1000)); }, - // TODO: Implement these for real. + clock_gettime__deps: ['emscripten_get_now'], clock_gettime: function(clk_id, tp) { // int clock_gettime(clockid_t clk_id, struct timespec *tp); - var now = Date.now(); + var now; + if (clk_id === {{{ cDefine('CLOCK_REALTIME') }}}) { + now = Date.now(); + } else { + now = _emscripten_get_now(); + } {{{ makeSetValue('tp', C_STRUCTS.timespec.tv_sec, 'Math.floor(now/1000)', 'i32') }}}; // seconds - {{{ makeSetValue('tp', C_STRUCTS.timespec.tv_nsec, '(now % 1000) * 1000 * 1000', 'i32') }}}; // nanoseconds (really milliseconds) + {{{ makeSetValue('tp', C_STRUCTS.timespec.tv_nsec, 'Math.floor((now % 1000)*1000*1000)', 'i32') }}}; // nanoseconds return 0; }, clock_settime: function(clk_id, tp) { @@ -8672,6 +8677,24 @@ LibraryManager.library = { return func(); }, + emscripten_get_now: function() { + if (!_emscripten_get_now.actual) { + if (ENVIRONMENT_IS_NODE) { + _emscripten_get_now.actual = function _emscripten_get_now_actual() { + var t = process['hrtime'](); + return t[0] * 1e3 + t[1] / 1e6; + } + } else if (typeof dateNow !== 'undefined') { + _emscripten_get_now.actual = dateNow; + } else if (ENVIRONMENT_IS_WEB && window['performance'] && window['performance']['now']) { + _emscripten_get_now.actual = function _emscripten_get_now_actual() { return window['performance']['now'](); }; + } else { + _emscripten_get_now.actual = Date.now; + } + } + return _emscripten_get_now.actual(); + }, + //============================ // emscripten vector ops //============================ diff --git a/src/library_browser.js b/src/library_browser.js index 39a1c55d..1883c3be 100644 --- a/src/library_browser.js +++ b/src/library_browser.js @@ -871,24 +871,6 @@ mergeInto(LibraryManager.library, { {{{ makeSetValue('isFullscreen', '0', 'Browser.isFullScreen ? 1 : 0', 'i32') }}}; }, - emscripten_get_now: function() { - if (!_emscripten_get_now.actual) { - if (ENVIRONMENT_IS_NODE) { - _emscripten_get_now.actual = function _emscripten_get_now_actual() { - var t = process['hrtime'](); - return t[0] * 1e3 + t[1] / 1e6; - } - } else if (typeof dateNow !== 'undefined') { - _emscripten_get_now.actual = dateNow; - } else if (ENVIRONMENT_IS_WEB && window['performance'] && window['performance']['now']) { - _emscripten_get_now.actual = function _emscripten_get_now_actual() { return window['performance']['now'](); }; - } else { - _emscripten_get_now.actual = Date.now; - } - } - return _emscripten_get_now.actual(); - }, - emscripten_create_worker: function(url) { url = Pointer_stringify(url); var id = Browser.workers.length; diff --git a/src/struct_info.json b/src/struct_info.json index b91d077e..c136cc8b 100644 --- a/src/struct_info.json +++ b/src/struct_info.json @@ -169,7 +169,8 @@ { "file": "libc/time.h", "defines": [ - ["li", "CLOCKS_PER_SEC"] + ["li", "CLOCKS_PER_SEC"], + "CLOCK_REALTIME" ], "structs": { "timezone": [ |