thr_detach.c (127568) | thr_detach.c (129484) |
---|---|
1/* 2 * Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 15 unchanged lines hidden (view full) --- 24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 * | 1/* 2 * Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 15 unchanged lines hidden (view full) --- 24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 * |
32 * $FreeBSD: head/lib/libthr/thread/thr_detach.c 127568 2004-03-29 13:51:51Z mtm $ | 32 * $FreeBSD: head/lib/libthr/thread/thr_detach.c 129484 2004-05-20 12:06:16Z mtm $ |
33 */ 34#include <errno.h> 35#include <pthread.h> 36#include <stdlib.h> 37#include "thr_private.h" 38 39__weak_reference(_pthread_detach, pthread_detach); 40 41int 42_pthread_detach(pthread_t pthread) 43{ | 33 */ 34#include <errno.h> 35#include <pthread.h> 36#include <stdlib.h> 37#include "thr_private.h" 38 39__weak_reference(_pthread_detach, pthread_detach); 40 41int 42_pthread_detach(pthread_t pthread) 43{ |
44 int error; 45 |
|
44 if (pthread->magic != PTHREAD_MAGIC) 45 return (EINVAL); 46 | 46 if (pthread->magic != PTHREAD_MAGIC) 47 return (EINVAL); 48 |
47 UMTX_LOCK(&pthread->lock); | 49 PTHREAD_LOCK(pthread); |
48 49 if ((pthread->attr.flags & PTHREAD_DETACHED) != 0) { | 50 51 if ((pthread->attr.flags & PTHREAD_DETACHED) != 0) { |
50 UMTX_UNLOCK(&pthread->lock); 51 return ((pthread->state == PS_DEAD) ? ESRCH : EINVAL); | 52 _thread_sigblock(); 53 DEAD_LIST_LOCK; 54 error = pthread->isdead ? ESRCH : EINVAL; 55 DEAD_LIST_UNLOCK; 56 _thread_sigunblock(); 57 PTHREAD_UNLOCK(pthread); 58 return (error); |
52 } 53 54 pthread->attr.flags |= PTHREAD_DETACHED; 55 56 /* Check if there is a joiner: */ 57 if (pthread->joiner != NULL) { 58 struct pthread *joiner = pthread->joiner; | 59 } 60 61 pthread->attr.flags |= PTHREAD_DETACHED; 62 63 /* Check if there is a joiner: */ 64 if (pthread->joiner != NULL) { 65 struct pthread *joiner = pthread->joiner; |
59 _thread_critical_enter(joiner); | |
60 | 66 |
61 /* Make the thread runnable: */ 62 PTHREAD_NEW_STATE(joiner, PS_RUNNING); 63 | |
64 /* Set the return value for the woken thread: */ 65 joiner->join_status.error = ESRCH; 66 joiner->join_status.ret = NULL; 67 joiner->join_status.thread = NULL; 68 69 /* 70 * Disconnect the joiner from the thread being detached: 71 */ 72 pthread->joiner = NULL; | 67 /* Set the return value for the woken thread: */ 68 joiner->join_status.error = ESRCH; 69 joiner->join_status.ret = NULL; 70 joiner->join_status.thread = NULL; 71 72 /* 73 * Disconnect the joiner from the thread being detached: 74 */ 75 pthread->joiner = NULL; |
73 _thread_critical_exit(joiner); | 76 PTHREAD_WAKE(joiner); |
74 } 75 | 77 } 78 |
76 UMTX_UNLOCK(&pthread->lock); | 79 PTHREAD_UNLOCK(pthread); |
77 78 return (0); 79} | 80 81 return (0); 82} |