aboutsummaryrefslogtreecommitdiffstats
path: root/OpenAL32
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2014-04-16 01:39:11 -0700
committerChris Robinson <[email protected]>2014-04-16 01:39:11 -0700
commit29cb5058c0b05cca8ebeb40d84aba8a8d2e11075 (patch)
tree749d963f365901b22eabd8eaf164f38f2efb8789 /OpenAL32
parent9c70ca9da6479595946def59cd616e6823c86d78 (diff)
Use a C11-like mutex wrapper instead of CRITICAL_SECTIONs
Diffstat (limited to 'OpenAL32')
-rw-r--r--OpenAL32/Include/threads.h86
1 files changed, 86 insertions, 0 deletions
diff --git a/OpenAL32/Include/threads.h b/OpenAL32/Include/threads.h
index 26493101..03589d15 100644
--- a/OpenAL32/Include/threads.h
+++ b/OpenAL32/Include/threads.h
@@ -11,4 +11,90 @@ ALuint StopThread(althread_t thread);
void SetThreadName(const char *name);
+
+enum {
+ althrd_success = 0,
+ althrd_timeout,
+ althrd_error,
+ althrd_busy,
+ althrd_nomem
+};
+
+enum {
+ almtx_plain = 0,
+ almtx_recursive = 1,
+ almtx_timed = 2,
+ almtx_normal = 4,
+ almtx_errorcheck = 8
+};
+
+typedef struct alxtime {
+ time_t sec;
+ long nsec;
+} alxtime;
+
+
+#ifdef _WIN32
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+
+typedef CRITICAL_SECTION almtx_t;
+
+inline int almtx_lock(almtx_t *mtx)
+{
+ if(!mtx) return althrd_error;
+ EnterCriticalSection(mtx);
+ return althrd_success;
+}
+
+inline int almtx_unlock(almtx_t *mtx)
+{
+ if(!mtx) return althrd_error;
+ LeaveCriticalSection(mtx);
+ return althrd_success;
+}
+
+inline int almtx_trylock(almtx_t *mtx)
+{
+ if(!mtx) return althrd_error;
+ if(!TryEnterCriticalSection(mtx))
+ return althrd_busy;
+ return althrd_success;
+}
+
+#else
+
+#include <pthread.h>
+
+
+typedef pthread_mutex_t almtx_t;
+
+inline int almtx_lock(almtx_t *mtx)
+{
+ if(!mtx) return althrd_error;
+ pthread_mutex_lock(mtx);
+ return althrd_success;
+}
+
+inline int almtx_unlock(almtx_t *mtx)
+{
+ if(!mtx) return althrd_error;
+ pthread_mutex_unlock(mtx);
+ return althrd_success;
+}
+
+inline int almtx_trylock(almtx_t *mtx)
+{
+ if(!mtx) return althrd_error;
+ if(pthread_mutex_trylock(mtx) != 0)
+ return althrd_busy;
+ return althrd_success;
+}
+
+#endif
+
+int almtx_init(almtx_t *mtx, int type);
+void almtx_destroy(almtx_t *mtx);
+int almtx_timedlock(almtx_t *mtx, const alxtime *xt);
+
#endif /* AL_THREADS_H */