MCPcopy Create free account
hub / github.com/emscripten-core/emscripten / emscripten_thread_sleep

Function emscripten_thread_sleep

system/lib/pthread/library_pthread.c:65–86  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

63}
64
65void emscripten_thread_sleep(double msecs) {
66 // We include emscripten_current_thread_process_queued_calls before and
67 // after sleeping since that is how we recieve "async" signals.
68 // We include __pthread_testcancel here because clock_nanosleep is
69 // a pthread cancelation point.
70 emscripten_current_thread_process_queued_calls();
71 __pthread_testcancel();
72 if (msecs > 0) {
73 uint32_t dummyZeroAddress = 0;
74 double target = emscripten_get_now() + msecs;
75 do {
76 emscripten_conditional_set_current_thread_status(EM_THREAD_STATUS_RUNNING,
77 EM_THREAD_STATUS_SLEEPING);
78 emscripten_futex_wait(&dummyZeroAddress, 0, msecs);
79 emscripten_conditional_set_current_thread_status(EM_THREAD_STATUS_SLEEPING,
80 EM_THREAD_STATUS_RUNNING);
81 emscripten_current_thread_process_queued_calls();
82 __pthread_testcancel();
83 msecs = target - emscripten_get_now();
84 } while (msecs > 0);
85 }
86}
87
88static struct pthread __main_pthread;
89

Callers 12

mainFunction · 0.50
fillFunction · 0.50
do_sleepFunction · 0.50
workFunction · 0.50
thread_funcFunction · 0.50
mainFunction · 0.50
send_threadFunction · 0.50
mainFunction · 0.50
run_testFunction · 0.50
run_testFunction · 0.50
__clock_nanosleepFunction · 0.50

Tested by 5

do_sleepFunction · 0.40
workFunction · 0.40
thread_funcFunction · 0.40
run_testFunction · 0.40
run_testFunction · 0.40