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

Function mandelbrot_thread

test/pthread/test_pthread_mandelbrot.cpp:299–336  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

297_Atomic uint32_t tasksPending[MAX_NUM_THREADS] = {};
298#ifndef SINGLETHREADED
299void *mandelbrot_thread(void *arg)
300{
301 long idx = (long)arg;
302 numThreadsRunning++;
303
304 char threadName[32];
305 sprintf(threadName, "Worker %ld", idx);
306 emscripten_set_thread_name(pthread_self(), threadName);
307
308 for(;;)
309 {
310 while (tasksPending[idx] == 0) {
311 emscripten_futex_wait(&tasksPending[idx], 0, INFINITY);
312 }
313 tasksPending[idx] = 0;
314 double t0 = emscripten_get_now();
315 int ni;
316#ifdef TEST_THREAD_PROFILING
317 // If building as part of the harness, do silly things that show up in --threadprofiler,
318 // such as sleeping and proxied file i/o ops
319 usleep(2000);
320 FILE *handle = fopen("a.txt", "w");
321 fputs("hello", handle);
322 fclose(handle);
323#endif
324#ifdef __SSE__
325 if (use_sse)
326 ni = ComputeMandelbrot_SSE(mandelReal, mandelImag, outputImage, sizeof(float)*W, sizeof(uint32_t)*W, 0, (int)idx, numTasks, W, H, left, top, incrX, incrY, numItersDoneOnCanvas, numItersPerFrame);
327 else
328#endif
329 ni = ComputeMandelbrot(mandelReal, mandelImag, outputImage, sizeof(float)*W, sizeof(uint32_t)*W, 0, (int)idx, numTasks, W, H, left, top, incrX, incrY, numItersDoneOnCanvas, numItersPerFrame);
330 double t1 = emscripten_get_now();
331 numIters[idx] += ni;
332 timeSpentInMandelbrot[idx] += t1-t0;
333 tasksDone++;
334 emscripten_futex_wake(&tasksDone, 9999);
335 }
336}
337#endif
338
339float hScroll = 0;

Callers

nothing calls this directly

Calls 11

sprintfFunction · 0.85
usleepFunction · 0.85
fopenFunction · 0.85
fputsFunction · 0.85
fcloseFunction · 0.85
ComputeMandelbrot_SSEFunction · 0.85
ComputeMandelbrotFunction · 0.85
emscripten_futex_waitFunction · 0.50
emscripten_get_nowFunction · 0.50
emscripten_futex_wakeFunction · 0.50

Tested by

no test coverage detected