[17] | 1 | /* -*- mode: C; tab-width:8; c-basic-offset:8 -*- |
---|
| 2 | * vi:set ts=8: |
---|
| 3 | * |
---|
| 4 | * mutexlib.h |
---|
| 5 | * |
---|
| 6 | * Include that sorts out which mutex library we're using. |
---|
| 7 | */ |
---|
| 8 | #ifndef MUTEXLIB_H_ |
---|
| 9 | #define MUTEXLIB_H_ |
---|
| 10 | |
---|
| 11 | #include "al_siteconfig.h" |
---|
| 12 | |
---|
| 13 | #if defined(USE_EMPTY_LOCKS) |
---|
| 14 | |
---|
| 15 | #define _alCreateMutex() |
---|
| 16 | #define _alDestroyMutex(m) |
---|
| 17 | #define _alLockMutex(m) |
---|
| 18 | #define _alTryLockMutex(m) |
---|
| 19 | #define _alUnlockMutex(m) |
---|
| 20 | |
---|
| 21 | #else |
---|
| 22 | |
---|
| 23 | #if defined(USE_POSIXTHREADING) |
---|
| 24 | |
---|
| 25 | #include <pthread.h> |
---|
| 26 | typedef pthread_mutex_t *MutexID; |
---|
| 27 | |
---|
| 28 | #elif defined(USE_WINDOWSTHREADING) |
---|
| 29 | |
---|
| 30 | #include <windows.h> |
---|
| 31 | typedef LPCRITICAL_SECTION MutexID; |
---|
| 32 | |
---|
| 33 | #elif defined(USE_MORPHOSTHREADING) |
---|
| 34 | |
---|
| 35 | #include <exec/semaphores.h> |
---|
| 36 | typedef struct SignalSemaphore *MutexID; |
---|
| 37 | |
---|
| 38 | #else |
---|
| 39 | |
---|
| 40 | #error "No mutex package" |
---|
| 41 | |
---|
| 42 | #endif |
---|
| 43 | |
---|
| 44 | /* Creates a new mutex. Returns NULL on error. */ |
---|
| 45 | extern MutexID _alCreateMutex( void ); |
---|
| 46 | |
---|
| 47 | /* Destroys the given mutex, which must be unlocked. */ |
---|
| 48 | extern void _alDestroyMutex( MutexID mutex ); |
---|
| 49 | |
---|
| 50 | /* Locks the given mutex, blocking if it is already locked. */ |
---|
| 51 | extern void _alLockMutex( MutexID mutex ); |
---|
| 52 | |
---|
| 53 | /* Try to lock the given mutex, returning zero if it succeeded, non-zero |
---|
| 54 | otherwise. Non-blocking. */ |
---|
| 55 | extern int _alTryLockMutex( MutexID mutex ); |
---|
| 56 | |
---|
| 57 | /* Unlocks the given mutex, which must be locked by the same thread. */ |
---|
| 58 | extern void _alUnlockMutex( MutexID mutex ); |
---|
| 59 | |
---|
| 60 | #endif /* USE_EMPTY_LOCKS */ |
---|
| 61 | |
---|
| 62 | #endif /* MUTEXLIB_H_ */ |
---|