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

Function set_status_conditional

system/lib/pthread/thread_profiler.c:32–49  ·  view source on GitHub ↗

Sets the current thread status, but only if it was in the given expected state before. This is used to allow high-level control flow "override" the thread status before low-level (futex wait) operations set it.

Source from the content-addressed store, hash-verified

30// state before. This is used to allow high-level control flow "override" the
31// thread status before low-level (futex wait) operations set it.
32static void set_status_conditional(int expectedStatus, int newStatus) {
33 if (!enabled) {
34 return;
35 }
36 pthread_t thread = pthread_self();
37 if (!thread) return; // AudioWorklets do not have a pthread block, but if user calls emscripten_futex_wait() in an AudioWorklet, it will call here via emscripten_set_current_thread_status().
38 int prevStatus = thread->profilerBlock->threadStatus;
39
40 if (prevStatus != newStatus && (prevStatus == expectedStatus || expectedStatus == -1)) {
41 double now = emscripten_get_now();
42 double startState = thread->profilerBlock->currentStatusStartTime;
43 double duration = now - startState;
44
45 thread->profilerBlock->timeSpentInStatus[prevStatus] += duration;
46 thread->profilerBlock->threadStatus = newStatus;
47 thread->profilerBlock->currentStatusStartTime = now;
48 }
49}
50
51void emscripten_conditional_set_current_thread_status(int expectedStatus, int newStatus) {
52 set_status_conditional(expectedStatus, newStatus);

Calls 1

emscripten_get_nowFunction · 0.50

Tested by

no test coverage detected