beemutex.h
Go to the documentation of this file.
1 
19 /***********************************************************************
20  Copyright (c) 2004 Beeyond Software Holding BV and (c) 2007-2008
21  by Educational Technology Resources, Inc. Others may also hold
22  copyrights on code in this file. See the CREDITS.txt file in the
23  top directory of the distribution for details.
24 
25  This file is part of MySQL++.
26 
27  MySQL++ is free software; you can redistribute it and/or modify it
28  under the terms of the GNU Lesser General Public License as published
29  by the Free Software Foundation; either version 2.1 of the License, or
30  (at your option) any later version.
31 
32  MySQL++ is distributed in the hope that it will be useful, but WITHOUT
33  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
34  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
35  License for more details.
36 
37  You should have received a copy of the GNU Lesser General Public
38  License along with MySQL++; if not, write to the Free Software
39  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
40  USA
41 ***********************************************************************/
42 
43 #if !defined(MYSQLPP_BEEMUTEX_H)
44 #define MYSQLPP_BEEMUTEX_H
45 
46 #include "exceptions.h"
47 
48 namespace mysqlpp {
49 
57 class MYSQLPP_EXPORT BeecryptMutex
58 {
59 public:
64  BeecryptMutex() throw (MutexFailed);
65 
69  ~BeecryptMutex();
70 
73  void lock() throw (MutexFailed);
74 
77  bool trylock() throw (MutexFailed);
78 
80  void unlock() throw (MutexFailed);
81 
82 private:
83  void* pmutex_;
84 };
85 
86 
94 
96 {
97 public:
99  explicit ScopedLock(BeecryptMutex& mutex) :
100  mutex_(mutex)
101  {
102  mutex.lock();
103  }
104 
106  ~ScopedLock() { mutex_.unlock(); }
107 
108 private:
109  ScopedLock(const ScopedLock&); // can't copy
110  ScopedLock& operator =(const ScopedLock&); // can't assign
111 
112  BeecryptMutex& mutex_;
113 };
114 
115 } // end namespace mysqlpp
116 
117 #endif // !defined(MYSQLPP_BEEMUTEX_H)
118 
ScopedLock(BeecryptMutex &mutex)
Lock the mutex.
Definition: beemutex.h:99
Exception thrown when a BeecryptMutex object fails.
Definition: exceptions.h:389
Wrapper around BeecryptMutex to add scope-bound locking and unlocking.
Definition: beemutex.h:95
~ScopedLock()
Unlock the mutex.
Definition: beemutex.h:106
void lock()
Acquire the mutex, blocking if it can't be acquired immediately.
Definition: beemutex.cpp:106
Declares the MySQL++-specific exception classes.
Wrapper around platform-specific mutexes.
Definition: beemutex.h:57
void unlock()
Release the mutex.
Definition: beemutex.cpp:163