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