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