@@ -599,55 +599,45 @@ int cl_thread_trigger_event(cl_thread_settings_t *thread_config) {
599599}
600600
601601int cl_thread_func_testcancel (cl_thread_settings_t *thread_config) {
602- int ret_val = 0 ;
603- int execute_pop = 0 ;
604-
605602 if (thread_config == nullptr ) {
606603 return CL_RETVAL_THREAD_CANCELSTATE_ERROR;
607604 }
608605
609- /* pthread_cleanup_push() and pthread_cleanup_pop() must be used in the
610- same { ... } context */
611-
612606#ifdef CL_DO_COMMLIB_DEBUG
613- gettimeofday (&(thread_config->thread_last_cancel_test_time ),nullptr );
607+ gettimeofday (&(thread_config->thread_last_cancel_test_time ), nullptr );
614608#endif
615609
616- if (thread_config->thread_cleanup_func != nullptr ) {
617- /* push user cleanup function */
618- pthread_cleanup_push ((void (*)(void *)) thread_config->thread_cleanup_func , thread_config) ;
619-
620- /* push default cleanup function */
621- pthread_cleanup_push ((void (*)(void *)) cl_thread_default_cleanup_function, thread_config) ;
622-
623- ret_val = pthread_setcancelstate (PTHREAD_CANCEL_ENABLE, nullptr );
610+ // pthread_cleanup_push() and pthread_cleanup_pop() must be used in the same { ... } context
624611
625- if (ret_val == 0 ) {
626- pthread_testcancel ();
627- ret_val = pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, nullptr );
628- }
629- /* remove cleanup function from stack without execution */
630- pthread_cleanup_pop (execute_pop); /* client_thread_cleanup */
631-
632- /* remove user function from stack without execution */
612+ pthread_setcancelstate (PTHREAD_CANCEL_ENABLE, nullptr );
613+ if (thread_config->thread_cleanup_func != nullptr ) {
614+ #if not defined(XLINUXAMD64)
615+ constexpr int execute_pop = 0 ;
616+ // push user cleanup function
617+ pthread_cleanup_push (reinterpret_cast <void (*)(void *)>(thread_config->thread_cleanup_func ), thread_config) ;
618+ // push default cleanup function
619+ pthread_cleanup_push (reinterpret_cast <void (*)(void *)>(cl_thread_default_cleanup_function), thread_config) ;
620+ #endif
621+ // check if the thread was cancelled - if yes, pthread_testcancel() will not return
622+ pthread_testcancel ();
623+ #if not defined(XLINUXAMD64)
633624 pthread_cleanup_pop (execute_pop);
625+ pthread_cleanup_pop (execute_pop);
626+ #endif
634627 } else {
635- /* push default cleanup function */
636- pthread_cleanup_push (( void (*)( void *)) cl_thread_default_cleanup_function, thread_config) ;
637- ret_val = pthread_setcancelstate (PTHREAD_CANCEL_ENABLE, nullptr );
638-
639- if (ret_val == 0 ) {
640- pthread_testcancel ();
641- ret_val = pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, nullptr );
642- }
643- /* remove cleanup function from stack without execution */
644- pthread_cleanup_pop (execute_pop); /* client_thread_cleanup */
628+ # if not defined(XLINUXAMD64)
629+ constexpr int execute_pop = 0 ;
630+ // push default cleanup function
631+ pthread_cleanup_push ( reinterpret_cast < void (*)( void *)>(cl_thread_default_cleanup_function), thread_config) ;
632+ # endif
633+ // check if the thread was cancelled - if yes, pthread_testcancel() will not return
634+ pthread_testcancel ( );
635+ # if not defined(XLINUXAMD64)
636+ pthread_cleanup_pop (execute_pop);
637+ # endif
645638 }
639+ pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, nullptr );
646640
647-
648- if (ret_val != 0 ) {
649- return CL_RETVAL_THREAD_CANCELSTATE_ERROR;
650- }
651641 return CL_RETVAL_OK;
652642}
653643
0 commit comments