@@ -408,6 +408,7 @@ 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.
411
412
if ( ! ENVIRONMENT_IS_PTHREAD ) cleanupThread ( thread ) ;
412
413
else postMessage ( { 'cmd' : 'cleanupThread' , 'thread' : thread } ) ;
413
414
} ,
@@ -751,12 +752,12 @@ var LibraryPThread = {
751
752
#endif
752
753
} ,
753
754
754
- pthread_kill__deps : [ '$killThread' , ' emscripten_main_browser_thread_id'] ,
755
+ pthread_kill__deps : [ 'emscripten_main_browser_thread_id' ] ,
755
756
pthread_kill : function ( thread , signal ) {
756
757
if ( signal < 0 || signal >= 65 /*_NSIG*/ ) return { { { cDefine ( 'EINVAL' ) } } } ;
757
758
if ( thread === _emscripten_main_browser_thread_id ( ) ) {
758
759
if ( signal == 0 ) return 0 ; // signal == 0 is a no-op.
759
- err ( 'Main thread (id=' + thread + ') cannot be killed with pthread_kill!' ) ;
760
+ err ( 'Main thread (id=0x ' + thread . toString ( 16 ) + ') cannot be killed with pthread_kill!' ) ;
760
761
return { { { cDefine ( 'ESRCH' ) } } } ;
761
762
}
762
763
if ( ! thread ) {
@@ -765,38 +766,19 @@ var LibraryPThread = {
765
766
}
766
767
var self = { { { makeGetValue ( 'thread' , C_STRUCTS . pthread . self , 'i32' ) } } } ;
767
768
if ( self !== thread ) {
768
- err ( 'pthread_kill attempted on thread ' + thread + ', which does not point to a valid thread, or does not exist anymore!' ) ;
769
+ err ( 'pthread_kill attempted on thread 0x ' + thread . toString ( 16 ) + ', which does not point to a valid thread, or does not exist anymore!' ) ;
769
770
return { { { cDefine ( 'ESRCH' ) } } } ;
770
771
}
771
- if ( signal != 0 ) {
772
+ if ( signal === { { { cDefine ( 'SIGCANCEL' ) } } } ) { // Used by pthread_cancel in musl
773
+ if ( ! ENVIRONMENT_IS_PTHREAD ) cancelThread ( thread ) ;
774
+ else postMessage ( { 'cmd' : 'cancelThread' , 'thread' : thread } ) ;
775
+ } else if ( signal != 0 ) {
772
776
if ( ! ENVIRONMENT_IS_PTHREAD ) killThread ( thread ) ;
773
- else postMessage ( { 'cmd' : 'killThread' , 'thread' : thread } ) ;
777
+ else postMessage ( { 'cmd' : 'killThread' , 'thread' : thread } ) ;
774
778
}
775
779
return 0 ;
776
780
} ,
777
781
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
782
// Returns 0 on success, or one of the values -ETIMEDOUT, -EWOULDBLOCK or -EINVAL on error.
801
783
_emscripten_futex_wait_non_blocking__deps: [ 'emscripten_main_thread_process_queued_calls' ] ,
802
784
_emscripten_futex_wait_non_blocking : function ( addr , val , timeout ) {
0 commit comments