Deleted Added
full compact
thr_barrier.c (126000) thr_barrier.c (129484)
1/*-
2 * Copyright (c) 2004 Michael Telahun Makonnen <mtm@FreeBSD.Org>
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

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

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
1/*-
2 * Copyright (c) 2004 Michael Telahun Makonnen <mtm@FreeBSD.Org>
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

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

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * $FreeBSD: head/lib/libthr/thread/thr_barrier.c 126000 2004-02-19 13:51:52Z mtm $
26 * $FreeBSD: head/lib/libthr/thread/thr_barrier.c 129484 2004-05-20 12:06:16Z mtm $
27 */
28
29#include <pthread.h>
30#include <stdlib.h>
31#include <string.h>
32
33#include "thr_private.h"
34

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

80 * Check if threads waiting on the barrier can be released. If
81 * so, release them and make this last thread the special thread.
82 */
83 error = 0;
84 b = *barrier;
85 UMTX_LOCK(&b->b_lock);
86 if (b->b_subtotal == (b->b_total - 1)) {
87 TAILQ_FOREACH(ptd, &b->b_barrq, sqe) {
27 */
28
29#include <pthread.h>
30#include <stdlib.h>
31#include <string.h>
32
33#include "thr_private.h"
34

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

80 * Check if threads waiting on the barrier can be released. If
81 * so, release them and make this last thread the special thread.
82 */
83 error = 0;
84 b = *barrier;
85 UMTX_LOCK(&b->b_lock);
86 if (b->b_subtotal == (b->b_total - 1)) {
87 TAILQ_FOREACH(ptd, &b->b_barrq, sqe) {
88 _thread_critical_enter(ptd);
89 PTHREAD_NEW_STATE(ptd, PS_RUNNING);
88 PTHREAD_LOCK(ptd);
90 TAILQ_REMOVE(&b->b_barrq, ptd, sqe);
89 TAILQ_REMOVE(&b->b_barrq, ptd, sqe);
90 ptd->flags &= ~PTHREAD_FLAGS_IN_BARRQ;
91 ptd->flags |= PTHREAD_FLAGS_BARR_REL;
91 ptd->flags |= PTHREAD_FLAGS_BARR_REL;
92 _thread_critical_exit(ptd);
92 PTHREAD_WAKE(ptd);
93 PTHREAD_UNLOCK(ptd);
93 }
94 b->b_subtotal = 0;
95 UMTX_UNLOCK(&b->b_lock);
96 return (PTHREAD_BARRIER_SERIAL_THREAD);
97 }
98
99 /*
100 * More threads need to reach the barrier. Suspend this thread.
101 */
94 }
95 b->b_subtotal = 0;
96 UMTX_UNLOCK(&b->b_lock);
97 return (PTHREAD_BARRIER_SERIAL_THREAD);
98 }
99
100 /*
101 * More threads need to reach the barrier. Suspend this thread.
102 */
102 _thread_critical_enter(curthread);
103 PTHREAD_LOCK(curthread);
103 TAILQ_INSERT_HEAD(&b->b_barrq, curthread, sqe);
104 TAILQ_INSERT_HEAD(&b->b_barrq, curthread, sqe);
104 PTHREAD_NEW_STATE(curthread, PS_BARRIER_WAIT);
105 _thread_critical_exit(curthread);
105 curthread->flags |= PTHREAD_FLAGS_IN_BARRQ;
106 PTHREAD_UNLOCK(curthread);
106 b->b_subtotal++;
107 PTHREAD_ASSERT(b->b_subtotal < b->b_total,
108 "the number of threads waiting at a barrier is too large");
109 UMTX_UNLOCK(&b->b_lock);
110 do {
111 error = _thread_suspend(curthread, NULL);
112 if (error == EINTR) {
113 /*
114 * Make sure this thread wasn't released from
115 * the barrier while it was handling the signal.
116 */
107 b->b_subtotal++;
108 PTHREAD_ASSERT(b->b_subtotal < b->b_total,
109 "the number of threads waiting at a barrier is too large");
110 UMTX_UNLOCK(&b->b_lock);
111 do {
112 error = _thread_suspend(curthread, NULL);
113 if (error == EINTR) {
114 /*
115 * Make sure this thread wasn't released from
116 * the barrier while it was handling the signal.
117 */
117 _thread_critical_enter(curthread);
118 PTHREAD_LOCK(curthread);
118 if ((curthread->flags & PTHREAD_FLAGS_BARR_REL) != 0) {
119 curthread->flags &= ~PTHREAD_FLAGS_BARR_REL;
119 if ((curthread->flags & PTHREAD_FLAGS_BARR_REL) != 0) {
120 curthread->flags &= ~PTHREAD_FLAGS_BARR_REL;
120 _thread_critical_exit(curthread);
121 PTHREAD_UNLOCK(curthread);
121 error = 0;
122 break;
123 }
122 error = 0;
123 break;
124 }
124 PTHREAD_NEW_STATE(curthread, PS_BARRIER_WAIT);
125 _thread_critical_exit(curthread);
125 PTHREAD_UNLOCK(curthread);
126 }
127 } while (error == EINTR);
128 return (error);
129}
126 }
127 } while (error == EINTR);
128 return (error);
129}