| 63 | } |
| 64 | |
| 65 | void 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 | |
| 88 | static struct pthread __main_pthread; |
| 89 | |