- Main Page
- Related Pages
- Modules
- Classes
- Files

- File List
- File Members

# /home/jklowden/releases/freetds-0.91/include/tdsthread.h

    00001 /* FreeTDS - Library of routines accessing Sybase and Microsoft databases
    00002  *
    00003  * Copyright (C) 2005 Liam Widdowson
    00004  * Copyright (C) 2010 Frediano Ziglio
    00005  *
    00006  * This library is free software; you can redistribute it and/or
    00007  * modify it under the terms of the GNU Library General Public
    00008  * License as published by the Free Software Foundation; either
    00009  * version 2 of the License, or (at your option) any later version.
    00010  *
    00011  * This library is distributed in the hope that it will be useful,
    00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00014  * Library General Public License for more details.
    00015  *
    00016  * You should have received a copy of the GNU Library General Public
    00017  * License along with this library; if not, write to the
    00018  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00019  * Boston, MA 02111-1307, USA.
    00020  */
    00021
    00022 #ifndef TDSTHREAD_H
    00023 #define TDSTHREAD_H 1
    00024
    00025 /* $Id: tdsthread.h,v 1.9 2010/09/16 11:12:08 freddy77 Exp $ */
    00026
    00027 #undef TDS_HAVE_MUTEX
    00028
    00029 #if defined(_THREAD_SAFE) && defined(TDS_HAVE_PTHREAD_MUTEX)
    00030
    00031 #include <pthread.h>
    00032
    00033 #define TDS_MUTEX_DEFINE(name) pthread_mutex_t name = PTHREAD_MUTEX_INITIALIZER
    00034 #define TDS_MUTEX_LOCK(mtx) pthread_mutex_lock(mtx)
    00035 #define TDS_MUTEX_UNLOCK(mtx) pthread_mutex_unlock(mtx)
    00036 #define TDS_MUTEX_DECLARE(name) pthread_mutex_t name
    00037 #define TDS_MUTEX_INIT(mtx) pthread_mutex_init(mtx, NULL)
    00038 #define TDS_MUTEX_FREE(mtx) pthread_mutex_destroy(mtx)
    00039
    00040 #define TDS_HAVE_MUTEX 1
    00041
    00042 #elif defined(_WIN32)
    00043
    00044 struct ptw32_mcs_node_t_;
    00045
    00046 typedef struct tds_win_mutex_t_ {
    00047         struct ptw32_mcs_node_t_ *lock;
    00048         LONG done;
    00049         CRITICAL_SECTION crit;
    00050 } tds_win_mutex_t;
    00051
    00052 void tds_win_mutex_lock(tds_win_mutex_t *mutex);
    00053 static inline int tds_win_mutex_init(tds_win_mutex_t *mtx)
    00054 {
    00055         mtx->lock = NULL;
    00056         mtx->done = 0;
    00057         return 0;
    00058 }
    00059 /* void tds_win_mutex_unlock(tds_win_mutex_t *mutex); */
    00060
    00061 #define TDS_MUTEX_DEFINE(name) tds_win_mutex_t name = { NULL, 0 }
    00062 #define TDS_MUTEX_LOCK(mtx) \
    00063         do { if ((mtx)->done) EnterCriticalSection(&(mtx)->crit); else tds_win_mutex_lock(mtx); } while(0)
    00064 #define TDS_MUTEX_UNLOCK(mtx) LeaveCriticalSection(&(mtx)->crit)
    00065 #define TDS_MUTEX_DECLARE(name) tds_win_mutex_t name
    00066 #define TDS_MUTEX_INIT(mtx) tds_win_mutex_init(mtx)
    00067 #define TDS_MUTEX_FREE(mtx) do { if ((mtx)->done) { DeleteCriticalSection(&(mtx)->crit); (mtx)->done = 0; } } while(0)
    00068
    00069 #define TDS_HAVE_MUTEX 1
    00070
    00071 #else
    00072
    00073 #define TDS_MUTEX_DEFINE(name) int name
    00074 #define TDS_MUTEX_LOCK(mtx)
    00075 #define TDS_MUTEX_UNLOCK(mtx)
    00076 #define TDS_MUTEX_DECLARE(name) int name
    00077 #define TDS_MUTEX_INIT(mtx)
    00078 #define TDS_MUTEX_FREE(mtx)
    00079
    00080 #endif
    00081
    00082 #endif

All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines