summaryrefslogtreecommitdiffstats
path: root/lib/libthr
diff options
context:
space:
mode:
authordavidxu <davidxu@FreeBSD.org>2006-12-05 06:54:25 +0000
committerdavidxu <davidxu@FreeBSD.org>2006-12-05 06:54:25 +0000
commitf26900460b6cdaada0c389a79033299c96c3d392 (patch)
tree6699e8d2c0b214b4ce0461d7a05f5a95a1ae3d7a /lib/libthr
parentf1f529336506971061548ea5dd335e3874fad4ca (diff)
downloadFreeBSD-src-f26900460b6cdaada0c389a79033299c96c3d392.zip
FreeBSD-src-f26900460b6cdaada0c389a79033299c96c3d392.tar.gz
Use ucond to implement barrier.
Diffstat (limited to 'lib/libthr')
-rw-r--r--lib/libthr/thread/thr_barrier.c9
-rw-r--r--lib/libthr/thread/thr_private.h9
2 files changed, 10 insertions, 8 deletions
diff --git a/lib/libthr/thread/thr_barrier.c b/lib/libthr/thread/thr_barrier.c
index 48fb7dd..cafba69 100644
--- a/lib/libthr/thread/thr_barrier.c
+++ b/lib/libthr/thread/thr_barrier.c
@@ -70,6 +70,7 @@ _pthread_barrier_init(pthread_barrier_t *barrier,
return (ENOMEM);
_thr_umutex_init(&bar->b_lock);
+ _thr_ucond_init(&bar->b_cv);
bar->b_cycle = 0;
bar->b_waiters = 0;
bar->b_count = count;
@@ -83,7 +84,7 @@ _pthread_barrier_wait(pthread_barrier_t *barrier)
{
struct pthread *curthread = _get_curthread();
pthread_barrier_t bar;
- long cycle;
+ int64_t cycle;
int ret;
if (barrier == NULL || *barrier == NULL)
@@ -95,16 +96,16 @@ _pthread_barrier_wait(pthread_barrier_t *barrier)
/* Current thread is lastest thread */
bar->b_waiters = 0;
bar->b_cycle++;
- _thr_umtx_wake(&bar->b_cycle, bar->b_count - 1);
+ _thr_ucond_broadcast(&bar->b_cv);
THR_UMUTEX_UNLOCK(curthread, &bar->b_lock);
ret = PTHREAD_BARRIER_SERIAL_THREAD;
} else {
cycle = bar->b_cycle;
- THR_UMUTEX_UNLOCK(curthread, &bar->b_lock);
do {
- _thr_umtx_wait(&bar->b_cycle, cycle, NULL);
+ _thr_ucond_wait(&bar->b_cv, &bar->b_lock, NULL, 0);
/* test cycle to avoid bogus wakeup */
} while (cycle == bar->b_cycle);
+ THR_UMUTEX_UNLOCK(curthread, &bar->b_lock);
ret = 0;
}
return (ret);
diff --git a/lib/libthr/thread/thr_private.h b/lib/libthr/thread/thr_private.h
index b36fef7..04492ea 100644
--- a/lib/libthr/thread/thr_private.h
+++ b/lib/libthr/thread/thr_private.h
@@ -155,10 +155,11 @@ struct pthread_cond_attr {
};
struct pthread_barrier {
- struct umutex b_lock;
- volatile umtx_t b_cycle;
- volatile int b_count;
- volatile int b_waiters;
+ struct umutex b_lock;
+ struct ucond b_cv;
+ volatile int64_t b_cycle;
+ volatile int b_count;
+ volatile int b_waiters;
};
struct pthread_barrierattr {
OpenPOWER on IntegriCloud