aboutsummaryrefslogtreecommitdiff
path: root/src/library.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/library.js')
-rw-r--r--src/library.js29
1 files changed, 26 insertions, 3 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
//============================