From 18c086b25d49b7ba812d3b05bb5b5450888e4911 Mon Sep 17 00:00:00 2001 From: danij Date: Mon, 29 Aug 2011 18:08:47 +0100 Subject: [PATCH] Implemented Sem_Value for debug; get the current value of a semaphore. --- doomsday/engine/portable/include/sys_system.h | 10 ++++++++++ doomsday/engine/portable/src/sys_system.c | 20 +++++++++---------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/doomsday/engine/portable/include/sys_system.h b/doomsday/engine/portable/include/sys_system.h index 874bca5fc8..d60b018324 100644 --- a/doomsday/engine/portable/include/sys_system.h +++ b/doomsday/engine/portable/include/sys_system.h @@ -64,7 +64,17 @@ void Sys_Unlock(mutex_t mutexHandle); sem_t Sem_Create(uint32_t initialValue); void Sem_Destroy(sem_t semaphore); + +/** + * "Proberen" a semaphore. Blocks until the successful. + */ void Sem_P(sem_t semaphore); + +/** + * "Verhogen" a semaphore. Returns immediately. + */ void Sem_V(sem_t semaphore); +uint32_t Sem_Value(sem_t semaphore); + #endif /* LIBDENG_FILESYS_SYSTEM_H */ diff --git a/doomsday/engine/portable/src/sys_system.c b/doomsday/engine/portable/src/sys_system.c index f24c98cb2f..40c494ac83 100644 --- a/doomsday/engine/portable/src/sys_system.c +++ b/doomsday/engine/portable/src/sys_system.c @@ -375,11 +375,6 @@ void Sys_Unlock(mutex_t handle) SDL_mutexV((SDL_mutex *) handle); } -/** - * Create a new semaphore. - * - * @return New handle. - */ sem_t Sem_Create(uint32_t initialValue) { return (sem_t) SDL_CreateSemaphore(initialValue); @@ -393,9 +388,6 @@ void Sem_Destroy(sem_t semaphore) } } -/** - * "Proberen" a semaphore. Blocks until the successful. - */ void Sem_P(sem_t semaphore) { if(semaphore) @@ -404,9 +396,6 @@ void Sem_P(sem_t semaphore) } } -/** - * "Verhogen" a semaphore. Returns immediately. - */ void Sem_V(sem_t semaphore) { if(semaphore) @@ -414,3 +403,12 @@ void Sem_V(sem_t semaphore) SDL_SemPost((SDL_sem *) semaphore); } } + +uint32_t Sem_Value(sem_t semaphore) +{ + if(semaphore) + { + return (uint32_t)SDL_SemValue((SDL_sem*)semaphore); + } + return 0; +}