Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members  

odbc++/threads.h

00001 /* 
00002    This file is part of libodbc++.
00003    
00004    Copyright (C) 1999-2000 Manush Dodunekov <manush@stendahls.net>
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 License
00017    along with this library; see the file COPYING.  If not, write to
00018    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00019    Boston, MA 02111-1307, USA.
00020 */
00021 
00022 #ifndef __ODBCXX_THREADS_H
00023 #define __ODBCXX_THREADS_H
00024 
00025 #include <odbc++/setup.h>
00026 
00027 #if defined(ODBCXX_ENABLE_THREADS)
00028 
00029 #if !defined(WIN32)
00030 # include <pthread.h>
00031 #endif
00032 
00033 namespace odbc {
00034   
00035   class ODBCXX_EXPORT Mutex {
00036   private:
00037 #if !defined(WIN32)
00038     pthread_mutex_t mutex_;
00039 #else
00040     CRITICAL_SECTION mutex_;
00041 #endif
00042 
00043     Mutex(const Mutex&);
00044     Mutex& operator=(const Mutex&);
00045 
00046   public:
00047     explicit Mutex();
00048     ~Mutex();
00049 
00050     void lock();
00051     void unlock();
00052   };
00053 
00054   class ODBCXX_EXPORT Locker {
00055   private:
00056     Mutex& m_;
00057   public:
00058     Locker(Mutex& m)
00059       :m_(m) {
00060       m_.lock();
00061     }
00062     
00063     ~Locker() {
00064       m_.unlock();
00065     }
00066   };
00067 
00068 }; //namespace odbc
00069 
00070 // macro used all over the place
00071 #define ODBCXX_LOCKER(mut) odbc::Locker _locker(mut)
00072 
00073 #else // !ODBCXX_ENABLE_THREADS
00074 
00075 #define ODBCXX_LOCKER(mut) ((void)0)
00076 
00077 #endif
00078 
00079 #endif // __ODBCXX_THREADS_H

Go back to the freeodbc++ homepage