@@ -1271,6 +1271,8 @@ def __init__(self, **kwargs):
1271
1271
self .memvalidate = kwargs .pop ('memvalidate' )
1272
1272
self .verbose = kwargs .pop ('verbose' )
1273
1273
self .is_debug = kwargs .pop ('is_debug' ) or self .memvalidate or self .verbose
1274
+ self .thread_safe = kwargs .pop ('thread_safe' )
1275
+ self .use_spinlocks = kwargs .pop ('use_spinlocks' )
1274
1276
1275
1277
super ().__init__ (** kwargs )
1276
1278
@@ -1296,6 +1298,11 @@ def get_cflags(self):
1296
1298
cflags += ['-DMALLOC_FAILURE_ACTION=' , '-DEMSCRIPTEN_NO_ERRNO' ]
1297
1299
if self .is_tracing :
1298
1300
cflags += ['--tracing' ]
1301
+ # Target dlmalloc multithreading aware implementation if using pthreads or Wasm Workers
1302
+ cflags += [f'-DUSE_LOCKS={ self .thread_safe } ' ]
1303
+ # When using Wasm Workers, target spinlocks. Otherwise target pthread mutexes when using pthreads.
1304
+ cflags += [f'-DUSE_SPIN_LOCKS={ self .use_spinlocks } ' ]
1305
+
1299
1306
return cflags
1300
1307
1301
1308
def get_base_name_prefix (self ):
@@ -1338,6 +1345,8 @@ def get_default_variation(cls, **kwargs):
1338
1345
is_tracing = settings .EMSCRIPTEN_TRACING ,
1339
1346
memvalidate = 'memvalidate' in settings .MALLOC ,
1340
1347
verbose = 'verbose' in settings .MALLOC ,
1348
+ use_spinlocks = settings .WASM_WORKERS ,
1349
+ thread_safe = settings .SHARED_MEMORY ,
1341
1350
** kwargs
1342
1351
)
1343
1352
0 commit comments