29 #if defined(_THREAD_SAFE) && defined(TDS_HAVE_PTHREAD_MUTEX)
33 #include <freetds/pushvis.h>
36 #define TDS_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
38 static inline void tds_mutex_lock(
tds_mutex *mtx)
40 pthread_mutex_lock(mtx);
43 static inline int tds_mutex_trylock(
tds_mutex *mtx)
45 return pthread_mutex_trylock(mtx);
48 static inline void tds_mutex_unlock(
tds_mutex *mtx)
50 pthread_mutex_unlock(mtx);
53 static inline int tds_mutex_init(
tds_mutex *mtx)
55 return pthread_mutex_init(mtx, NULL);
58 static inline void tds_mutex_free(
tds_mutex *mtx)
60 pthread_mutex_destroy(mtx);
68 return pthread_cond_destroy(cond);
72 return pthread_cond_signal(cond);
74 static inline int tds_cond_wait(
tds_condition *cond, pthread_mutex_t *mtx)
76 return pthread_cond_wait(cond, mtx);
78 int tds_cond_timedwait(
tds_condition *cond, pthread_mutex_t *mtx,
int timeout_sec);
80 #define TDS_HAVE_MUTEX 1
83 typedef void *(*tds_thread_proc)(
void *arg);
84 #define TDS_THREAD_PROC_DECLARE(name, arg) \
87 static inline int tds_thread_create(
tds_thread *ret, tds_thread_proc proc,
void *arg)
89 return pthread_create(ret, NULL, proc, arg);
92 static inline int tds_thread_join(
tds_thread th,
void **ret)
94 return pthread_join(th, ret);
97 #include <freetds/popvis.h>
106 CRITICAL_SECTION crit;
109 #define TDS_MUTEX_INITIALIZER { NULL, 0 }
119 void tds_win_mutex_lock(
tds_mutex *mutex);
121 static inline void tds_mutex_lock(
tds_mutex *mtx)
124 EnterCriticalSection(&(mtx)->crit);
126 tds_win_mutex_lock(mtx);
131 static inline void tds_mutex_unlock(
tds_mutex *mtx)
133 LeaveCriticalSection(&(mtx)->crit);
136 static inline void tds_mutex_free(
tds_mutex *mtx)
139 DeleteCriticalSection(&(mtx)->crit);
144 #define TDS_HAVE_MUTEX 1
147 typedef void *TDS_CONDITION_VARIABLE;
150 TDS_CONDITION_VARIABLE cv;
159 return tds_cond_timedwait(cond, mtx, -1);
163 typedef void *(WINAPI *tds_thread_proc)(
void *arg);
164 #define TDS_THREAD_PROC_DECLARE(name, arg) \
165 void *WINAPI name(void *arg)
167 static inline int tds_thread_create(tds_thread *ret, tds_thread_proc proc,
void *arg)
169 *ret = CreateThread(NULL, 0, (DWORD (WINAPI *)(
void*)) proc, arg, 0, NULL);
170 return *ret != NULL ? 0 : 11 ;
173 static inline int tds_thread_join(tds_thread th,
void **ret)
175 if (WaitForSingleObject(th, INFINITE) == WAIT_OBJECT_0) {
177 if (ret && GetExitCodeThread(th, &r))
178 *ret = (
void*) (((
char*)0) + r);
193 #define TDS_MUTEX_INITIALIZER {}
195 static inline void tds_mutex_lock(
tds_mutex *mtx)
199 static inline int tds_mutex_trylock(
tds_mutex *mtx)
204 static inline void tds_mutex_unlock(
tds_mutex *mtx)
208 static inline int tds_mutex_init(
tds_mutex *mtx)
213 static inline void tds_mutex_free(
tds_mutex *mtx)
228 #define tds_cond_signal(cond) \
229 FreeTDS_Condition_not_compiled
231 #define tds_cond_wait(cond, mtx) \
232 FreeTDS_Condition_not_compiled
234 #define tds_cond_timedwait(cond, mtx, timeout_sec) \
235 FreeTDS_Condition_not_compiled
240 typedef void *(*tds_thread_proc)(
void *arg);
241 #define TDS_THREAD_PROC_DECLARE(name, arg) \
242 void *name(void *arg)
244 #define tds_thread_create(ret, proc, arg) \
245 FreeTDS_Thread_not_compiled
247 #define tds_thread_join(th, ret) \
248 FreeTDS_Thread_not_compiled
Definition: ptw32_MCS_lock.c:97