00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef TDSTHREAD_H
00022 #define TDSTHREAD_H 1
00023
00024
00025
00026 #if defined(_THREAD_SAFE) && defined(TDS_HAVE_PTHREAD_MUTEX)
00027
00028 #include <pthread.h>
00029
00030 #define TDS_MUTEX_DECLARE(name) pthread_mutex_t name = PTHREAD_MUTEX_INITIALIZER
00031 #define TDS_MUTEX_LOCK(a) pthread_mutex_lock(a)
00032 #define TDS_MUTEX_UNLOCK(a) pthread_mutex_unlock(a)
00033 #define TDS_MUTEX_T pthread_mutex_t
00034 #define TDS_MUTEX_DECLARE_RECURSIVE(name) pthread_mutex_t name = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
00035 #define TDS_MUTEX_INIT_RECURSIVE(mutex) do { \
00036 pthread_mutexattr_t _attr; \
00037 pthread_mutexattr_init(&_attr); \
00038 pthread_mutexattr_settype(&_attr, PTHREAD_MUTEX_RECURSIVE); \
00039 pthread_mutex_init(mutex, &_attr); \
00040 pthread_mutexattr_destroy(&_attr); \
00041 } while(0)
00042 #else
00043
00044 #define TDS_MUTEX_DECLARE(name) int name
00045 #define TDS_MUTEX_LOCK(a)
00046 #define TDS_MUTEX_UNLOCK(a)
00047 #define TDS_MUTEX_T int
00048 #define TDS_MUTEX_DECLARE_RECURSIVE(name) int name
00049 #define TDS_MUTEX_INIT_RECURSIVE(mutex)
00050 #endif
00051
00052 #endif