[Scummvm-git-logs] scummvm master -> 502248927716cc0b11f31da706ca1d0a669fe48f
sev-
sev at scummvm.org
Fri Nov 12 19:19:48 UTC 2021
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
5022489277 BACKENDS: Refactor the API for creating Mutexes
Commit: 502248927716cc0b11f31da706ca1d0a669fe48f
https://github.com/scummvm/scummvm/commit/502248927716cc0b11f31da706ca1d0a669fe48f
Author: Cameron Cawley (ccawley2011 at gmail.com)
Date: 2021-11-12T20:19:45+01:00
Commit Message:
BACKENDS: Refactor the API for creating Mutexes
Changed paths:
A backends/mutex/3ds/3ds-mutex.cpp
A backends/mutex/3ds/3ds-mutex.h
A backends/mutex/wii/wii-mutex.cpp
A backends/mutex/wii/wii-mutex.h
R backends/mutex/mutex.h
backends/modular-backend.cpp
backends/modular-backend.h
backends/module.mk
backends/mutex/null/null-mutex.h
backends/mutex/pthread/pthread-mutex.cpp
backends/mutex/pthread/pthread-mutex.h
backends/mutex/sdl/sdl-mutex.cpp
backends/mutex/sdl/sdl-mutex.h
backends/platform/3ds/osystem.cpp
backends/platform/3ds/osystem.h
backends/platform/android/android.cpp
backends/platform/android/android.h
backends/platform/android3d/android.cpp
backends/platform/android3d/android.h
backends/platform/dc/dc.h
backends/platform/dc/dcmain.cpp
backends/platform/ds/osystem_ds.cpp
backends/platform/ds/osystem_ds.h
backends/platform/ios7/ios7_osys_main.cpp
backends/platform/ios7/ios7_osys_main.h
backends/platform/iphone/osys_main.cpp
backends/platform/iphone/osys_main.h
backends/platform/n64/osys_n64.h
backends/platform/n64/osys_n64_base.cpp
backends/platform/null/null.cpp
backends/platform/psp/osys_psp.cpp
backends/platform/psp/osys_psp.h
backends/platform/psp/thread.h
backends/platform/sdl/sdl.cpp
backends/platform/sdl/sdl.h
backends/platform/wii/osystem.cpp
backends/platform/wii/osystem.h
backends/timer/sdl/sdl-timer.cpp
common/mutex.cpp
common/mutex.h
common/system.h
diff --git a/backends/modular-backend.cpp b/backends/modular-backend.cpp
index 956c310539..63ecfeb93d 100644
--- a/backends/modular-backend.cpp
+++ b/backends/modular-backend.cpp
@@ -25,7 +25,6 @@
#include "backends/audiocd/audiocd.h"
#include "backends/graphics/graphics.h"
#include "backends/mixer/mixer.h"
-#include "backends/mutex/mutex.h"
#include "gui/EventRecorder.h"
#include "common/timer.h"
@@ -316,37 +315,3 @@ Audio::Mixer *ModularMixerBackend::getMixer() {
return getMixerManager()->getMixer();
}
-
-ModularMutexBackend::ModularMutexBackend()
- :
- _mutexManager(0) {
-
-}
-
-ModularMutexBackend::~ModularMutexBackend() {
- // _timerManager needs to be deleted before _mutexManager to avoid a crash.
- delete _timerManager;
- _timerManager = 0;
- delete _mutexManager;
- _mutexManager = 0;
-}
-
-OSystem::MutexRef ModularMutexBackend::createMutex() {
- assert(_mutexManager);
- return _mutexManager->createMutex();
-}
-
-void ModularMutexBackend::lockMutex(MutexRef mutex) {
- assert(_mutexManager);
- _mutexManager->lockMutex(mutex);
-}
-
-void ModularMutexBackend::unlockMutex(MutexRef mutex) {
- assert(_mutexManager);
- _mutexManager->unlockMutex(mutex);
-}
-
-void ModularMutexBackend::deleteMutex(MutexRef mutex) {
- assert(_mutexManager);
- _mutexManager->deleteMutex(mutex);
-}
diff --git a/backends/modular-backend.h b/backends/modular-backend.h
index 2318bfc0eb..6ebdfad25c 100644
--- a/backends/modular-backend.h
+++ b/backends/modular-backend.h
@@ -27,7 +27,6 @@
class GraphicsManager;
class MixerManager;
-class MutexManager;
/**
* Base classes for modular backends.
@@ -38,6 +37,7 @@ class MutexManager;
* A backend derivated from these classes, will need to implement
* these functions on its own:
* OSystem::pollEvent()
+ * OSystem::createMutex()
* OSystem::getMillis()
* OSystem::delayMillis()
* OSystem::getTimeAndDate()
@@ -165,28 +165,4 @@ protected:
//@}
};
-class ModularMutexBackend : virtual public BaseBackend {
-public:
- ModularMutexBackend();
- virtual ~ModularMutexBackend();
-
- /** @name Mutex handling */
- //@{
-
- virtual MutexRef createMutex() override final;
- virtual void lockMutex(MutexRef mutex) override final;
- virtual void unlockMutex(MutexRef mutex) override final;
- virtual void deleteMutex(MutexRef mutex) override final;
-
- //@}
-
-protected:
- /** @name Managers variables */
- //@{
-
- MutexManager *_mutexManager;
-
- //@}
-};
-
#endif
diff --git a/backends/module.mk b/backends/module.mk
index 49f9a30cc5..c84334cfb9 100644
--- a/backends/module.mk
+++ b/backends/module.mk
@@ -224,6 +224,11 @@ endif
endif
+ifeq ($(BACKEND),3ds)
+MODULE_OBJS += \
+ mutex/3ds/3ds-mutex.o
+endif
+
ifeq ($(BACKEND),android)
MODULE_OBJS += \
mutex/pthread/pthread-mutex.o
@@ -371,6 +376,7 @@ ifeq ($(BACKEND),wii)
MODULE_OBJS += \
fs/wii/wii-fs.o \
fs/wii/wii-fs-factory.o \
+ mutex/wii/wii-mutex.o \
plugins/wii/wii-provider.o
endif
diff --git a/backends/mutex/3ds/3ds-mutex.cpp b/backends/mutex/3ds/3ds-mutex.cpp
new file mode 100644
index 0000000000..9ad3244a8f
--- /dev/null
+++ b/backends/mutex/3ds/3ds-mutex.cpp
@@ -0,0 +1,54 @@
+/* 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.
+ *
+ * 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 2
+ * of the License, or (at your option) any later version.
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#define FORBIDDEN_SYMBOL_EXCEPTION_printf
+#define FORBIDDEN_SYMBOL_EXCEPTION_time_h
+#define FORBIDDEN_SYMBOL_EXCEPTION_unistd_h
+
+#include "common/scummsys.h"
+
+#if defined(__3DS__)
+
+#include "backends/mutex/3ds/3ds-mutex.h"
+
+#include <3ds.h>
+
+/**
+ * 3DS mutex manager
+ */
+class _3DSMutexInternal final : public Common::MutexInternal {
+public:
+ _3DSMutexInternal() { RecursiveLock_Init(&_mutex); }
+ virtual ~_3DSMutexInternal() override {}
+
+ virtual bool lock() override { RecursiveLock_Lock(&_mutex); return true; }
+ virtual bool unlock() override { RecursiveLock_Unlock(&_mutex); return true; }
+
+private:
+ RecursiveLock _mutex;
+};
+
+Common::MutexInternal *create3DSMutexInternal() {
+ return new _3DSMutexInternal();
+}
+
+#endif
diff --git a/backends/mutex/mutex.h b/backends/mutex/3ds/3ds-mutex.h
similarity index 65%
rename from backends/mutex/mutex.h
rename to backends/mutex/3ds/3ds-mutex.h
index 26a6d47e09..db62a303c5 100644
--- a/backends/mutex/mutex.h
+++ b/backends/mutex/3ds/3ds-mutex.h
@@ -20,24 +20,11 @@
*
*/
-#ifndef BACKENDS_MUTEX_ABSTRACT_H
-#define BACKENDS_MUTEX_ABSTRACT_H
+#ifndef BACKENDS_MUTEX_3DS_H
+#define BACKENDS_MUTEX_3DS_H
-#include "common/system.h"
-#include "common/noncopyable.h"
+#include "common/mutex.h"
-/**
- * Abstract class for mutex manager. Subclasses
- * implement the real functionality.
- */
-class MutexManager : Common::NonCopyable {
-public:
- virtual ~MutexManager() {}
-
- virtual OSystem::MutexRef createMutex() = 0;
- virtual void lockMutex(OSystem::MutexRef mutex) = 0;
- virtual void unlockMutex(OSystem::MutexRef mutex) = 0;
- virtual void deleteMutex(OSystem::MutexRef mutex) = 0;
-};
+Common::MutexInternal *create3DSMutexInternal();
#endif
diff --git a/backends/mutex/null/null-mutex.h b/backends/mutex/null/null-mutex.h
index 218b1adf02..7417d96119 100644
--- a/backends/mutex/null/null-mutex.h
+++ b/backends/mutex/null/null-mutex.h
@@ -23,17 +23,17 @@
#ifndef BACKENDS_MUTEX_NULL_H
#define BACKENDS_MUTEX_NULL_H
-#include "backends/mutex/mutex.h"
+#include "common/mutex.h"
/**
* Null mutex manager
*/
-class NullMutexManager : public MutexManager {
+class NullMutexInternal final : public Common::MutexInternal {
public:
- virtual OSystem::MutexRef createMutex() { return OSystem::MutexRef(); }
- virtual void lockMutex(OSystem::MutexRef mutex) {}
- virtual void unlockMutex(OSystem::MutexRef mutex) {}
- virtual void deleteMutex(OSystem::MutexRef mutex) {}
+ NullMutexInternal() {}
+ virtual ~NullMutexInternal() {}
+ virtual bool lock() { return true; }
+ virtual bool unlock() { return true; }
};
#endif
diff --git a/backends/mutex/pthread/pthread-mutex.cpp b/backends/mutex/pthread/pthread-mutex.cpp
index e82d7db2b7..68d874500b 100644
--- a/backends/mutex/pthread/pthread-mutex.cpp
+++ b/backends/mutex/pthread/pthread-mutex.cpp
@@ -30,41 +30,58 @@
#include <pthread.h>
+/**
+ * pthreads mutex implementation
+ */
+class PthreadMutexInternal final : public Common::MutexInternal {
+public:
+ PthreadMutexInternal();
+ virtual ~PthreadMutexInternal() override;
+
+ virtual bool lock() override;
+ virtual bool unlock() override;
+
+private:
+ pthread_mutex_t _mutex;
+};
-OSystem::MutexRef PthreadMutexManager::createMutex() {
+
+PthreadMutexInternal::PthreadMutexInternal() {
pthread_mutexattr_t attr;
pthread_mutexattr_init(&attr);
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
- pthread_mutex_t *mutex = new pthread_mutex_t;
-
- if (pthread_mutex_init(mutex, &attr) != 0) {
+ if (pthread_mutex_init(&_mutex, &attr) != 0) {
warning("pthread_mutex_init() failed");
- delete mutex;
- return NULL;
}
+}
- return (OSystem::MutexRef)mutex;
+PthreadMutexInternal::~PthreadMutexInternal() {
+ if (pthread_mutex_destroy(&_mutex) != 0)
+ warning("pthread_mutex_destroy() failed");
}
-void PthreadMutexManager::lockMutex(OSystem::MutexRef mutex) {
- if (pthread_mutex_lock((pthread_mutex_t *)mutex) != 0)
+bool PthreadMutexInternal::lock() {
+ if (pthread_mutex_lock(&_mutex) != 0) {
warning("pthread_mutex_lock() failed");
+ return false;
+ } else {
+ return true;
+ }
}
-void PthreadMutexManager::unlockMutex(OSystem::MutexRef mutex) {
- if (pthread_mutex_unlock((pthread_mutex_t *)mutex) != 0)
+bool PthreadMutexInternal::unlock() {
+ if (pthread_mutex_unlock(&_mutex) != 0) {
warning("pthread_mutex_unlock() failed");
+ return false;
+ } else {
+ return true;
+ }
}
-void PthreadMutexManager::deleteMutex(OSystem::MutexRef mutex) {
- pthread_mutex_t *m = (pthread_mutex_t *)mutex;
-
- if (pthread_mutex_destroy(m) != 0)
- warning("pthread_mutex_destroy() failed");
- else
- delete m;
+Common::MutexInternal *createPthreadMutexInternal() {
+ return new PthreadMutexInternal();
}
#endif
diff --git a/backends/mutex/pthread/pthread-mutex.h b/backends/mutex/pthread/pthread-mutex.h
index fdb3d72fcf..0b87efe619 100644
--- a/backends/mutex/pthread/pthread-mutex.h
+++ b/backends/mutex/pthread/pthread-mutex.h
@@ -23,18 +23,8 @@
#ifndef BACKENDS_MUTEX_PTHREAD_H
#define BACKENDS_MUTEX_PTHREAD_H
-#include "backends/mutex/mutex.h"
-
-/**
- * pthreads mutex manager
- */
-class PthreadMutexManager : public MutexManager {
-public:
- virtual OSystem::MutexRef createMutex() override;
- virtual void lockMutex(OSystem::MutexRef mutex) override;
- virtual void unlockMutex(OSystem::MutexRef mutex) override;
- virtual void deleteMutex(OSystem::MutexRef mutex) override;
-};
+#include "common/mutex.h"
+Common::MutexInternal *createPthreadMutexInternal();
#endif
diff --git a/backends/mutex/sdl/sdl-mutex.cpp b/backends/mutex/sdl/sdl-mutex.cpp
index be10d30500..54b8b5d693 100644
--- a/backends/mutex/sdl/sdl-mutex.cpp
+++ b/backends/mutex/sdl/sdl-mutex.cpp
@@ -27,21 +27,23 @@
#include "backends/mutex/sdl/sdl-mutex.h"
#include "backends/platform/sdl/sdl-sys.h"
+/**
+ * SDL mutex manager
+ */
+class SdlMutexInternal final : public Common::MutexInternal {
+public:
+ SdlMutexInternal() { _mutex = SDL_CreateMutex(); }
+ virtual ~SdlMutexInternal() override { SDL_DestroyMutex(_mutex); }
-OSystem::MutexRef SdlMutexManager::createMutex() {
- return (OSystem::MutexRef) SDL_CreateMutex();
-}
+ virtual bool lock() override { return (SDL_mutexP(_mutex) == 0); }
+ virtual bool unlock() override { return (SDL_mutexV(_mutex) == 0); }
-void SdlMutexManager::lockMutex(OSystem::MutexRef mutex) {
- SDL_mutexP((SDL_mutex *)mutex);
-}
-
-void SdlMutexManager::unlockMutex(OSystem::MutexRef mutex) {
- SDL_mutexV((SDL_mutex *)mutex);
-}
+private:
+ SDL_mutex *_mutex;
+};
-void SdlMutexManager::deleteMutex(OSystem::MutexRef mutex) {
- SDL_DestroyMutex((SDL_mutex *)mutex);
+Common::MutexInternal *createSdlMutexInternal() {
+ return new SdlMutexInternal();
}
#endif
diff --git a/backends/mutex/sdl/sdl-mutex.h b/backends/mutex/sdl/sdl-mutex.h
index 6fcae05cee..0e06e9d899 100644
--- a/backends/mutex/sdl/sdl-mutex.h
+++ b/backends/mutex/sdl/sdl-mutex.h
@@ -23,18 +23,8 @@
#ifndef BACKENDS_MUTEX_SDL_H
#define BACKENDS_MUTEX_SDL_H
-#include "backends/mutex/mutex.h"
-
-/**
- * SDL mutex manager
- */
-class SdlMutexManager : public MutexManager {
-public:
- virtual OSystem::MutexRef createMutex();
- virtual void lockMutex(OSystem::MutexRef mutex);
- virtual void unlockMutex(OSystem::MutexRef mutex);
- virtual void deleteMutex(OSystem::MutexRef mutex);
-};
+#include "common/mutex.h"
+Common::MutexInternal *createSdlMutexInternal();
#endif
diff --git a/backends/mutex/wii/wii-mutex.cpp b/backends/mutex/wii/wii-mutex.cpp
new file mode 100644
index 0000000000..e94132f637
--- /dev/null
+++ b/backends/mutex/wii/wii-mutex.cpp
@@ -0,0 +1,90 @@
+/* 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.
+ *
+ * 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 2
+ * of the License, or (at your option) any later version.
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#define FORBIDDEN_SYMBOL_ALLOW_ALL
+
+#include "common/scummsys.h"
+
+#if defined(__WII__)
+
+#include "backends/mutex/wii/wii-mutex.h"
+
+#include <ogc/mutex.h>
+
+/**
+ * Wii mutex implementation
+ */
+class WiiMutexInternal final : public Common::MutexInternal {
+public:
+ WiiMutexInternal();
+ virtual ~WiiMutexInternal() override;
+
+ virtual bool lock() override;
+ virtual bool unlock() override;
+
+private:
+ mutex_t _mutex;
+};
+
+
+WiiMutexInternal::WiiMutexInternal() {
+ s32 res = LWP_MutexInit(&_mutex, true);
+
+ if (res) {
+ printf("ERROR creating mutex\n");
+ }
+}
+
+WiiMutexInternal::~WiiMutexInternal() {
+ s32 res = LWP_MutexDestroy(_mutex);
+
+ if (res)
+ printf("ERROR destroying mutex (%d)\n", res);
+}
+
+bool WiiMutexInternal::lock() {
+ s32 res = LWP_MutexLock(_mutex);
+
+ if (res) {
+ printf("ERROR locking mutex (%d)\n", res);
+ return false;
+ } else {
+ return true;
+ }
+}
+
+bool WiiMutexInternal::unlock() {
+ s32 res = LWP_MutexUnlock(_mutex);
+
+ if (res) {
+ printf("ERROR unlocking mutex (%d)\n", res);
+ return false;
+ } else {
+ return true;
+ }
+}
+
+Common::MutexInternal *createWiiMutexInternal() {
+ return new WiiMutexInternal();
+}
+
+#endif
diff --git a/backends/mutex/wii/wii-mutex.h b/backends/mutex/wii/wii-mutex.h
new file mode 100644
index 0000000000..620b70ec8f
--- /dev/null
+++ b/backends/mutex/wii/wii-mutex.h
@@ -0,0 +1,30 @@
+/* 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.
+ *
+ * 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 2
+ * of the License, or (at your option) any later version.
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef BACKENDS_MUTEX_WII_H
+#define BACKENDS_MUTEX_WII_H
+
+#include "common/mutex.h"
+
+Common::MutexInternal *createWiiMutexInternal();
+
+#endif
diff --git a/backends/platform/3ds/osystem.cpp b/backends/platform/3ds/osystem.cpp
index 8e40e53fef..67bd3c8a98 100644
--- a/backends/platform/3ds/osystem.cpp
+++ b/backends/platform/3ds/osystem.cpp
@@ -28,6 +28,7 @@
#include "osystem.h"
#include "backends/platform/3ds/config.h"
+#include "backends/mutex/3ds/3ds-mutex.h"
#include "backends/saves/default/default-saves.h"
#include "backends/timer/default/default-timer.h"
#include "backends/events/default/default-events.h"
@@ -198,19 +199,8 @@ void OSystem_3DS::getTimeAndDate(TimeDate& td, bool skipRecord) const {
td.tm_wday = t.tm_wday;
}
-OSystem::MutexRef OSystem_3DS::createMutex() {
- RecursiveLock *mutex = new RecursiveLock();
- RecursiveLock_Init(mutex);
- return (OSystem::MutexRef) mutex;
-}
-void OSystem_3DS::lockMutex(MutexRef mutex) {
- RecursiveLock_Lock((RecursiveLock*)mutex);
-}
-void OSystem_3DS::unlockMutex(MutexRef mutex) {
- RecursiveLock_Unlock((RecursiveLock*)mutex);
-}
-void OSystem_3DS::deleteMutex(MutexRef mutex) {
- delete (RecursiveLock*)mutex;
+Common::MutexInternal *OSystem_3DS::createMutex() {
+ return create3DSMutexInternal();
}
Common::String OSystem_3DS::getSystemLanguage() const {
diff --git a/backends/platform/3ds/osystem.h b/backends/platform/3ds/osystem.h
index e3c92f6e7a..327ada7a6b 100644
--- a/backends/platform/3ds/osystem.h
+++ b/backends/platform/3ds/osystem.h
@@ -25,7 +25,6 @@
#define FORBIDDEN_SYMBOL_EXCEPTION_time_h
-#include "backends/mutex/mutex.h"
#include "backends/base-backend.h"
#include "graphics/palette.h"
#include "base/main.h"
@@ -118,10 +117,7 @@ public:
virtual void delayMillis(uint msecs);
virtual void getTimeAndDate(TimeDate &td, bool skipRecord = false) const;
- virtual MutexRef createMutex();
- virtual void lockMutex(MutexRef mutex);
- virtual void unlockMutex(MutexRef mutex);
- virtual void deleteMutex(MutexRef mutex);
+ virtual Common::MutexInternal *createMutex();
virtual void logMessage(LogMessageType::Type type, const char *message);
diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp
index 499c418773..0d3e7c9f4a 100644
--- a/backends/platform/android/android.cpp
+++ b/backends/platform/android/android.cpp
@@ -425,7 +425,6 @@ void OSystem_Android::initBackend() {
// TODO remove the debug message eventually
LOGD("Setting DefaultSaveFileManager path to: %s", ConfMan.get("savepath").c_str());
- _mutexManager = new PthreadMutexManager();
_timerManager = new DefaultTimerManager();
_event_queue_lock = new Common::Mutex();
@@ -559,6 +558,10 @@ void OSystem_Android::delayMillis(uint msecs) {
usleep(msecs * 1000);
}
+Common::MutexInternal *OSystem_Android::createMutex() {
+ return createPthreadMutexInternal();
+}
+
void OSystem_Android::quit() {
ENTER();
diff --git a/backends/platform/android/android.h b/backends/platform/android/android.h
index a07f7b5507..825d35716c 100644
--- a/backends/platform/android/android.h
+++ b/backends/platform/android/android.h
@@ -57,7 +57,7 @@ extern const char *android_log_tag;
#define ENTER(fmt, args...) do { } while (false)
#endif
-class OSystem_Android : public ModularMutexBackend, public ModularGraphicsBackend, Common::EventSource {
+class OSystem_Android : public ModularGraphicsBackend, Common::EventSource {
private:
// passed from the dark side
int _audio_sample_rate;
@@ -129,6 +129,7 @@ public:
virtual uint32 getMillis(bool skipRecord = false) override;
virtual void delayMillis(uint msecs) override;
+ virtual Common::MutexInternal *createMutex() override;
virtual void quit() override;
diff --git a/backends/platform/android3d/android.cpp b/backends/platform/android3d/android.cpp
index fe5e230631..d8a270b2f4 100644
--- a/backends/platform/android3d/android.cpp
+++ b/backends/platform/android3d/android.cpp
@@ -362,7 +362,6 @@ void OSystem_Android::initBackend() {
// TODO remove the debug message eventually
LOGD("Setting DefaultSaveFileManager path to: %s", ConfMan.get("savepath").c_str());
- _mutexManager = new PthreadMutexManager();
_timerManager = new DefaultTimerManager();
_event_queue_lock = new Common::Mutex();
@@ -476,6 +475,10 @@ void OSystem_Android::delayMillis(uint msecs) {
usleep(msecs * 1000);
}
+Common::MutexInternal *OSystem_Android::createMutex() {
+ return createPthreadMutexInternal();
+}
+
void OSystem_Android::quit() {
ENTER();
diff --git a/backends/platform/android3d/android.h b/backends/platform/android3d/android.h
index 149d3782ce..6c0c29f6ff 100644
--- a/backends/platform/android3d/android.h
+++ b/backends/platform/android3d/android.h
@@ -102,7 +102,7 @@ extern void checkGlError(const char *expr, const char *file, int line);
#define GLTHREADCHECK do { } while (false)
#endif
-class OSystem_Android : public ModularMutexBackend, public ModularGraphicsBackend, Common::EventSource {
+class OSystem_Android : public ModularGraphicsBackend, Common::EventSource {
private:
// passed from the dark side
int _audio_sample_rate;
@@ -172,6 +172,7 @@ public:
virtual uint32 getMillis(bool skipRecord = false);
virtual void delayMillis(uint msecs);
+ virtual Common::MutexInternal *createMutex();
virtual void quit();
diff --git a/backends/platform/dc/dc.h b/backends/platform/dc/dc.h
index 7665ae8420..e96e969921 100644
--- a/backends/platform/dc/dc.h
+++ b/backends/platform/dc/dc.h
@@ -163,10 +163,7 @@ public:
virtual Graphics::PixelFormat getOverlayFormat() const { return Graphics::PixelFormat(2, 4, 4, 4, 4, 8, 4, 0, 12); }
// Mutex handling
- MutexRef createMutex();
- void lockMutex(MutexRef mutex);
- void unlockMutex(MutexRef mutex);
- void deleteMutex(MutexRef mutex);
+ Common::MutexInternal *createMutex();
// Set a window caption or any other comparable status display to the
// given value.
diff --git a/backends/platform/dc/dcmain.cpp b/backends/platform/dc/dcmain.cpp
index 3b3436c46a..741776ffe1 100644
--- a/backends/platform/dc/dcmain.cpp
+++ b/backends/platform/dc/dcmain.cpp
@@ -30,6 +30,7 @@
#include "dcutils.h"
#include "icon.h"
#include "DCLauncherDialog.h"
+#include "backends/mutex/null/null-mutex.h"
#include <common/config-manager.h>
#include <common/memstream.h>
#include <common/endian.h>
@@ -153,24 +154,11 @@ void OSystem_Dreamcast::quit() {
}
/* Mutex handling */
-OSystem::MutexRef OSystem_Dreamcast::createMutex()
+Common::MutexInternal *OSystem_Dreamcast::createMutex()
{
- return NULL;
+ return new NullMutexInternal();
}
-void OSystem_Dreamcast::lockMutex(MutexRef mutex)
-{
-}
-
-void OSystem_Dreamcast::unlockMutex(MutexRef mutex)
-{
-}
-
-void OSystem_Dreamcast::deleteMutex(MutexRef mutex)
-{
-}
-
-
/* Features */
bool OSystem_Dreamcast::hasFeature(Feature f)
{
diff --git a/backends/platform/ds/osystem_ds.cpp b/backends/platform/ds/osystem_ds.cpp
index bd7ef899c9..5bf02dcacc 100644
--- a/backends/platform/ds/osystem_ds.cpp
+++ b/backends/platform/ds/osystem_ds.cpp
@@ -56,7 +56,6 @@ OSystem_DS::OSystem_DS()
nitroFSInit(NULL);
_fsFactory = new DevoptabFilesystemFactory();
- _mutexManager = new NullMutexManager();
}
OSystem_DS::~OSystem_DS() {
@@ -129,6 +128,10 @@ void OSystem_DS::getTimeAndDate(TimeDate &td, bool skipRecord) const {
td.tm_wday = t.tm_wday;
}
+Common::MutexInternal *OSystem_DS::createMutex() {
+ return new NullMutexInternal();
+}
+
void OSystem_DS::quit() {
}
diff --git a/backends/platform/ds/osystem_ds.h b/backends/platform/ds/osystem_ds.h
index 79e62b2675..67c385dfeb 100644
--- a/backends/platform/ds/osystem_ds.h
+++ b/backends/platform/ds/osystem_ds.h
@@ -38,7 +38,7 @@ enum {
GFX_SWSCALE = 2
};
-class OSystem_DS : public ModularMutexBackend, public ModularMixerBackend, public PaletteManager {
+class OSystem_DS : public ModularMixerBackend, public PaletteManager {
protected:
DS::Background _framebuffer, _overlay;
#ifdef DISABLE_TEXT_CONSOLE
@@ -130,6 +130,7 @@ public:
virtual void delayMillis(uint msecs);
virtual void getTimeAndDate(TimeDate &td, bool skipRecord = false) const;
void doTimerCallback(int interval = 10);
+ virtual Common::MutexInternal *createMutex();
virtual Common::EventSource *getDefaultEventSource() { return _eventSource; }
virtual Common::HardwareInputSet *getHardwareInputSet();
diff --git a/backends/platform/ios7/ios7_osys_main.cpp b/backends/platform/ios7/ios7_osys_main.cpp
index ff275f3549..952c8e2563 100644
--- a/backends/platform/ios7/ios7_osys_main.cpp
+++ b/backends/platform/ios7/ios7_osys_main.cpp
@@ -131,8 +131,6 @@ int OSystem_iOS7::timerHandler(int t) {
}
void OSystem_iOS7::initBackend() {
- _mutexManager = new PthreadMutexManager();
-
#ifdef IPHONE_SANDBOXED
_savefileManager = new SandboxedSaveFileManager(_chrootBasePath, "/Savegames");
#else
@@ -309,6 +307,10 @@ void OSystem_iOS7::setTimerCallback(TimerProc callback, int interval) {
_timerCallback = NULL;
}
+Common::MutexInternal *OSystem_iOS7::createMutex() {
+ return createPthreadMutexInternal();
+}
+
void OSystem_iOS7::quit() {
}
diff --git a/backends/platform/ios7/ios7_osys_main.h b/backends/platform/ios7/ios7_osys_main.h
index ba627c5509..2e8afc8360 100644
--- a/backends/platform/ios7/ios7_osys_main.h
+++ b/backends/platform/ios7/ios7_osys_main.h
@@ -53,7 +53,7 @@ struct AQCallbackStruct {
AudioStreamBasicDescription dataFormat;
};
-class OSystem_iOS7 : public EventsBaseBackend, public ModularMutexBackend, public PaletteManager {
+class OSystem_iOS7 : public EventsBaseBackend, public PaletteManager {
protected:
static AQCallbackStruct s_AudioQueue;
static SoundProc s_soundCallback;
@@ -180,6 +180,7 @@ public:
virtual bool pollEvent(Common::Event &event) override;
virtual uint32 getMillis(bool skipRecord = false) override;
virtual void delayMillis(uint msecs) override;
+ virtual Common::MutexInternal *createMutex() override;
static void mixCallback(void *sys, byte *samples, int len);
virtual void setupMixer(void);
diff --git a/backends/platform/iphone/osys_main.cpp b/backends/platform/iphone/osys_main.cpp
index 42db5221bc..c14c031e56 100644
--- a/backends/platform/iphone/osys_main.cpp
+++ b/backends/platform/iphone/osys_main.cpp
@@ -84,8 +84,6 @@ int OSystem_IPHONE::timerHandler(int t) {
}
void OSystem_IPHONE::initBackend() {
- _mutexManager = new PthreadMutexManager();
-
#ifdef IPHONE_SANDBOXED
_savefileManager = new DefaultSaveFileManager(iPhone_getDocumentsDir());
#else
@@ -195,6 +193,10 @@ void OSystem_IPHONE::setTimerCallback(TimerProc callback, int interval) {
_timerCallback = NULL;
}
+Common::MutexInternal *OSystem_IPHONE::createMutex() {
+ return createPthreadMutexInternal();
+}
+
void OSystem_IPHONE::quit() {
}
diff --git a/backends/platform/iphone/osys_main.h b/backends/platform/iphone/osys_main.h
index 139b301559..f4d389ff88 100644
--- a/backends/platform/iphone/osys_main.h
+++ b/backends/platform/iphone/osys_main.h
@@ -51,7 +51,7 @@ struct AQCallbackStruct {
AudioStreamBasicDescription dataFormat;
};
-class OSystem_IPHONE : public EventsBaseBackend, public ModularMutexBackend, public PaletteManager {
+class OSystem_IPHONE : public EventsBaseBackend, public PaletteManager {
protected:
static AQCallbackStruct s_AudioQueue;
static SoundProc s_soundCallback;
@@ -165,6 +165,7 @@ public:
virtual bool pollEvent(Common::Event &event);
virtual uint32 getMillis(bool skipRecord = false);
virtual void delayMillis(uint msecs);
+ virtual Common::MutexInternal *createMutex();
static void mixCallback(void *sys, byte *samples, int len);
virtual void setupMixer(void);
diff --git a/backends/platform/n64/osys_n64.h b/backends/platform/n64/osys_n64.h
index b5cb45312c..6360542813 100644
--- a/backends/platform/n64/osys_n64.h
+++ b/backends/platform/n64/osys_n64.h
@@ -187,10 +187,7 @@ public:
virtual uint32 getMillis(bool skipRecord = false);
virtual void delayMillis(uint msecs);
- virtual MutexRef createMutex(void);
- virtual void lockMutex(MutexRef mutex);
- virtual void unlockMutex(MutexRef mutex);
- virtual void deleteMutex(MutexRef mutex);
+ virtual Common::MutexInternal *createMutex(void);
virtual void quit();
diff --git a/backends/platform/n64/osys_n64_base.cpp b/backends/platform/n64/osys_n64_base.cpp
index 679e0c504c..a3296cc20f 100644
--- a/backends/platform/n64/osys_n64_base.cpp
+++ b/backends/platform/n64/osys_n64_base.cpp
@@ -30,6 +30,7 @@
#include "pakfs_save_manager.h"
#include "framfs_save_manager.h"
#include "backends/fs/n64/n64-fs-factory.h"
+#include "backends/mutex/null/null-mutex.h"
#include "backends/saves/default/default-saves.h"
#include "backends/timer/default/default-timer.h"
#include "graphics/conversion.h"
@@ -812,20 +813,8 @@ void OSystem_N64::delayMillis(uint msecs) {
}
// As we don't have multi-threading, no need for mutexes
-OSystem::MutexRef OSystem_N64::createMutex(void) {
- return NULL;
-}
-
-void OSystem_N64::lockMutex(MutexRef mutex) {
- return;
-}
-
-void OSystem_N64::unlockMutex(MutexRef mutex) {
- return;
-}
-
-void OSystem_N64::deleteMutex(MutexRef mutex) {
- return;
+Common::MutexInternal *OSystem_N64::createMutex(void) {
+ return new NullMutexInternal();
}
void OSystem_N64::quit() {
diff --git a/backends/platform/null/null.cpp b/backends/platform/null/null.cpp
index 4507d3d114..d667e40c0a 100644
--- a/backends/platform/null/null.cpp
+++ b/backends/platform/null/null.cpp
@@ -49,6 +49,7 @@ typedef void (*sighandler_t)(int);
#if defined(USE_NULL_DRIVER)
#include "backends/modular-backend.h"
+#include "backends/mutex/null/null-mutex.h"
#include "base/main.h"
#ifndef NULL_DRIVER_USE_FOR_TEST
@@ -56,7 +57,6 @@ typedef void (*sighandler_t)(int);
#include "backends/timer/default/default-timer.h"
#include "backends/events/default/default-events.h"
#include "backends/mixer/null/null-mixer.h"
-#include "backends/mutex/null/null-mutex.h"
#include "backends/graphics/null/null-graphics.h"
#include "gui/debugger.h"
#endif
@@ -76,7 +76,7 @@ typedef void (*sighandler_t)(int);
#include "backends/fs/windows/windows-fs-factory.h"
#endif
-class OSystem_NULL : public ModularMutexBackend, public ModularMixerBackend, public ModularGraphicsBackend, Common::EventSource {
+class OSystem_NULL : public ModularMixerBackend, public ModularGraphicsBackend, Common::EventSource {
public:
OSystem_NULL();
virtual ~OSystem_NULL();
@@ -85,6 +85,7 @@ public:
virtual bool pollEvent(Common::Event &event);
+ virtual Common::MutexInternal *createMutex();
virtual uint32 getMillis(bool skipRecord = false);
virtual void delayMillis(uint msecs);
virtual void getTimeAndDate(TimeDate &td, bool skipRecord = false) const;
@@ -145,7 +146,6 @@ void OSystem_NULL::initBackend() {
last_handler = signal(SIGINT, intHandler);
#endif
- _mutexManager = new NullMutexManager();
_timerManager = new DefaultTimerManager();
_eventManager = new DefaultEventManager(this);
_savefileManager = new DefaultSaveFileManager();
@@ -185,6 +185,10 @@ bool OSystem_NULL::pollEvent(Common::Event &event) {
return false;
}
+Common::MutexInternal *OSystem_NULL::createMutex() {
+ return new NullMutexInternal();
+}
+
uint32 OSystem_NULL::getMillis(bool skipRecord) {
#ifdef POSIX
timeval curTime;
diff --git a/backends/platform/psp/osys_psp.cpp b/backends/platform/psp/osys_psp.cpp
index 83f1fde1e3..c10ed5658d 100644
--- a/backends/platform/psp/osys_psp.cpp
+++ b/backends/platform/psp/osys_psp.cpp
@@ -358,20 +358,8 @@ void OSystem_PSP::delayMillis(uint msecs) {
PspThread::delayMillis(msecs);
}
-OSystem::MutexRef OSystem_PSP::createMutex(void) {
- return (MutexRef) new PspMutex(true); // start with a full mutex
-}
-
-void OSystem_PSP::lockMutex(MutexRef mutex) {
- ((PspMutex *)mutex)->lock();
-}
-
-void OSystem_PSP::unlockMutex(MutexRef mutex) {
- ((PspMutex *)mutex)->unlock();
-}
-
-void OSystem_PSP::deleteMutex(MutexRef mutex) {
- delete (PspMutex *)mutex;
+Common::MutexInternal *OSystem_PSP::createMutex(void) {
+ return new PspMutex(true); // start with a full mutex
}
void OSystem_PSP::mixCallback(void *sys, byte *samples, int len) {
diff --git a/backends/platform/psp/osys_psp.h b/backends/platform/psp/osys_psp.h
index d12be80944..cf64b74f0b 100644
--- a/backends/platform/psp/osys_psp.h
+++ b/backends/platform/psp/osys_psp.h
@@ -126,10 +126,7 @@ public:
void delayMillis(uint msecs);
// Mutex
- MutexRef createMutex(void);
- void lockMutex(MutexRef mutex);
- void unlockMutex(MutexRef mutex);
- void deleteMutex(MutexRef mutex);
+ Common::MutexInternal *createMutex(void);
// Sound
static void mixCallback(void *sys, byte *samples, int len);
diff --git a/backends/platform/psp/thread.h b/backends/platform/psp/thread.h
index a0d53e8638..176654b701 100644
--- a/backends/platform/psp/thread.h
+++ b/backends/platform/psp/thread.h
@@ -24,7 +24,7 @@
#define PSP_THREAD_H
#include <pspthreadman.h>
-#include "common/scummsys.h"
+#include "common/mutex.h"
// class to inherit for creating threads
class PspThreadable {
@@ -60,7 +60,7 @@ public:
int getValue();
};
-class PspMutex {
+class PspMutex : public Common::MutexInternal {
private:
PspSemaphore _semaphore;
int _recursiveCount;
diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp
index b5f231c742..04ed348d50 100644
--- a/backends/platform/sdl/sdl.cpp
+++ b/backends/platform/sdl/sdl.cpp
@@ -133,8 +133,6 @@ OSystem_SDL::~OSystem_SDL() {
#endif
_timerManager = 0;
- delete _mutexManager;
- _mutexManager = 0;
delete _logger;
_logger = 0;
@@ -163,11 +161,6 @@ void OSystem_SDL::init() {
// Disable OS cursor
SDL_ShowCursor(SDL_DISABLE);
- // Creates the early needed managers, if they don't exist yet
- // (we check for this to allow subclasses to provide their own).
- if (_mutexManager == 0)
- _mutexManager = new SdlMutexManager();
-
if (_window == 0)
_window = new SdlWindow();
@@ -650,6 +643,10 @@ bool OSystem_SDL::openUrl(const Common::String &url) {
}
#endif
+Common::MutexInternal *OSystem_SDL::createMutex() {
+ return createSdlMutexInternal();
+}
+
uint32 OSystem_SDL::getMillis(bool skipRecord) {
uint32 millis = SDL_GetTicks();
diff --git a/backends/platform/sdl/sdl.h b/backends/platform/sdl/sdl.h
index 4248bac1ee..c376591bd6 100644
--- a/backends/platform/sdl/sdl.h
+++ b/backends/platform/sdl/sdl.h
@@ -40,7 +40,7 @@ class DiscordPresence;
/**
* Base OSystem class for all SDL ports.
*/
-class OSystem_SDL : public ModularMutexBackend, public ModularMixerBackend, public ModularGraphicsBackend {
+class OSystem_SDL : public ModularMixerBackend, public ModularGraphicsBackend {
public:
OSystem_SDL();
virtual ~OSystem_SDL();
@@ -83,6 +83,7 @@ public:
virtual void setWindowCaption(const Common::U32String &caption) override;
virtual void addSysArchivesToSearchSet(Common::SearchSet &s, int priority = 0) override;
+ virtual Common::MutexInternal *createMutex() override;
virtual uint32 getMillis(bool skipRecord = false) override;
virtual void delayMillis(uint msecs) override;
virtual void getTimeAndDate(TimeDate &td, bool skipRecord = false) const override;
diff --git a/backends/platform/wii/osystem.cpp b/backends/platform/wii/osystem.cpp
index f5c90fb0d5..dfbcb687a4 100644
--- a/backends/platform/wii/osystem.cpp
+++ b/backends/platform/wii/osystem.cpp
@@ -25,12 +25,12 @@
#include <unistd.h>
#include <ogc/conf.h>
-#include <ogc/mutex.h>
#include <ogc/lwp_watchdog.h>
#include "common/config-manager.h"
#include "common/textconsole.h"
#include "backends/fs/wii/wii-fs-factory.h"
+#include "backends/mutex/wii/wii-mutex.h"
#include "backends/saves/default/default-saves.h"
#include "backends/timer/default/default-timer.h"
@@ -221,40 +221,8 @@ void OSystem_Wii::delayMillis(uint msecs) {
usleep(msecs * 1000);
}
-OSystem::MutexRef OSystem_Wii::createMutex() {
- mutex_t *mutex = (mutex_t *) malloc(sizeof(mutex_t));
- s32 res = LWP_MutexInit(mutex, true);
-
- if (res) {
- printf("ERROR creating mutex\n");
- free(mutex);
- return NULL;
- }
-
- return (MutexRef) mutex;
-}
-
-void OSystem_Wii::lockMutex(MutexRef mutex) {
- s32 res = LWP_MutexLock(*(mutex_t *)mutex);
-
- if (res)
- printf("ERROR locking mutex %p (%d)\n", mutex, res);
-}
-
-void OSystem_Wii::unlockMutex(MutexRef mutex) {
- s32 res = LWP_MutexUnlock(*(mutex_t *)mutex);
-
- if (res)
- printf("ERROR unlocking mutex %p (%d)\n", mutex, res);
-}
-
-void OSystem_Wii::deleteMutex(MutexRef mutex) {
- s32 res = LWP_MutexDestroy(*(mutex_t *)mutex);
-
- if (res)
- printf("ERROR destroying mutex %p (%d)\n", mutex, res);
-
- free(mutex);
+Common::MutexInternal *OSystem_Wii::createMutex() {
+ return createWiiMutexInternal();
}
Audio::Mixer *OSystem_Wii::getMixer() {
diff --git a/backends/platform/wii/osystem.h b/backends/platform/wii/osystem.h
index a76f5cc132..8d49cf342b 100644
--- a/backends/platform/wii/osystem.h
+++ b/backends/platform/wii/osystem.h
@@ -197,10 +197,7 @@ public:
virtual uint32 getMillis(bool skipRecord = false) override;
virtual void delayMillis(uint msecs) override;
- virtual MutexRef createMutex() override;
- virtual void lockMutex(MutexRef mutex) override;
- virtual void unlockMutex(MutexRef mutex) override;
- virtual void deleteMutex(MutexRef mutex) override;
+ virtual Common::MutexInternal *createMutex() override;
typedef void (*SoundProc)(void *param, byte *buf, int len);
diff --git a/backends/timer/sdl/sdl-timer.cpp b/backends/timer/sdl/sdl-timer.cpp
index f9d79ac885..ce1af0ea68 100644
--- a/backends/timer/sdl/sdl-timer.cpp
+++ b/backends/timer/sdl/sdl-timer.cpp
@@ -29,11 +29,7 @@
#include "common/textconsole.h"
-OSystem::MutexRef timerMutex;
-
static Uint32 timer_handler(Uint32 interval, void *param) {
- Common::StackLock lock(timerMutex);
-
((DefaultTimerManager *)param)->handler();
return interval;
}
@@ -49,8 +45,6 @@ SdlTimerManager::SdlTimerManager() {
}
SdlTimerManager::~SdlTimerManager() {
- Common::StackLock lock(timerMutex);
-
// Removes the timer callback
SDL_RemoveTimer(_timerID);
diff --git a/common/mutex.cpp b/common/mutex.cpp
index cc5af7b4a7..5d489407b8 100644
--- a/common/mutex.cpp
+++ b/common/mutex.cpp
@@ -32,22 +32,22 @@ Mutex::Mutex() {
}
Mutex::~Mutex() {
- g_system->deleteMutex(_mutex);
+ delete _mutex;
}
-void Mutex::lock() {
- g_system->lockMutex(_mutex);
+bool Mutex::lock() {
+ return _mutex->lock();
}
-void Mutex::unlock() {
- g_system->unlockMutex(_mutex);
+bool Mutex::unlock() {
+ return _mutex->unlock();
}
#pragma mark -
-StackLock::StackLock(OSystem::MutexRef mutex, const char *mutexName)
+StackLock::StackLock(MutexInternal *mutex, const char *mutexName)
: _mutex(mutex), _mutexName(mutexName) {
lock();
}
@@ -61,18 +61,18 @@ StackLock::~StackLock() {
unlock();
}
-void StackLock::lock() {
+bool StackLock::lock() {
if (_mutexName != nullptr)
debug(6, "Locking mutex %s", _mutexName);
- g_system->lockMutex(_mutex);
+ return _mutex->lock();
}
-void StackLock::unlock() {
+bool StackLock::unlock() {
if (_mutexName != nullptr)
debug(6, "Unlocking mutex %s", _mutexName);
- g_system->unlockMutex(_mutex);
+ return _mutex->unlock();
}
} // End of namespace Common
diff --git a/common/mutex.h b/common/mutex.h
index 3c64b0214c..9d5b4d8105 100644
--- a/common/mutex.h
+++ b/common/mutex.h
@@ -38,17 +38,25 @@ namespace Common {
class Mutex;
+class MutexInternal {
+public:
+ virtual ~MutexInternal() {}
+
+ virtual bool lock() = 0;
+ virtual bool unlock() = 0;
+};
+
/**
* Auxillary class to (un)lock a mutex on the stack.
*/
class StackLock {
- OSystem::MutexRef _mutex;
+ MutexInternal *_mutex;
const char *_mutexName;
- void lock();
- void unlock();
+ bool lock();
+ bool unlock();
public:
- explicit StackLock(OSystem::MutexRef mutex, const char *mutexName = nullptr);
+ explicit StackLock(MutexInternal *mutex, const char *mutexName = nullptr);
explicit StackLock(const Mutex &mutex, const char *mutexName = nullptr);
~StackLock();
};
@@ -60,14 +68,14 @@ public:
class Mutex {
friend class StackLock;
- OSystem::MutexRef _mutex;
+ MutexInternal *_mutex;
public:
Mutex();
~Mutex();
- void lock();
- void unlock();
+ bool lock();
+ bool unlock();
};
/** @} */
diff --git a/common/system.h b/common/system.h
index bbbf4378a8..f4315deaef 100644
--- a/common/system.h
+++ b/common/system.h
@@ -47,6 +47,7 @@ class OptionsContainerWidget;
namespace Common {
class EventManager;
+class MutexInternal;
struct Rect;
class SaveFileManager;
class SearchSet;
@@ -1436,44 +1437,12 @@ public:
* use dummy implementations for these methods.
*/
- typedef struct OpaqueMutex *MutexRef;
-
/**
* Create a new mutex.
*
* @return The newly created mutex, or 0 if an error occurred.
*/
- virtual MutexRef createMutex() = 0;
-
- /**
- * Lock the given mutex.
- *
- * @note ScummVM code assumes that the mutex implementation supports
- * recursive locking. That is, a thread can lock a mutex twice without
- * deadlocking. In case of a multilock, the mutex must be unlocked
- * as many times as it was locked befored it really becomes unlocked.
- *
- * @param mutex The mutex to lock.
- */
- virtual void lockMutex(MutexRef mutex) = 0;
-
- /**
- * Unlock the given mutex.
- *
- * @param mutex The mutex to unlock.
- */
- virtual void unlockMutex(MutexRef mutex) = 0;
-
- /**
- * Delete the given mutex.
- *
- * Make sure the mutex is unlocked before you delete it.
- * If you delete a locked mutex, the behavior is undefined.
- * In particular, your program may crash.
- *
- * @param mutex The mutex to delete.
- */
- virtual void deleteMutex(MutexRef mutex) = 0;
+ virtual Common::MutexInternal *createMutex() = 0;
/** @} */
More information about the Scummvm-git-logs
mailing list