2007-05-30 21:56:52 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
2005-01-10 22:04:04 +00:00
|
|
|
*
|
2021-12-26 17:47:58 +00:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
2014-02-18 01:34:18 +00:00
|
|
|
*
|
2005-01-10 22:04:04 +00:00
|
|
|
* This program 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 General Public License for more details.
|
2014-02-18 01:34:18 +00:00
|
|
|
*
|
2005-01-10 22:04:04 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
2021-12-26 17:47:58 +00:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2005-01-10 22:04:04 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef COMMON_MUTEX_H
|
|
|
|
#define COMMON_MUTEX_H
|
|
|
|
|
|
|
|
#include "common/scummsys.h"
|
2009-01-30 03:35:47 +00:00
|
|
|
#include "common/system.h"
|
2005-01-10 22:04:04 +00:00
|
|
|
|
|
|
|
namespace Common {
|
|
|
|
|
2020-07-08 21:30:36 +00:00
|
|
|
/**
|
|
|
|
* @defgroup common_mutex Mutex
|
|
|
|
* @ingroup common
|
|
|
|
*
|
|
|
|
* @brief API for managing the mutex.
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2005-01-15 22:41:23 +00:00
|
|
|
class Mutex;
|
|
|
|
|
2021-08-24 22:53:21 +00:00
|
|
|
class MutexInternal {
|
|
|
|
public:
|
|
|
|
virtual ~MutexInternal() {}
|
|
|
|
|
|
|
|
virtual bool lock() = 0;
|
|
|
|
virtual bool unlock() = 0;
|
|
|
|
};
|
|
|
|
|
2005-01-10 22:04:04 +00:00
|
|
|
/**
|
|
|
|
* Auxillary class to (un)lock a mutex on the stack.
|
|
|
|
*/
|
|
|
|
class StackLock {
|
2021-08-24 22:53:21 +00:00
|
|
|
MutexInternal *_mutex;
|
2005-01-10 22:04:04 +00:00
|
|
|
const char *_mutexName;
|
|
|
|
|
2021-08-24 22:53:21 +00:00
|
|
|
bool lock();
|
|
|
|
bool unlock();
|
2005-01-10 22:04:04 +00:00
|
|
|
public:
|
2021-08-24 22:53:21 +00:00
|
|
|
explicit StackLock(MutexInternal *mutex, const char *mutexName = nullptr);
|
2018-04-05 18:25:28 +00:00
|
|
|
explicit StackLock(const Mutex &mutex, const char *mutexName = nullptr);
|
2005-01-10 22:04:04 +00:00
|
|
|
~StackLock();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2005-01-15 22:41:23 +00:00
|
|
|
/**
|
|
|
|
* Wrapper class around the OSystem mutex functions.
|
|
|
|
*/
|
|
|
|
class Mutex {
|
|
|
|
friend class StackLock;
|
|
|
|
|
2021-08-24 22:53:21 +00:00
|
|
|
MutexInternal *_mutex;
|
2005-01-15 22:41:23 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
Mutex();
|
|
|
|
~Mutex();
|
|
|
|
|
2021-08-24 22:53:21 +00:00
|
|
|
bool lock();
|
|
|
|
bool unlock();
|
2005-01-15 22:41:23 +00:00
|
|
|
};
|
|
|
|
|
2020-07-08 21:30:36 +00:00
|
|
|
/** @} */
|
2005-01-15 22:41:23 +00:00
|
|
|
|
2005-01-10 22:04:04 +00:00
|
|
|
} // End of namespace Common
|
|
|
|
|
|
|
|
#endif
|