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

Function init_malloc_global_mutex

system/lib/dlmalloc.c:2069–2083  ·  view source on GitHub ↗

Use spin loop to initialize global lock */

Source from the content-addressed store, hash-verified

2067
2068/* Use spin loop to initialize global lock */
2069static void init_malloc_global_mutex() {
2070 for (;;) {
2071 long stat = malloc_global_mutex_status;
2072 if (stat > 0)
2073 return;
2074 /* transition to < 0 while initializing, then to > 0) */
2075 if (stat == 0 &&
2076 interlockedcompareexchange(&malloc_global_mutex_status, (LONG)-1, (LONG)0) == 0) {
2077 InitializeCriticalSection(&malloc_global_mutex);
2078 interlockedexchange(&malloc_global_mutex_status, (LONG)1);
2079 return;
2080 }
2081 SleepEx(0, FALSE);
2082 }
2083}
2084
2085#else /* pthreads-based locks */
2086

Callers 1

init_mparamsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected