ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

mutex.cpp

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #include "common/debug.h"
00024 #include "common/mutex.h"
00025 #include "common/system.h"
00026 
00027 namespace Common {
00028 
00029 Mutex::Mutex() {
00030     assert(g_system);
00031     _mutex = g_system->createMutex();
00032 }
00033 
00034 Mutex::~Mutex() {
00035     g_system->deleteMutex(_mutex);
00036 }
00037 
00038 void Mutex::lock() {
00039     g_system->lockMutex(_mutex);
00040 }
00041 
00042 void Mutex::unlock() {
00043     g_system->unlockMutex(_mutex);
00044 }
00045 
00046 
00047 #pragma mark -
00048 
00049 
00050 StackLock::StackLock(MutexRef mutex, const char *mutexName)
00051     : _mutex(mutex), _mutexName(mutexName) {
00052     lock();
00053 }
00054 
00055 StackLock::StackLock(const Mutex &mutex, const char *mutexName)
00056     : _mutex(mutex._mutex), _mutexName(mutexName) {
00057     lock();
00058 }
00059 
00060 StackLock::~StackLock() {
00061     unlock();
00062 }
00063 
00064 void StackLock::lock() {
00065     if (_mutexName != nullptr)
00066         debug(6, "Locking mutex %s", _mutexName);
00067 
00068     g_system->lockMutex(_mutex);
00069 }
00070 
00071 void StackLock::unlock() {
00072     if (_mutexName != nullptr)
00073         debug(6, "Unlocking mutex %s", _mutexName);
00074 
00075     g_system->unlockMutex(_mutex);
00076 }
00077 
00078 } // End of namespace Common


Generated on Sat Mar 16 2019 05:01:47 for ResidualVM by doxygen 1.7.1
curved edge   curved edge