Deleted Added
full compact
thr_detach.c (114187) thr_detach.c (115278)
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/libkse/thread/thr_detach.c 114187 2003-04-28 23:56:12Z deischen $
32 * $FreeBSD: head/lib/libkse/thread/thr_detach.c 115278 2003-05-24 02:29:25Z deischen $
33 */
34#include <sys/types.h>
35#include <machine/atomic.h>
36#include <errno.h>
37#include <pthread.h>
38#include "thr_private.h"
39
40__weak_reference(_pthread_detach, pthread_detach);

--- 24 unchanged lines hidden (view full) ---

65 /* Lock the detached thread: */
66 THR_SCHED_LOCK(curthread, pthread);
67
68 /* Flag the thread as detached: */
69 pthread->attr.flags |= PTHREAD_DETACHED;
70
71 /* Retrieve any joining thread and remove it: */
72 joiner = pthread->joiner;
33 */
34#include <sys/types.h>
35#include <machine/atomic.h>
36#include <errno.h>
37#include <pthread.h>
38#include "thr_private.h"
39
40__weak_reference(_pthread_detach, pthread_detach);

--- 24 unchanged lines hidden (view full) ---

65 /* Lock the detached thread: */
66 THR_SCHED_LOCK(curthread, pthread);
67
68 /* Flag the thread as detached: */
69 pthread->attr.flags |= PTHREAD_DETACHED;
70
71 /* Retrieve any joining thread and remove it: */
72 joiner = pthread->joiner;
73 pthread->joiner = NULL;
74 if (joiner->kseg == pthread->kseg) {
73 if ((joiner != NULL) && (joiner->kseg == pthread->kseg)) {
75 /*
76 * We already own the scheduler lock for the joiner.
77 * Take advantage of that and make the joiner runnable.
78 */
79 if (joiner->join_status.thread == pthread) {
80 /*
81 * Set the return value for the woken thread:
82 */
83 joiner->join_status.error = ESRCH;
84 joiner->join_status.ret = NULL;
85 joiner->join_status.thread = NULL;
86
87 _thr_setrunnable_unlocked(joiner);
88 }
89 joiner = NULL;
90 }
91 THR_SCHED_UNLOCK(curthread, pthread);
74 /*
75 * We already own the scheduler lock for the joiner.
76 * Take advantage of that and make the joiner runnable.
77 */
78 if (joiner->join_status.thread == pthread) {
79 /*
80 * Set the return value for the woken thread:
81 */
82 joiner->join_status.error = ESRCH;
83 joiner->join_status.ret = NULL;
84 joiner->join_status.thread = NULL;
85
86 _thr_setrunnable_unlocked(joiner);
87 }
88 joiner = NULL;
89 }
90 THR_SCHED_UNLOCK(curthread, pthread);
92 _thr_ref_delete(curthread, pthread);
93
94 /* See if there is a thread waiting in pthread_join(): */
91
92 /* See if there is a thread waiting in pthread_join(): */
95 if (joiner != NULL && _thr_ref_add(curthread, joiner, 0) == 0) {
93 if ((joiner != NULL) &&
94 (_thr_ref_add(curthread, joiner, 0) == 0)) {
96 /* Lock the joiner before fiddling with it. */
97 THR_SCHED_LOCK(curthread, joiner);
98 if (joiner->join_status.thread == pthread) {
99 /*
100 * Set the return value for the woken thread:
101 */
102 joiner->join_status.error = ESRCH;
103 joiner->join_status.ret = NULL;
104 joiner->join_status.thread = NULL;
105
106 _thr_setrunnable_unlocked(joiner);
107 }
108 THR_SCHED_UNLOCK(curthread, joiner);
109 _thr_ref_delete(curthread, joiner);
110 }
95 /* Lock the joiner before fiddling with it. */
96 THR_SCHED_LOCK(curthread, joiner);
97 if (joiner->join_status.thread == pthread) {
98 /*
99 * Set the return value for the woken thread:
100 */
101 joiner->join_status.error = ESRCH;
102 joiner->join_status.ret = NULL;
103 joiner->join_status.thread = NULL;
104
105 _thr_setrunnable_unlocked(joiner);
106 }
107 THR_SCHED_UNLOCK(curthread, joiner);
108 _thr_ref_delete(curthread, joiner);
109 }
110 _thr_ref_delete(curthread, pthread);
111 }
112
113 /* Return the completion status: */
114 return (rval);
115}
111 }
112
113 /* Return the completion status: */
114 return (rval);
115}