PERFORCE change 69094 for review
David Xu
davidxu at FreeBSD.org
Sat Jan 15 16:45:38 PST 2005
http://perforce.freebsd.org/chv.cgi?CH=69094
Change 69094 by davidxu at davidxu_tiger on 2005/01/16 00:45:34
Use umtx_wait and umtx_wake.
Affected files ...
.. //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_barrier.c#3 edit
.. //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_barrierattr.c#3 edit
Differences ...
==== //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_barrier.c#3 (text+ko) ====
@@ -41,7 +41,6 @@
_pthread_barrier_destroy(pthread_barrier_t *barrier)
{
pthread_barrier_t bar;
- int ret, ret2;
if (barrier == NULL || *barrier == NULL)
return (EINVAL);
@@ -50,10 +49,8 @@
if (bar->b_waiters > 0)
return (EBUSY);
*barrier = NULL;
- ret = _pthread_mutex_destroy(&bar->b_lock);
- ret2 = _pthread_cond_destroy(&bar->b_cond);
free(bar);
- return (ret ? ret : ret2);
+ return (0);
}
int
@@ -61,7 +58,6 @@
const pthread_barrierattr_t *attr, int count)
{
pthread_barrier_t bar;
- int ret;
if (barrier == NULL || count <= 0)
return (EINVAL);
@@ -70,20 +66,10 @@
if (bar == NULL)
return (ENOMEM);
- if ((ret = _pthread_mutex_init(&bar->b_lock, NULL)) != 0) {
- free(bar);
- return (ret);
- }
-
- if ((ret = _pthread_cond_init(&bar->b_cond, NULL)) != 0) {
- _pthread_mutex_destroy(&bar->b_lock);
- free(bar);
- return (ret);
- }
-
+ umtx_init(&bar->b_lock);
+ bar->b_cycle = 0;
bar->b_waiters = 0;
bar->b_count = count;
- bar->b_cycle = 0;
*barrier = bar;
return (0);
@@ -92,31 +78,31 @@
int
_pthread_barrier_wait(pthread_barrier_t *barrier)
{
- int ret, cycle;
+ struct pthread *curthread = _get_curthread();
pthread_barrier_t bar;
+ long cycle;
+ int ret;
if (barrier == NULL || *barrier == NULL)
return (EINVAL);
bar = *barrier;
- if ((ret = _pthread_mutex_lock(&bar->b_lock)) != 0)
- return (ret);
-
+ THR_UMTX_LOCK(curthread, &bar->b_lock);
if (++bar->b_waiters == bar->b_count) {
/* Current thread is lastest thread */
+ bar->b_waiters = 0;
bar->b_cycle++;
- bar->b_waiters = 0;
- ret = _pthread_cond_broadcast(&bar->b_cond);
- if (ret == 0)
- ret = PTHREAD_BARRIER_SERIAL_THREAD;
+ umtx_wake((struct umtx *)&bar->b_cycle, INT_MAX);
+ THR_UMTX_UNLOCK(curthread, &bar->b_lock);
+ ret = PTHREAD_BARRIER_SERIAL_THREAD;
} else {
cycle = bar->b_cycle;
+ THR_UMTX_UNLOCK(curthread, &bar->b_lock);
do {
- ret = _pthread_cond_wait(
- &bar->b_cond, &bar->b_lock);
- /* test cycle to avoid bogus wakeup */
- } while (ret == 0 && cycle == bar->b_cycle);
+ umtx_wait((struct umtx *)&bar->b_cycle, cycle);
+ /* test cycle to avoid bogus wakeup */
+ } while (cycle == bar->b_cycle);
+ ret = 0;
}
- _pthread_mutex_unlock(&bar->b_lock);
return (ret);
}
==== //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_barrierattr.c#3 (text+ko) ====
More information about the p4-projects
mailing list