blob: 595f99b9e0bd6e5992047cf78e4dc7124ece0f2f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
#include <stdio.h>
#include <assert.h>
#include <emscripten.h>
int w1;
bool sawCalls[] = { false, false, false, false };
void c1(char *data, int size, void *arg) {
assert((int)arg == 97);
assert(size >= sizeof(int));
int *x = (int*)data;
printf("c1: %d\n", x[0]);
if (*x >= 0 && *x < 4) {
// Calls should have happened in order.
sawCalls[*x] = true; // Note the call with current param was made
for (int i = 0; i < *x - 1; ++i) {
if (!sawCalls[i]) {
// If we were called out of order, fail this and all following calls.
sawCalls[*x] = false;
break;
}
}
} else {
assert(*x == 4);
// This is the last call. All prior calls should have occurred.
int result = 1; // Final call occurred.
for (int i = 0; i < 4; ++i)
if (sawCalls[i]) result++;
REPORT_RESULT();
}
}
int main() {
w1 = emscripten_create_worker("worker.js");
int x[1] = { 0 };
emscripten_call_worker(w1, "one", (char*)x, sizeof(x), c1, (void*)97);
return 0;
}
|