@@ -408,6 +408,11 @@ var LibraryPThread = {
408
408
} ,
409
409
410
410
__emscripten_thread_cleanup : function ( thread ) {
411
+ // Called when a thread needs to be cleaned up so it can be reused.
412
+ // A thread is considered reusable when it either returns from its
413
+ // entry point, calls pthread_exit, or acts upon a cancellation.
414
+ // Detached threads are responsible for calling this themselves,
415
+ // otherwise pthread_join is responsible for calling this.
411
416
if ( ! ENVIRONMENT_IS_PTHREAD ) cleanupThread ( thread ) ;
412
417
else postMessage ( { 'cmd' : 'cleanupThread' , 'thread' : thread } ) ;
413
418
} ,
@@ -751,12 +756,12 @@ var LibraryPThread = {
751
756
#endif
752
757
} ,
753
758
754
- pthread_kill__deps : [ '$killThread' , ' emscripten_main_browser_thread_id'] ,
759
+ pthread_kill__deps : [ 'emscripten_main_browser_thread_id' ] ,
755
760
pthread_kill : function ( thread , signal ) {
756
761
if ( signal < 0 || signal >= 65 /*_NSIG*/ ) return { { { cDefine ( 'EINVAL' ) } } } ;
757
762
if ( thread === _emscripten_main_browser_thread_id ( ) ) {
758
763
if ( signal == 0 ) return 0 ; // signal == 0 is a no-op.
759
- err ( 'Main thread (id=' + thread + ') cannot be killed with pthread_kill!' ) ;
764
+ err ( 'Main thread (id=0x ' + thread . toString ( 16 ) + ') cannot be killed with pthread_kill!' ) ;
760
765
return { { { cDefine ( 'ESRCH' ) } } } ;
761
766
}
762
767
if ( ! thread ) {
@@ -765,38 +770,19 @@ var LibraryPThread = {
765
770
}
766
771
var self = { { { makeGetValue ( 'thread' , C_STRUCTS . pthread . self , 'i32' ) } } } ;
767
772
if ( self !== thread ) {
768
- err ( 'pthread_kill attempted on thread ' + thread + ', which does not point to a valid thread, or does not exist anymore!' ) ;
773
+ err ( 'pthread_kill attempted on thread 0x ' + thread . toString ( 16 ) + ', which does not point to a valid thread, or does not exist anymore!' ) ;
769
774
return { { { cDefine ( 'ESRCH' ) } } } ;
770
775
}
771
- if ( signal != 0 ) {
776
+ if ( signal === { { { cDefine ( 'SIGCANCEL' ) } } } ) { // Used by pthread_cancel in musl
777
+ if ( ! ENVIRONMENT_IS_PTHREAD ) cancelThread ( thread ) ;
778
+ else postMessage ( { 'cmd' : 'cancelThread' , 'thread' : thread } ) ;
779
+ } else if ( signal != 0 ) {
772
780
if ( ! ENVIRONMENT_IS_PTHREAD ) killThread ( thread ) ;
773
- else postMessage ( { 'cmd' : 'killThread' , 'thread' : thread } ) ;
781
+ else postMessage ( { 'cmd' : 'killThread' , 'thread' : thread } ) ;
774
782
}
775
783
return 0 ;
776
784
} ,
777
785
778
- pthread_cancel__deps: [ '$cancelThread' , 'emscripten_main_browser_thread_id' ] ,
779
- pthread_cancel : function ( thread ) {
780
- if ( thread === _emscripten_main_browser_thread_id ( ) ) {
781
- err ( 'Main thread (id=' + thread + ') cannot be canceled!' ) ;
782
- return { { { cDefine ( 'ESRCH' ) } } } ;
783
- }
784
- if ( ! thread ) {
785
- err ( 'pthread_cancel attempted on a null thread pointer!' ) ;
786
- return { { { cDefine ( 'ESRCH' ) } } } ;
787
- }
788
- var self = { { { makeGetValue ( 'thread' , C_STRUCTS . pthread . self , 'i32' ) } } } ;
789
- if ( self !== thread ) {
790
- err ( 'pthread_cancel attempted on thread ' + thread + ', which does not point to a valid thread, or does not exist anymore!' ) ;
791
- return { { { cDefine ( 'ESRCH' ) } } } ;
792
- }
793
- // Signal the thread that it needs to cancel itself.
794
- Atomics . store ( HEAPU32 , ( thread + { { { C_STRUCTS . pthread . cancel } } } ) >> 2 , 1 ) ;
795
- if ( ! ENVIRONMENT_IS_PTHREAD ) cancelThread ( thread ) ;
796
- else postMessage ( { 'cmd' : 'cancelThread' , 'thread' : thread } ) ;
797
- return 0 ;
798
- } ,
799
-
800
786
// Returns 0 on success, or one of the values -ETIMEDOUT, -EWOULDBLOCK or -EINVAL on error.
801
787
_emscripten_futex_wait_non_blocking__deps: [ 'emscripten_main_thread_process_queued_calls' ] ,
802
788
_emscripten_futex_wait_non_blocking : function ( addr , val , timeout ) {
0 commit comments