Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
threads.h
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file threads.h
1 /*
2  This file is part of libodbc++.
3 
4  Copyright (C) 1999-2000 Manush Dodunekov <manush@stendahls.net>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Library General Public
8  License as published by the Free Software Foundation; either
9  version 2 of the License, or (at your option) any later version.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Library General Public License for more details.
15 
16  You should have received a copy of the GNU Library General Public License
17  along with this library; see the file COPYING. If not, write to
18  the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19  Boston, MA 02111-1307, USA.
20 */
21 
22 #ifndef __ODBCXX_THREADS_H
23 #define __ODBCXX_THREADS_H
24 
25 #include <RDBC/odbc++/setup.h>
26 
27 #if defined(ODBCXX_ENABLE_THREADS)
28 
29 #if !defined(WIN32)
30 # include <pthread.h>
31 #endif
32 
33 namespace odbc {
34 
35  class ODBCXX_EXPORT Mutex {
36  private:
37 #if !defined(WIN32)
38  pthread_mutex_t mutex_;
39 #else
40  CRITICAL_SECTION mutex_;
41 #endif
42 
43  Mutex(const Mutex&);
44  Mutex& operator=(const Mutex&);
45 
46  public:
47  explicit Mutex();
48  ~Mutex();
49 
50  void lock();
51  void unlock();
52  };
53 
54  class ODBCXX_EXPORT Locker {
55  private:
56  Mutex& m_;
57  public:
58  Locker(Mutex& m)
59  :m_(m) {
60  m_.lock();
61  }
62 
63  ~Locker() {
64  m_.unlock();
65  }
66  };
67 
68 }; //namespace odbc
69 
70 // macro used all over the place
71 #define ODBCXX_LOCKER(mut) odbc::Locker _locker(mut)
72 
73 #else // !ODBCXX_ENABLE_THREADS
74 
75 #define ODBCXX_LOCKER(mut) ((void)0)
76 
77 #endif
78 
79 #endif // __ODBCXX_THREADS_H