diff --git a/system/lib/emmalloc.c b/system/lib/emmalloc.c index 1fcad3318f363..8d144f616a7af 100644 --- a/system/lib/emmalloc.c +++ b/system/lib/emmalloc.c @@ -107,7 +107,7 @@ typedef struct RootRegion uint8_t* endPtr; } RootRegion; -#if defined(__EMSCRIPTEN_PTHREADS__) +#ifdef __EMSCRIPTEN_SHARED_MEMORY__ // In multithreaded builds, use a simple global spinlock strategy to acquire/release access to the memory allocator. static volatile uint8_t multithreadingLock = 0; #define MALLOC_ACQUIRE() while(__sync_lock_test_and_set(&multithreadingLock, 1)) { while(multithreadingLock) { /*nop*/ } } diff --git a/system/lib/sbrk.c b/system/lib/sbrk.c index e443ddf3ba893..21f2d570956eb 100644 --- a/system/lib/sbrk.c +++ b/system/lib/sbrk.c @@ -12,7 +12,7 @@ #include #include #include -#if __EMSCRIPTEN_PTHREADS__ // for error handling, see below +#ifdef __EMSCRIPTEN_SHARED_MEMORY__ // for error handling, see below #include #include #endif @@ -54,16 +54,16 @@ void *sbrk(intptr_t increment_) { uintptr_t old_size; uintptr_t increment = (uintptr_t)increment_; increment = (increment + (SBRK_ALIGNMENT-1)) & ~(SBRK_ALIGNMENT-1); -#if __EMSCRIPTEN_PTHREADS__ +#ifdef __EMSCRIPTEN_SHARED_MEMORY__ // Our default dlmalloc uses locks around each malloc/free, so no additional // work is necessary to keep things threadsafe, but we also make sure sbrk // itself is threadsafe so alternative allocators work. We do that by looping // and retrying if we hit interference with another thread. uintptr_t expected; while (1) { -#endif // __EMSCRIPTEN_PTHREADS__ +#endif // __EMSCRIPTEN_SHARED_MEMORY__ uintptr_t* sbrk_ptr = emscripten_get_sbrk_ptr(); -#if __EMSCRIPTEN_PTHREADS__ +#ifdef __EMSCRIPTEN_SHARED_MEMORY__ uintptr_t old_brk = __c11_atomic_load((_Atomic(uintptr_t)*)sbrk_ptr, __ATOMIC_SEQ_CST); #else uintptr_t old_brk = *sbrk_ptr; @@ -81,7 +81,7 @@ void *sbrk(intptr_t increment_) { goto Error; } } -#if __EMSCRIPTEN_PTHREADS__ +#ifdef __EMSCRIPTEN_SHARED_MEMORY__ // Attempt to update the dynamic top to new value. Another thread may have // beat this one to the update, in which case we will need to start over // by iterating the loop body again. @@ -93,18 +93,18 @@ void *sbrk(intptr_t increment_) { if (expected != old_brk) { continue; } -#else // __EMSCRIPTEN_PTHREADS__ +#else // __EMSCRIPTEN_SHARED_MEMORY__ *sbrk_ptr = new_brk; -#endif // __EMSCRIPTEN_PTHREADS__ +#endif // __EMSCRIPTEN_SHARED_MEMORY__ #ifdef __EMSCRIPTEN_TRACING__ emscripten_memprof_sbrk_grow(old_brk, new_brk); #endif return (void*)old_brk; -#if __EMSCRIPTEN_PTHREADS__ +#ifdef __EMSCRIPTEN_SHARED_MEMORY__ } -#endif // __EMSCRIPTEN_PTHREADS__ +#endif // __EMSCRIPTEN_SHARED_MEMORY__ Error: SET_ERRNO(); @@ -112,7 +112,7 @@ void *sbrk(intptr_t increment_) { } int brk(void* ptr) { -#if __EMSCRIPTEN_PTHREADS__ +#ifdef __EMSCRIPTEN_SHARED_MEMORY__ // FIXME printf("brk() is not theadsafe yet, https://github.com/emscripten-core/emscripten/issues/10006"); abort(); diff --git a/test/code_size/hello_wasm_worker_wasm.json b/test/code_size/hello_wasm_worker_wasm.json index e3837cd951cb2..13b3212340a7d 100644 --- a/test/code_size/hello_wasm_worker_wasm.json +++ b/test/code_size/hello_wasm_worker_wasm.json @@ -3,8 +3,8 @@ "a.html.gz": 433, "a.js": 733, "a.js.gz": 463, - "a.wasm": 1805, - "a.wasm.gz": 1002, + "a.wasm": 1861, + "a.wasm.gz": 1031, "total": 3275, "total_gz": 1898 }