FreeTDS API
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
tdsthread.h
1 /* FreeTDS - Library of routines accessing Sybase and Microsoft databases
2  *
3  * Copyright (C) 2005 Liam Widdowson
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20 
21 #ifndef TDSTHREAD_H
22 #define TDSTHREAD_H 1
23 
24 /* $Id: tdsthread.h,v 1.3 2005/07/06 12:35:37 freddy77 Exp $ */
25 
26 #if defined(_THREAD_SAFE) && defined(TDS_HAVE_PTHREAD_MUTEX)
27 
28 #include <pthread.h>
29 
30 #define TDS_MUTEX_DECLARE(name) pthread_mutex_t name = PTHREAD_MUTEX_INITIALIZER
31 #define TDS_MUTEX_LOCK(a) pthread_mutex_lock(a)
32 #define TDS_MUTEX_UNLOCK(a) pthread_mutex_unlock(a)
33 #define TDS_MUTEX_T pthread_mutex_t
34 #define TDS_MUTEX_DECLARE_RECURSIVE(name) pthread_mutex_t name = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
35 #define TDS_MUTEX_INIT_RECURSIVE(mutex) do { \
36  pthread_mutexattr_t _attr; \
37  pthread_mutexattr_init(&_attr); \
38  pthread_mutexattr_settype(&_attr, PTHREAD_MUTEX_RECURSIVE); \
39  pthread_mutex_init(mutex, &_attr); \
40  pthread_mutexattr_destroy(&_attr); \
41  } while(0)
42 #else
43 
44 #define TDS_MUTEX_DECLARE(name) int name
45 #define TDS_MUTEX_LOCK(a)
46 #define TDS_MUTEX_UNLOCK(a)
47 #define TDS_MUTEX_T int
48 #define TDS_MUTEX_DECLARE_RECURSIVE(name) int name
49 #define TDS_MUTEX_INIT_RECURSIVE(mutex)
50 #endif
51 
52 #endif