aboutsummaryrefslogtreecommitdiff
path: root/tests/worker_api_2_worker.cpp
blob: d7033bc41f968ad49cb7be390dbecad39c9f2418 (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 <assert.h>
#include <emscripten.h>

struct Info {
  int i;
  float f;
  char c;
  double d;
};

int calls = 0; // global state that is not in all workers

extern "C" {

void one(char *data, int size) {
  calls++;
  emscripten_worker_respond(data, size);
}

void two(char *data, int size) {
  calls++;
  Info *x = (Info*)data;
  x[0].i++;
  x[0].f--;
  x[0].c++;
  x[0].d--;
  emscripten_worker_respond(data, size);
}

void three(char *data, int size) {
  assert(data == 0);
  assert(size == 0);
  calls++;
  // no response
}

void four(char *data, int size) {
  assert(data == 0);
  assert(size == 0);
  emscripten_worker_respond((char*)&calls, sizeof(calls));
}

}