MySQL++  3.3.0
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 
107 #if __cplusplus >= 201103L
108  // Disallow copies and assignments
109  ScopedLock(const ScopedLock&) = delete;
110  const ScopedLock& operator =(const ScopedLock&) = delete;
111 #endif
112 
114  ~ScopedLock() { mutex_.unlock(); }
115 
116 private:
117 #if __cplusplus < 201103L
118  // Pre-C++11 alternatives to disallow copies and assignments.
119  ScopedLock(const ScopedLock&);
120  ScopedLock& operator =(const ScopedLock&);
121 #endif
122 
123  BeecryptMutex& mutex_;
124 };
125 
126 } // end namespace mysqlpp
127 
128 #endif // !defined(MYSQLPP_BEEMUTEX_H)
129 
Wrapper around platform-specific mutexes.
Definition: beemutex.h:60
void unlock() MAY_THROW(MutexFailed)
Release the mutex.
Definition: beemutex.cpp:167
void lock() MAY_THROW(MutexFailed)
Acquire the mutex, blocking if it can't be acquired immediately.
Definition: beemutex.cpp:110
Exception thrown when a BeecryptMutex object fails.
Definition: exceptions.h:390
Wrapper around BeecryptMutex to add scope-bound locking and unlocking.
Definition: beemutex.h:98
ScopedLock(BeecryptMutex &mutex)
Lock the mutex.
Definition: beemutex.h:101
~ScopedLock()
Unlock the mutex.
Definition: beemutex.h:114
Declares the MySQL++-specific exception classes.