diff options
author | Brian Paul <[email protected]> | 2009-12-07 17:58:46 -0700 |
---|---|---|
committer | Brian Paul <[email protected]> | 2009-12-07 18:04:54 -0700 |
commit | 87c9ceaea2138e051c48cd8c0fbf5f6658100779 (patch) | |
tree | 1eb51a04550a7189cba7674823a630cf80352c0c /src/gallium | |
parent | 3a06c113c76355fc9622adfe7565c18d9787e9a8 (diff) |
gallium: added pipe_semaphore and related code
Diffstat (limited to 'src/gallium')
-rw-r--r-- | 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 25e41482325..45c35a87d0e 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. |