MySQL++: beemutex.h Source File
beemutex.h
Go to the documentation of this file.
/***********************************************************************
Copyright © 2004 Beeyond Software Holding BV and © 2007-2008, 2018
by Educational Technology Resources, Inc. Others may also hold
copyrights on code in this file. See the CREDITS.txt file in the
top directory of the distribution for details.
This file is part of MySQL++.
MySQL++ is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
MySQL++ is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public
License along with MySQL++; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
USA
***********************************************************************/
#if !defined(MYSQLPP_BEEMUTEX_H)
#define MYSQLPP_BEEMUTEX_H
#include "exceptions.h"
namespace mysqlpp {
class MYSQLPP_EXPORT BeecryptMutex
{
public:
BeecryptMutex() MAY_THROW(MutexFailed);
~BeecryptMutex();
void lock() MAY_THROW(MutexFailed);
bool trylock() MAY_THROW(MutexFailed);
void unlock() MAY_THROW(MutexFailed);
private:
void* pmutex_;
};
class ScopedLock
{
public:
explicit ScopedLock(BeecryptMutex& mutex) :
mutex_(mutex)
{
mutex.lock();
}
#if __cplusplus >= 201103L
// Disallow copies and assignments
ScopedLock(const ScopedLock&) = delete;
const ScopedLock& operator =(const ScopedLock&) = delete;
#endif
~ScopedLock() { mutex_.unlock(); }
private:
#if __cplusplus < 201103L
// Pre-C++11 alternatives to disallow copies and assignments.
ScopedLock(const ScopedLock&);
ScopedLock& operator =(const ScopedLock&);
#endif
BeecryptMutex& mutex_;
};
} // end namespace mysqlpp
#endif // !defined(MYSQLPP_BEEMUTEX_H)
mysqlpp::BeecryptMutex
Wrapper around platform-specific mutexes.
Definition: beemutex.h:60
mysqlpp::BeecryptMutex::unlock
void unlock() MAY_THROW(MutexFailed)
Release the mutex.
Definition: beemutex.cpp:167
mysqlpp::BeecryptMutex::lock
void lock() MAY_THROW(MutexFailed)
Acquire the mutex, blocking if it can't be acquired immediately.
Definition: beemutex.cpp:110
mysqlpp::MutexFailed
Exception thrown when a BeecryptMutex object fails.
Definition: exceptions.h:390
mysqlpp::ScopedLock
Wrapper around BeecryptMutex to add scope-bound locking and unlocking.
Definition: beemutex.h:98
mysqlpp::ScopedLock::ScopedLock
ScopedLock(BeecryptMutex &mutex)
Lock the mutex.
Definition: beemutex.h:101
mysqlpp::ScopedLock::~ScopedLock
~ScopedLock()
Unlock the mutex.
Definition: beemutex.h:114
exceptions.h
Declares the MySQL++-specific exception classes.