00001 
00004 #ifndef RAZORBACK_LOCK_H
00005 #define RAZORBACK_LOCK_H
00006 
00007 #include <razorback/visibility.h>
00008 #include <razorback/types.h>
00009 
00010 #ifdef _MSC_VER
00011 #else //_MSC_VER
00012 #include <pthread.h>
00013 #include <semaphore.h>
00014 #endif //_MSC_VER
00015 
00016 #ifdef __cplusplus
00017 extern "C" {
00018 #endif
00019 
00020 #define MUTEX_MODE_NORMAL               0       ///< None recursively lockable mutex
00021 #define MUTEX_MODE_RECURSIVE    1       ///< Recursively lockable mutex
00022 
00025 struct Mutex
00026 {
00027 #ifdef _MSC_VER
00028         HANDLE recursiveLock;                   
00029         CRITICAL_SECTION cs;                    
00030 #else
00031     pthread_mutex_t lock;                       
00032     pthread_mutexattr_t attrs;          
00033 #endif
00034         int mode;                                               
00035 };
00036 
00039 struct Semaphore
00040 {
00041 #ifdef _MSC_VER
00042         HANDLE sem;     
00043 #else
00044     sem_t sem;  
00045 #endif
00046 };
00047 
00048 
00053 SO_PUBLIC extern struct Mutex * Mutex_Create(int mode);
00054 
00059 SO_PUBLIC extern bool Mutex_Lock(struct Mutex *mutex);
00060 
00065 SO_PUBLIC extern bool Mutex_Unlock(struct Mutex *mutex);
00066 
00070 SO_PUBLIC extern void Mutex_Destroy(struct Mutex *mutex);
00071 
00077 SO_PUBLIC extern struct Semaphore * Semaphore_Create(bool shared, unsigned int value);
00078 
00083 SO_PUBLIC extern bool Semaphore_Post(struct Semaphore *sem);
00088 SO_PUBLIC extern bool Semaphore_Wait(struct Semaphore *sem);
00089 SO_PUBLIC extern bool Semaphore_TimedWait(struct Semaphore *sem);
00090 
00094 SO_PUBLIC extern void Semaphore_Destroy(struct Semaphore *sem);
00095 
00096 #ifdef __cplusplus
00097 }
00098 #endif
00099 #endif //RAZORBACK_LOCK_H