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

Function work

test/wasm_worker/lock_async_acquire.c:26–59  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

24}
25
26void work() {
27 // emscripten_out("work");
28 volatile int x = sharedState0;
29 volatile int y = sharedState1;
30 assert(x == y+1 || y == x+1);
31
32 if (emscripten_current_thread_is_wasm_worker()) {
33 ++numTimesWasmWorkerAcquiredLock;
34 } else {
35 ++numTimesMainThreadAcquiredLock;
36 }
37
38 if (x < y) {
39 x = y + 1;
40 if (emscripten_current_thread_is_wasm_worker()) {
41 emscripten_wasm_worker_sleep(/*nsecs=*/(rand()%100000));
42 }
43 sharedState0 = x;
44 } else {
45 y = x + 1;
46 if (emscripten_current_thread_is_wasm_worker()) {
47 emscripten_wasm_worker_sleep(/*nsecs=*/(rand()%100000));
48 }
49 sharedState1 = y;
50
51 if (y > 100 && numTimesMainThreadAcquiredLock && numTimesWasmWorkerAcquiredLock) {
52 if (!testFinished) {
53 testFinished = true;
54 emscripten_out("test finished");
55 emscripten_wasm_worker_post_function_v(EMSCRIPTEN_WASM_WORKER_ID_PARENT, do_exit);
56 }
57 }
58 }
59}
60
61void schedule_work(void *userData);
62

Callers 2

lock_async_acquiredFunction · 0.70
schedule_workFunction · 0.70

Calls 5

randFunction · 0.85
assertFunction · 0.50
emscripten_outFunction · 0.50

Tested by

no test coverage detected