Skip to content

Commit 72da048

Browse files
committed
Revert NFC changes from pthread_create.c
1 parent 8b3eb79 commit 72da048

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

system/lib/pthread/pthread_create.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
// See musl's pthread_create.c
2424

25-
extern int __pthread_create_js(pthread_t thread, const pthread_attr_t *attr, void *(*start_routine) (void *), void *arg);
25+
extern int __pthread_create_js(struct pthread *thread, const pthread_attr_t *attr, void *(*start_routine) (void *), void *arg);
2626
extern void _emscripten_thread_init(int, int, int);
2727
extern int _emscripten_default_pthread_stack_size();
2828
extern void __pthread_detached_exit();
@@ -76,7 +76,7 @@ int __pthread_create(pthread_t* restrict res,
7676
void* (*entry)(void*),
7777
void* restrict arg) {
7878
// Note on LSAN: lsan intercepts/wraps calls to pthread_create so any
79-
// allocation we do here should be considered as leak.
79+
// allocation we we do here should be considered leaks.
8080
// See: lsan_interceptors.cpp.
8181
if (!res) {
8282
return EINVAL;
@@ -188,11 +188,11 @@ static void free_tls_data() {
188188
}
189189

190190
void _emscripten_thread_exit(void* result) {
191-
pthread_t self = __pthread_self();
191+
struct pthread *self = __pthread_self();
192192
assert(self);
193193

194-
self->canceldisable = 1;
195-
self->cancelasync = 0;
194+
self->canceldisable = PTHREAD_CANCEL_DISABLE;
195+
self->cancelasync = PTHREAD_CANCEL_DEFERRED;
196196
self->result = result;
197197

198198
// Run any handlers registered with pthread_cleanup_push
@@ -219,16 +219,16 @@ void _emscripten_thread_exit(void* result) {
219219
return;
220220
}
221221

222-
// We have the call the builtin free here since lsan handling for this thread
222+
// We have the call the buildin free here since lsan handling for this thread
223223
// gets shut down during __pthread_tsd_run_dtors.
224224
emscripten_builtin_free(self->tsd);
225225
self->tsd = NULL;
226226

227227
// Not hosting a pthread anymore in this worker set __pthread_self to NULL
228228
_emscripten_thread_init(0, 0, 0);
229229

230-
// This atomic potentially competes with a concurrent pthread_detach
231-
// call; the loser is responsible for freeing thread resources.
230+
/* This atomic potentially competes with a concurrent pthread_detach
231+
* call; the loser is responsible for freeing thread resources. */
232232
int state = a_cas(&self->detach_state, DT_JOINABLE, DT_EXITING);
233233

234234
// Mark the thread as no longer running.
@@ -244,7 +244,7 @@ void _emscripten_thread_exit(void* result) {
244244
}
245245
}
246246

247-
// Mark as `no_sanitize("address")` since emscripten_pthread_exit destroys
247+
// Mark as `no_sanitize("address"` since emscripten_pthread_exit destroys
248248
// the current thread and runs its exit handlers. Without this asan injects
249249
// a call to __asan_handle_no_return before emscripten_unwind_to_js_event_loop
250250
// which seem to cause a crash later down the line.

0 commit comments

Comments
 (0)