Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f849058

Browse files
committedAug 6, 2024
Implement single_threaded pthread_exit
Performs all the cancellation actions and then calls exit()
1 parent 7c33501 commit f849058

File tree

4 files changed

+36
-1
lines changed

4 files changed

+36
-1
lines changed
 

‎Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ LIBC_TOP_HALF_MUSL_SOURCES += \
289289
thread/pthread_barrierattr_init.c \
290290
thread/pthread_barrierattr_setpshared.c \
291291
thread/pthread_cancel.c \
292+
thread/pthread_cleanup_push.c \
292293
thread/pthread_condattr_destroy.c \
293294
thread/pthread_condattr_init.c \
294295
thread/pthread_condattr_setclock.c \
@@ -332,7 +333,6 @@ LIBC_TOP_HALF_MUSL_SOURCES += \
332333
thread/pthread_barrier_destroy.c \
333334
thread/pthread_barrier_init.c \
334335
thread/pthread_barrier_wait.c \
335-
thread/pthread_cleanup_push.c \
336336
thread/pthread_cond_broadcast.c \
337337
thread/pthread_cond_destroy.c \
338338
thread/pthread_cond_init.c \

‎expected/wasm32-wasip1/defined-symbols.txt

+5
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ __cxa_finalize
3838
__default_guardsize
3939
__default_stacksize
4040
__des_setkey
41+
__do_cleanup_pop
42+
__do_cleanup_push
4143
__do_des
4244
__duplocale
4345
__env_rm_add
@@ -383,6 +385,8 @@ _environ
383385
_exit
384386
_flushlbf
385387
_initialize
388+
_pthread_cleanup_pop
389+
_pthread_cleanup_push
386390
_start
387391
a64l
388392
abort
@@ -982,6 +986,7 @@ pthread_condattr_setpshared
982986
pthread_create
983987
pthread_detach
984988
pthread_equal
989+
pthread_exit
985990
pthread_getspecific
986991
pthread_join
987992
pthread_key_create

‎expected/wasm32-wasip2/defined-symbols.txt

+5
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ __cxa_finalize
4141
__default_guardsize
4242
__default_stacksize
4343
__des_setkey
44+
__do_cleanup_pop
45+
__do_cleanup_push
4446
__do_des
4547
__duplocale
4648
__env_rm_add
@@ -398,6 +400,8 @@ _environ
398400
_exit
399401
_flushlbf
400402
_initialize
403+
_pthread_cleanup_pop
404+
_pthread_cleanup_push
401405
_start
402406
a64l
403407
abort
@@ -1114,6 +1118,7 @@ pthread_condattr_setpshared
11141118
pthread_create
11151119
pthread_detach
11161120
pthread_equal
1121+
pthread_exit
11171122
pthread_getspecific
11181123
pthread_join
11191124
pthread_key_create

‎libc-top-half/stub-pthreads/stub-pthreads.c

+25
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ static void dummy_0()
55
}
66
weak_alias(dummy_0, __acquire_ptc);
77
weak_alias(dummy_0, __release_ptc);
8+
weak_alias(dummy_0, __pthread_tsd_run_dtors);
89

910
int __pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict attrp, void *(*entry)(void *), void *restrict arg)
1011
{
@@ -51,3 +52,27 @@ int pthread_once(pthread_once_t *control, void (*init)(void))
5152
}
5253
return 0;
5354
}
55+
56+
_Noreturn void pthread_exit(void *result)
57+
{
58+
/*
59+
We are the only thread, so when we exit the whole process exits.
60+
But we still have to run cancellation handlers...
61+
*/
62+
pthread_t self = __pthread_self();
63+
64+
self->canceldisable = 1;
65+
self->cancelasync = 0;
66+
self->result = result;
67+
68+
while (self->cancelbuf) {
69+
void (*f)(void *) = self->cancelbuf->__f;
70+
void *x = self->cancelbuf->__x;
71+
self->cancelbuf = self->cancelbuf->__next;
72+
f(x);
73+
}
74+
75+
__pthread_tsd_run_dtors();
76+
77+
exit(0);
78+
}

0 commit comments

Comments
 (0)
Please sign in to comment.