Permalink
Browse files

Changed the event API to use semaphores

  • Loading branch information...
John
John committed Oct 8, 2012
1 parent 8fde60f commit 002edab07df7660b9f7f58c7d81207436eb5e660
Showing with 18 additions and 22 deletions.
  1. +11 −15 Thread.c
  2. +7 −7 Thread.h
View
@@ -135,42 +135,38 @@ void SAL_Mutex_Release(SAL_Mutex mutex) {
}
/**
- * Create a new event.
+ * Create a new semaphore.
*
- * @return a new event
+ * @return a new semaphore
*/
-SAL_Event SAL_Event_Create(void) {
+SAL_Semaphore SAL_Semaphore_Create(void) {
#ifdef WINDOWS
- return CreateEvent(null, false, false, null);
+ return CreateSemaphore(null, 0, 4294967295, null);
#elif defined POSIX
#endif
}
-void SAL_Event_Free(SAL_Event event) {
+void SAL_Semaphore_Free(SAL_Semaphore Semaphore) {
#ifdef WINDOWS
- CloseHandle(event);
+ CloseHandle(Semaphore);
#elif defined POSIX
#endif
}
-uint64 SAL_Event_Wait(SAL_Event event) {
+void SAL_Semaphore_Decrement(SAL_Semaphore Semaphore) {
#ifdef WINDOWS
- DWORD result;
-
- result = WaitForSingleObject(event, INFINITE);
-
- return result;
+ WaitForSingleObject(Semaphore, INFINITE);
#elif defined POSIX
#endif
}
-void SAL_Event_Signal(SAL_Event event) {
+void SAL_Semaphore_Increment(SAL_Semaphore Semaphore) {
#ifdef WINDOWS
- SetEvent(event);
+ ReleaseSemaphore(Semaphore, 1, null);
#elif defined POSIX
#endif
-}
+}
View
@@ -7,16 +7,16 @@
typedef unsigned long (__stdcall *SAL_Thread_StartAddress)(void* SAL_Thread_StartParameter);
typedef void* SAL_Thread;
typedef void* SAL_Mutex;
- typedef void* SAL_Event;
+ typedef void* SAL_Semaphore;
#elif defined POSIX
#include <pthread.h>
#include <errno.h>
-
+
typedef void* (*SAL_Thread_StartAddress)(void* SAL_Thread_StartParameter);
typedef pthread_t SAL_Thread;
typedef pthread_mutex_t* SAL_Mutex;
- typedef pthread_cond_t* SAL_Event;
+ typedef pthread_cond_t* SAL_Semaphore;
#endif
public SAL_Thread SAL_Thread_Create(SAL_Thread_StartAddress startAddress, void* startParameter);
@@ -28,9 +28,9 @@ public uint8 SAL_Mutex_Free(SAL_Mutex mutex);
public void SAL_Mutex_Acquire(SAL_Mutex mutex);
public void SAL_Mutex_Release(SAL_Mutex mutex);
-public SAL_Event SAL_Event_Create(void);
-public void SAL_Event_Free(SAL_Event event);
-public uint64 SAL_Event_Wait(SAL_Event event);
-public void SAL_Event_Signal(SAL_Event event);
+public SAL_Semaphore SAL_Semaphore_Create(void);
+public void SAL_Semaphore_Free(SAL_Semaphore Semaphore);
+public void SAL_Semaphore_Decrement(SAL_Semaphore Semaphore);
+public void SAL_Semaphore_Increment(SAL_Semaphore Semaphore);
#endif

0 comments on commit 002edab

Please sign in to comment.