Skip to content

Commit abdcdcf

Browse files
committed
Split-out pthread_testcancel change
1 parent 8cf9c8b commit abdcdcf

File tree

5 files changed

+26
-5
lines changed

5 files changed

+26
-5
lines changed

system/lib/libc/musl/src/thread/pthread_cancel.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "pthread_impl.h"
44
#include "syscall.h"
55

6+
#ifndef __EMSCRIPTEN__
67
hidden long __cancel(), __syscall_cp_asm(), __syscall_cp_c();
78

89
long __cancel()
@@ -14,7 +15,6 @@ long __cancel()
1415
return -ECANCELED;
1516
}
1617

17-
#ifndef __EMSCRIPTEN__
1818
long __syscall_cp_asm(volatile void *, syscall_arg_t,
1919
syscall_arg_t, syscall_arg_t, syscall_arg_t,
2020
syscall_arg_t, syscall_arg_t, syscall_arg_t);
@@ -67,7 +67,6 @@ static void cancel_handler(int sig, siginfo_t *si, void *ctx)
6767

6868
__syscall(SYS_tkill, self->tid, SIGCANCEL);
6969
}
70-
#endif
7170

7271
void __testcancel()
7372
{
@@ -76,7 +75,6 @@ void __testcancel()
7675
__cancel();
7776
}
7877

79-
#ifndef __EMSCRIPTEN__
8078
static void init_cancellation()
8179
{
8280
struct sigaction sa = {

system/lib/pthread/library_pthread.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636

3737
#include "threading_internal.h"
3838

39+
void __pthread_testcancel();
40+
3941
int emscripten_pthread_attr_gettransferredcanvases(const pthread_attr_t* a, const char** str) {
4042
*str = a->_a_transferredcanvases;
4143
return 0;

system/lib/pthread/library_pthread_stub.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,6 @@ int pthread_cancel(pthread_t thread) {
206206
return 0;
207207
}
208208

209-
void pthread_testcancel() {}
210-
211209
_Noreturn void __pthread_exit(void* status) {
212210
exit(0);
213211
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright 2021 The Emscripten Authors. All rights reserved.
3+
* Emscripten is available under two separate licenses, the MIT license and the
4+
* University of Illinois/NCSA Open Source License. Both these licenses can be
5+
* found in the LICENSE file.
6+
*/
7+
8+
#include "pthread_impl.h"
9+
#include <pthread.h>
10+
11+
void __pthread_testcancel() {
12+
struct pthread* self = pthread_self();
13+
if (self->canceldisable)
14+
return;
15+
if (self->cancel) {
16+
pthread_exit(PTHREAD_CANCELED);
17+
}
18+
}
19+
20+
weak_alias(__pthread_testcancel, pthread_testcancel);

tools/system_libs.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -827,12 +827,15 @@ def get_files(self):
827827
'syscall_cp.c', 'tls.c',
828828
# TODO: Support this. See #12216.
829829
'pthread_setname_np.c',
830+
# TODO: Prefer to use the musl implementation.
831+
'pthread_testcancel.c',
830832
]
831833
libc_files += files_in_path(
832834
path='system/lib/pthread',
833835
filenames=[
834836
'library_pthread.c',
835837
'pthread_create.c',
838+
'pthread_testcancel.c',
836839
'emscripten_proxy_main.c',
837840
'emscripten_thread_init.c',
838841
'emscripten_thread_state.S',

0 commit comments

Comments
 (0)