Mesa (lp-binning): gallium: added pipe_semaphore and related code
Brian Paul
brianp at kemper.freedesktop.org
Tue Dec 8 01:16:04 UTC 2009
Module: Mesa
Branch: lp-binning
Commit: 87c9ceaea2138e051c48cd8c0fbf5f6658100779
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=87c9ceaea2138e051c48cd8c0fbf5f6658100779
Author: Brian Paul <brianp at vmware.com>
Date: Mon Dec 7 17:58:46 2009 -0700
gallium: added pipe_semaphore and related code
---
src/gallium/include/pipe/p_thread.h | 50 +++++++++++++++++++++++++++++++++++
1 files changed, 50 insertions(+), 0 deletions(-)
diff --git a/src/gallium/include/pipe/p_thread.h b/src/gallium/include/pipe/p_thread.h
index 25e4148..45c35a8 100644
--- a/src/gallium/include/pipe/p_thread.h
+++ b/src/gallium/include/pipe/p_thread.h
@@ -207,6 +207,56 @@ typedef unsigned pipe_condvar;
#endif /* PIPE_OS_? */
+/*
+ * Semaphores
+ */
+
+typedef struct
+{
+ pipe_mutex mutex;
+ pipe_condvar cond;
+ int counter;
+} pipe_semaphore;
+
+
+static INLINE void
+pipe_semaphore_init(pipe_semaphore *sema, int init_val)
+{
+ pipe_mutex_init(sema->mutex);
+ pipe_condvar_init(sema->cond);
+ sema->counter = init_val;
+}
+
+static INLINE void
+pipe_semaphore_destroy(pipe_semaphore *sema)
+{
+ pipe_mutex_destroy(sema->mutex);
+ pipe_condvar_destroy(sema->cond);
+}
+
+/** Signal/increment semaphore counter */
+static INLINE void
+pipe_semaphore_signal(pipe_semaphore *sema)
+{
+ pipe_mutex_lock(sema->mutex);
+ sema->counter++;
+ pipe_condvar_signal(sema->cond);
+ pipe_mutex_unlock(sema->mutex);
+}
+
+/** Wait for semaphore counter to be greater than zero */
+static INLINE void
+pipe_semaphore_wait(pipe_semaphore *sema)
+{
+ pipe_mutex_lock(sema->mutex);
+ while (sema->counter <= 0) {
+ pipe_condvar_wait(sema->cond, sema->mutex);
+ }
+ sema->counter--;
+ pipe_mutex_unlock(sema->mutex);
+}
+
+
/*
* Thread-specific data.
More information about the mesa-commit
mailing list