Esempio n. 1
0
void c1(char *data, int size, void *arg) { // tests copying + buffer enlargement
  assert((int)arg == stage);
  if (stage == 1) {
    printf("wait 0? %d\n", emscripten_get_worker_queue_size(w1));
    assert(emscripten_get_worker_queue_size(w1) == 0);
  }
  Info *x2 = (Info*)data;
  assert(x2 != x && x2 != x+1 && x2 != x+2);
  for (int i = 0; i < size/sizeof(Info); i++) {
    printf("c1-%d\n", i);
    printf("  %d, %.2f, %d, %.2f\n", x2[i].i, x2[i].f, x2[i].c, x2[i].d);
    printf("  %d, %.2f, %d, %.2f\n", x[i].i, x[i].f, x[i].c, x[i].d);
    assert(x2[i].i == x[i].i);
    assert(x2[i].f == x[i].f);
    assert(x2[i].c == x[i].c);
    assert(x2[i].d == x[i].d);
  }
  if (stage < 2) {
    emscripten_call_worker(w1, "one", (char*)x, sizeof(Info)*3, c1, (void*)2);
  } else {
    printf("wait 1? %d\n", emscripten_get_worker_queue_size(w1));
    assert(emscripten_get_worker_queue_size(w1) == 0);
    emscripten_call_worker(w1, "two", (char*)&x[0], sizeof(Info), c2, (void*)3);
    emscripten_call_worker(w1, "two", (char*)&x[1], sizeof(Info), c2, (void*)4);
    emscripten_call_worker(w1, "two", (char*)&x[2], sizeof(Info), c2, (void*)5);
    printf("wait 2? %d\n", emscripten_get_worker_queue_size(w1));
    assert(emscripten_get_worker_queue_size(w1) == 3);
  }
  stage++;
}
Esempio n. 2
0
void draw_same(void)
{
  disp_beginUpdate(&buf_graf, &buf_graf_stride, &wpar.width, &wpar.height);
  emscripten_call_worker(worker, "draw", (char *)&wpar, sizeof(wpar),
                         worker_callback, NULL);
  /* Worker callback will restart main loop */
  emscripten_cancel_main_loop();
}
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;
}
Esempio n. 4
0
int main() {
  w1 = emscripten_create_worker("worker.js");

  printf("wait -1? %d\n", emscripten_get_worker_queue_size(w1));
  assert(emscripten_get_worker_queue_size(w1) == 0);
  emscripten_call_worker(w1, "one", (char*)x, sizeof(Info)*2, c1, (void*)1);
  printf("wait -1? %d\n", emscripten_get_worker_queue_size(w1));
  assert(emscripten_get_worker_queue_size(w1) == 1);
  stage = 1; // make sure we get here

  return 0;
}
Esempio n. 5
0
void c2(char *data, int size, void *arg) { // tests queuing up several messages, each with different data
  assert((int)arg == stage);
  Info *x2 = (Info*)data;

  int i = stage - 3;
  printf("c2-%d\n", i);
  printf("%d, %.2f, %d, %.2f\n", x2[0].i, x2[0].f, x2[0].c, x2[0].d);
  printf("%d, %.2f, %d, %.2f\n", x[i].i, x[i].f, x[i].c, x[i].d);
  assert(x2[0].i == x[i].i+1);
  assert(x2[0].f == x[i].f-1);
  assert(x2[0].c == x[i].c+1);
  assert(x2[0].d == x[i].d-1);

  if (stage == 5) {
    int w2 = emscripten_create_worker("worker.js");
    emscripten_call_worker(w2, "three", NULL, 0, NULL, (void*)6); // bump calls in new worker, once

    emscripten_call_worker(w1, "four", NULL, 0, c3, (void*)7);
    emscripten_call_worker(w2, "four", NULL, 0, c3, (void*)8);
  }
  stage++;
}
Esempio n. 6
0
void loop() {
    if (!update) {
        return;
    }
    update = 0;

    int s1,s2,s3;
    int siz = (s1=fsize(lua)) + (s2=fsize(input)) + (s3=fsize(query_file)) + 3*4; // 3 times 4 bytes for lengths
    char* buf = (char*) malloc((unsigned int) siz);
    char* ptr = buf;
    memcpy(ptr,&s1,4);
    memcpy(ptr+4,&s2,4);
    memcpy(ptr+8,&s3,4);
    ptr += 12;

    ptr = cpy(lua,ptr);
    ptr = cpy(input,ptr);
    ptr = cpy(query_file,ptr);

    emscripten_call_worker(worker, "johnmandog", buf, siz, cback, (void*) 42);

    free(buf);
}