1 #include "pthread_impl.h" 2 #include <threads.h> 3 __pthread_detach(pthread_t t)4static int __pthread_detach(pthread_t t) 5 { 6 int ret; 7 8 /* If the cas fails, detach state is either already-detached 9 * or exiting/exited, and pthread_join will trap or cleanup. */ 10 if (a_cas(&t->detach_state, DT_JOINABLE, DT_DETACHED) != DT_JOINABLE) 11 return __pthread_join(t, 0); 12 ret = __syscall(SYS_pthread_set_detach, t->tid); 13 if (ret) a_swap(&t->detach_state, DT_JOINABLE); 14 if (ret == ESRCH) ret = 0; 15 return ret; 16 } 17 18 weak_alias(__pthread_detach, pthread_detach); 19 weak_alias(__pthread_detach, thrd_detach); 20