summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVinson Lee <vlee@vmware.com>2010-04-17 14:24:23 -0700
committerVinson Lee <vlee@vmware.com>2010-04-17 14:24:23 -0700
commit35aae6839e7bf29e602f6bf9e8730cc62d83f8cd (patch)
tree12cc3dd2d1ba694fa0777b693298f0694b87ab3d /src
parent44bafca1a0b1e9bf06e05a3ec982e0feab5ada47 (diff)
downloadexternal_mesa3d-35aae6839e7bf29e602f6bf9e8730cc62d83f8cd.zip
external_mesa3d-35aae6839e7bf29e602f6bf9e8730cc62d83f8cd.tar.gz
external_mesa3d-35aae6839e7bf29e602f6bf9e8730cc62d83f8cd.tar.bz2
os: Implement pipe_barrier for POSIX platforms without pthread_barrier_t.
This patch was tested on Mac OS X.
Diffstat (limited to 'src')
-rw-r--r--src/gallium/auxiliary/os/os_thread.h31
1 files changed, 26 insertions, 5 deletions
diff --git a/src/gallium/auxiliary/os/os_thread.h b/src/gallium/auxiliary/os/os_thread.h
index 004dad6..07a4268 100644
--- a/src/gallium/auxiliary/os/os_thread.h
+++ b/src/gallium/auxiliary/os/os_thread.h
@@ -299,22 +299,43 @@ static INLINE void pipe_barrier_wait(pipe_barrier *barrier)
#else
-typedef unsigned pipe_barrier;
+typedef struct {
+ unsigned count;
+ unsigned waiters;
+ pipe_mutex mutex;
+ pipe_condvar condvar;
+} pipe_barrier;
static INLINE void pipe_barrier_init(pipe_barrier *barrier, unsigned count)
{
- /* XXX we could implement barriers with a mutex and condition var */
- assert(0);
+ barrier->count = count;
+ barrier->waiters = 0;
+ pipe_mutex_init(barrier->mutex);
+ pipe_condvar_init(barrier->condvar);
}
static INLINE void pipe_barrier_destroy(pipe_barrier *barrier)
{
- assert(0);
+ assert(barrier->waiters == 0);
+ pipe_mutex_destroy(barrier->mutex);
+ pipe_condvar_destroy(barrier->condvar);
}
static INLINE void pipe_barrier_wait(pipe_barrier *barrier)
{
- assert(0);
+ pipe_mutex_lock(barrier->mutex);
+
+ assert(barrier->waiters < barrier->count);
+ barrier->waiters++;
+
+ if (barrier->waiters < barrier->count) {
+ pipe_condvar_wait(barrier->condvar, barrier->mutex);
+ } else {
+ barrier->waiters = 0;
+ pipe_condvar_broadcast(barrier->condvar);
+ }
+
+ pipe_mutex_unlock(barrier->mutex);
}