@@ -25,9 +25,6 @@ var LibraryPThread = {
25
25
// Points to a pthread_t structure in the Emscripten main heap, allocated on
26
26
// demand if/when first needed.
27
27
// mainThreadBlock: undefined,
28
- // Stores the memory address that the main thread is waiting on, if any. If
29
- // the main thread is waiting, we wake it up before waking up any workers.
30
- // mainThreadFutex: undefined,
31
28
initMainThreadBlock : function ( ) {
32
29
#if ASSERTIONS
33
30
assert ( ! ENVIRONMENT_IS_PTHREAD ) ;
@@ -107,9 +104,8 @@ var LibraryPThread = {
107
104
#endif
108
105
} ,
109
106
initShared : function ( ) {
110
- PThread . mainThreadFutex = _main_thread_futex ;
111
107
#if ASSERTIONS
112
- assert ( PThread . mainThreadFutex > 0 ) ;
108
+ assert ( __emscripten_main_thread_futex > 0 ) ;
113
109
#endif
114
110
} ,
115
111
// Maps pthread_t to pthread info objects
@@ -1145,20 +1141,20 @@ var LibraryPThread = {
1145
1141
#endif
1146
1142
// Register globally which address the main thread is simulating to be
1147
1143
// waiting on. When zero, the main thread is not waiting on anything, and on
1148
- // nonzero, the contents of the address pointed by PThread.mainThreadFutex
1144
+ // nonzero, the contents of the address pointed by __emscripten_main_thread_futex
1149
1145
// tell which address the main thread is simulating its wait on.
1150
1146
// We need to be careful of recursion here: If we wait on a futex, and
1151
1147
// then call _emscripten_main_thread_process_queued_calls() below, that
1152
1148
// will call code that takes the proxying mutex - which can once more
1153
1149
// reach this code in a nested call. To avoid interference between the
1154
- // two (there is just a single mainThreadFutex at a time), unmark
1150
+ // two (there is just a single __emscripten_main_thread_futex at a time), unmark
1155
1151
// ourselves before calling the potentially-recursive call. See below for
1156
1152
// how we handle the case of our futex being notified during the time in
1157
- // between when we are not set as the value of mainThreadFutex .
1153
+ // between when we are not set as the value of __emscripten_main_thread_futex .
1158
1154
#if ASSERTIONS
1159
- assert ( PThread . mainThreadFutex > 0 ) ;
1155
+ assert ( __emscripten_main_thread_futex > 0 ) ;
1160
1156
#endif
1161
- var lastAddr = Atomics . exchange ( HEAP32 , PThread . mainThreadFutex >> 2 , addr ) ;
1157
+ var lastAddr = Atomics . exchange ( HEAP32 , __emscripten_main_thread_futex >> 2 , addr ) ;
1162
1158
#if ASSERTIONS
1163
1159
// We must not have already been waiting.
1164
1160
assert ( lastAddr == 0 ) ;
@@ -1172,7 +1168,7 @@ var LibraryPThread = {
1172
1168
PThread . setThreadStatusConditional ( _pthread_self ( ) , { { { cDefine ( 'EM_THREAD_STATUS_RUNNING' ) } } } , { { { cDefine ( 'EM_THREAD_STATUS_WAITFUTEX' ) } } } ) ;
1173
1169
#endif
1174
1170
// We timed out, so stop marking ourselves as waiting.
1175
- lastAddr = Atomics . exchange ( HEAP32 , PThread . mainThreadFutex >> 2 , 0 ) ;
1171
+ lastAddr = Atomics . exchange ( HEAP32 , __emscripten_main_thread_futex >> 2 , 0 ) ;
1176
1172
#if ASSERTIONS
1177
1173
// The current value must have been our address which we set, or
1178
1174
// in a race it was set to 0 which means another thread just allowed
@@ -1186,7 +1182,7 @@ var LibraryPThread = {
1186
1182
// Note that we have to do so carefully, as we may take a lock while
1187
1183
// doing so, which can recurse into this function; stop marking
1188
1184
// ourselves as waiting while we do so.
1189
- lastAddr = Atomics . exchange ( HEAP32 , PThread . mainThreadFutex >> 2 , 0 ) ;
1185
+ lastAddr = Atomics . exchange ( HEAP32 , __emscripten_main_thread_futex >> 2 , 0 ) ;
1190
1186
#if ASSERTIONS
1191
1187
assert ( lastAddr == addr || lastAddr == 0 ) ;
1192
1188
#endif
@@ -1201,20 +1197,20 @@ var LibraryPThread = {
1201
1197
//
1202
1198
// * wait on futex A
1203
1199
// * recurse into emscripten_main_thread_process_queued_calls(),
1204
- // which waits on futex B. that sets the mainThreadFutex address to
1200
+ // which waits on futex B. that sets the __emscripten_main_thread_futex address to
1205
1201
// futex B, and there is no longer any mention of futex A.
1206
- // * a worker is done with futex A. it checks mainThreadFutex but does
1202
+ // * a worker is done with futex A. it checks __emscripten_main_thread_futex but does
1207
1203
// not see A, so it does nothing special for the main thread.
1208
1204
// * a worker is done with futex B. it flips mainThreadMutex from B
1209
1205
// to 0, ending the wait on futex B.
1210
- // * we return to the wait on futex A. mainThreadFutex is 0, but that
1206
+ // * we return to the wait on futex A. __emscripten_main_thread_futex is 0, but that
1211
1207
// is because of futex B being done - we can't tell from
1212
- // mainThreadFutex whether A is done or not. therefore, check the
1208
+ // __emscripten_main_thread_futex whether A is done or not. therefore, check the
1213
1209
// memory value of the futex.
1214
1210
//
1215
1211
// That case motivates the design here. Given that, checking the memory
1216
1212
// address is also necessary for other reasons: we unset and re-set our
1217
- // address in mainThreadFutex around calls to
1213
+ // address in __emscripten_main_thread_futex around calls to
1218
1214
// emscripten_main_thread_process_queued_calls(), and a worker could
1219
1215
// attempt to wake us up right before/after such times.
1220
1216
//
@@ -1235,7 +1231,7 @@ var LibraryPThread = {
1235
1231
}
1236
1232
1237
1233
// Mark us as waiting once more, and continue the loop.
1238
- lastAddr = Atomics . exchange ( HEAP32 , PThread . mainThreadFutex >> 2 , addr ) ;
1234
+ lastAddr = Atomics . exchange ( HEAP32 , __emscripten_main_thread_futex >> 2 , addr ) ;
1239
1235
#if ASSERTIONS
1240
1236
assert ( lastAddr == 0 ) ;
1241
1237
#endif
@@ -1260,19 +1256,19 @@ var LibraryPThread = {
1260
1256
// Note that this is not a fair procedure, since we always wake main thread first before any workers, so
1261
1257
// this scheme does not adhere to real queue-based waiting.
1262
1258
#if ASSERTIONS
1263
- assert ( PThread . mainThreadFutex > 0 ) ;
1259
+ assert ( __emscripten_main_thread_futex > 0 ) ;
1264
1260
#endif
1265
- var mainThreadWaitAddress = Atomics . load ( HEAP32 , PThread . mainThreadFutex >> 2 ) ;
1261
+ var mainThreadWaitAddress = Atomics . load ( HEAP32 , __emscripten_main_thread_futex >> 2 ) ;
1266
1262
var mainThreadWoken = 0 ;
1267
1263
if ( mainThreadWaitAddress == addr ) {
1268
1264
#if ASSERTIONS
1269
- // We only use mainThreadFutex on the main browser thread, where we
1265
+ // We only use __emscripten_main_thread_futex on the main browser thread, where we
1270
1266
// cannot block while we wait. Therefore we should only see it set from
1271
1267
// other threads, and not on the main thread itself. In other words, the
1272
1268
// main thread must never try to wake itself up!
1273
1269
assert ( ! ENVIRONMENT_IS_WEB ) ;
1274
1270
#endif
1275
- var loadedAddr = Atomics . compareExchange ( HEAP32 , PThread . mainThreadFutex >> 2 , mainThreadWaitAddress , 0 ) ;
1271
+ var loadedAddr = Atomics . compareExchange ( HEAP32 , __emscripten_main_thread_futex >> 2 , mainThreadWaitAddress , 0 ) ;
1276
1272
if ( loadedAddr == mainThreadWaitAddress ) {
1277
1273
-- count ;
1278
1274
mainThreadWoken = 1 ;
0 commit comments