summaryrefslogtreecommitdiff
path: root/src/gallium/include
diff options
context:
space:
mode:
authorBrian Paul <brianp@vmware.com>2009-12-07 17:58:46 -0700
committerBrian Paul <brianp@vmware.com>2009-12-07 18:04:54 -0700
commit87c9ceaea2138e051c48cd8c0fbf5f6658100779 (patch)
tree1eb51a04550a7189cba7674823a630cf80352c0c /src/gallium/include
parent3a06c113c76355fc9622adfe7565c18d9787e9a8 (diff)
gallium: added pipe_semaphore and related code
Diffstat (limited to 'src/gallium/include')
-rw-r--r--src/gallium/include/pipe/p_thread.h50
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 25e4148232..45c35a87d0 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.