[Scummvm-cvs-logs] SF.net SVN: scummvm: [20677] residual/trunk
marcus_c at users.sourceforge.net
marcus_c at users.sourceforge.net
Mon Feb 13 13:17:01 CET 2006
Revision: 20677
Author: marcus_c
Date: 2006-02-13 13:15:32 -0800 (Mon, 13 Feb 2006)
ViewCVS: http://svn.sourceforge.net/scummvm?rev=20677&view=rev
Log Message:
-----------
Mutex stuff moved to driver.
Modified Paths:
--------------
residual/trunk/driver.h
residual/trunk/driver_sdl.cpp
residual/trunk/driver_sdl.h
residual/trunk/imuse/imuse.cpp
residual/trunk/imuse/imuse_track.cpp
residual/trunk/main.cpp
residual/trunk/mixer/audiostream.cpp
residual/trunk/mixer/mixer.cpp
residual/trunk/stdafx.h
residual/trunk/timer.cpp
Modified: residual/trunk/driver.h
===================================================================
--- residual/trunk/driver.h 2006-02-13 21:02:31 UTC (rev 20676)
+++ residual/trunk/driver.h 2006-02-13 21:15:32 UTC (rev 20677)
@@ -234,6 +234,49 @@
//@}
+ /**
+ * @name Mutex handling
+ * Historically, the OSystem API used to have a method which allowed
+ * creating threads. Hence mutex support was needed for thread syncing.
+ * To ease portability, though, we decided to remove the threading API.
+ * Instead, we now use timers (see setTimerCallback() and Timer).
+ * But since those may be implemented using threads (and in fact, that's
+ * how our primary backend, the SDL one, does it on many systems), we
+ * still have to do mutex syncing in our timer callbacks.
+ *
+ * Hence backends which do not use threads to implement the timers simply
+ * can use dummy implementations for these methods.
+ */
+ //@{
+
+ /**
+ * Create a new mutex.
+ * @return the newly created mutex, or 0 if an error occured.
+ */
+ virtual MutexRef createMutex() = 0;
+
+ /**
+ * Lock the given mutex.
+ * @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;
+
+ //@}
+
/** @name Sound */
//@{
typedef void (*SoundProc)(void *param, byte *buf, int len);
@@ -277,4 +320,15 @@
extern Driver *g_driver;
+class StackLock {
+ MutexRef _mutex;
+public:
+ StackLock(MutexRef mutex) : _mutex(mutex) {
+ g_driver->lockMutex(_mutex);
+ }
+ ~StackLock() {
+ g_driver->unlockMutex(_mutex);
+ }
+};
+
#endif
Modified: residual/trunk/driver_sdl.cpp
===================================================================
--- residual/trunk/driver_sdl.cpp 2006-02-13 21:02:31 UTC (rev 20676)
+++ residual/trunk/driver_sdl.cpp 2006-02-13 21:15:32 UTC (rev 20677)
@@ -356,6 +356,22 @@
SDL_SetTimer(timer, (SDL_TimerCallback) callback);
}
+MutexRef DriverSDL::createMutex() {
+ return (MutexRef)SDL_CreateMutex();
+}
+
+void DriverSDL::lockMutex(MutexRef mutex) {
+ SDL_mutexP((SDL_mutex *)mutex);
+}
+
+void DriverSDL::unlockMutex(MutexRef mutex) {
+ SDL_mutexV((SDL_mutex *)mutex);
+}
+
+void DriverSDL::deleteMutex(MutexRef mutex) {
+ SDL_DestroyMutex((SDL_mutex *)mutex);
+}
+
bool DriverSDL::setSoundCallback(SoundProc proc, void *param) {
SDL_AudioSpec desired;
Modified: residual/trunk/driver_sdl.h
===================================================================
--- residual/trunk/driver_sdl.h 2006-02-13 21:02:31 UTC (rev 20676)
+++ residual/trunk/driver_sdl.h 2006-02-13 21:15:32 UTC (rev 20677)
@@ -48,6 +48,11 @@
void delayMillis(uint msecs);
void setTimerCallback(TimerProc callback, int interval);
+ MutexRef createMutex();
+ void lockMutex(MutexRef mutex);
+ void unlockMutex(MutexRef mutex);
+ void deleteMutex(MutexRef mutex);
+
bool setSoundCallback(SoundProc proc, void *param);
void clearSoundCallback();
int getOutputSampleRate() const;
Modified: residual/trunk/imuse/imuse.cpp
===================================================================
--- residual/trunk/imuse/imuse.cpp 2006-02-13 21:02:31 UTC (rev 20676)
+++ residual/trunk/imuse/imuse.cpp 2006-02-13 21:15:32 UTC (rev 20677)
@@ -46,7 +46,7 @@
}
Imuse::Imuse(int fps) {
- _mutex = createMutex();
+ _mutex = g_driver->createMutex();
_pause = false;
_sound = new ImuseSndMgr();
_volVoice = 0;
@@ -73,7 +73,7 @@
delete _track[l];
}
delete _sound;
- deleteMutex(_mutex);
+ g_driver->deleteMutex(_mutex);
}
void Imuse::resetState() {
Modified: residual/trunk/imuse/imuse_track.cpp
===================================================================
--- residual/trunk/imuse/imuse_track.cpp 2006-02-13 21:02:31 UTC (rev 20676)
+++ residual/trunk/imuse/imuse_track.cpp 2006-02-13 21:15:32 UTC (rev 20677)
@@ -18,6 +18,7 @@
#include "stdafx.h"
#include "bits.h"
#include "debug.h"
+#include "driver.h"
#include "mixer/mixer.h"
#include "mixer/audiostream.h"
Modified: residual/trunk/main.cpp
===================================================================
--- residual/trunk/main.cpp 2006-02-13 21:02:31 UTC (rev 20676)
+++ residual/trunk/main.cpp 2006-02-13 21:15:32 UTC (rev 20677)
@@ -262,28 +262,3 @@
}
SDL_Quit();
}
-
-StackLock::StackLock(MutexRef mutex) :
- _mutex(mutex) {
- lockMutex(_mutex);
-}
-
-StackLock::~StackLock() {
- unlockMutex(_mutex);
-}
-
-MutexRef createMutex() {
- return (MutexRef)SDL_CreateMutex();
-}
-
-void lockMutex(MutexRef mutex) {
- SDL_mutexP((SDL_mutex *)mutex);
-}
-
-void unlockMutex(MutexRef mutex) {
- SDL_mutexV((SDL_mutex *)mutex);
-}
-
-void deleteMutex(MutexRef mutex) {
- SDL_DestroyMutex((SDL_mutex *)mutex);
-}
Modified: residual/trunk/mixer/audiostream.cpp
===================================================================
--- residual/trunk/mixer/audiostream.cpp 2006-02-13 21:02:31 UTC (rev 20676)
+++ residual/trunk/mixer/audiostream.cpp 2006-02-13 21:15:32 UTC (rev 20677)
@@ -17,6 +17,7 @@
#include "stdafx.h"
#include "debug.h"
+#include "driver.h"
#include "mixer/mixer.h"
#include "mixer/audiostream.h"
@@ -132,13 +133,13 @@
_pos = _end = _bufferStart;
_bufferEnd = _bufferStart + bufferSize;
- _mutex = createMutex();
+ _mutex = g_driver->createMutex();
}
template<bool stereo, bool is16Bit, bool isUnsigned, bool isLE>
AppendableMemoryStream<stereo, is16Bit, isUnsigned, isLE>::~AppendableMemoryStream() {
free(_bufferStart);
- deleteMutex(_mutex);
+ g_driver->deleteMutex(_mutex);
}
template<bool stereo, bool is16Bit, bool isUnsigned, bool isLE>
Modified: residual/trunk/mixer/mixer.cpp
===================================================================
--- residual/trunk/mixer/mixer.cpp 2006-02-13 21:02:31 UTC (rev 20676)
+++ residual/trunk/mixer/mixer.cpp 2006-02-13 21:15:32 UTC (rev 20677)
@@ -80,7 +80,7 @@
SoundMixer::SoundMixer() {
- _mutex = createMutex();
+ _mutex = g_driver->createMutex();
_premixChannel = NULL;
_globalVolume = 0;
_paused = false;
@@ -102,7 +102,7 @@
delete _premixChannel;
_premixChannel = NULL;
- deleteMutex(_mutex);
+ g_driver->deleteMutex(_mutex);
}
bool SoundMixer::isPaused() {
Modified: residual/trunk/stdafx.h
===================================================================
--- residual/trunk/stdafx.h 2006-02-13 21:02:31 UTC (rev 20676)
+++ residual/trunk/stdafx.h 2006-02-13 21:15:32 UTC (rev 20677)
@@ -21,18 +21,6 @@
typedef struct Mutex *MutexRef;
-class StackLock {
- MutexRef _mutex;
-public:
- StackLock(MutexRef mutex);
- ~StackLock();
-};
-
-MutexRef createMutex();
-void lockMutex(MutexRef mutex);
-void unlockMutex(MutexRef mutex);
-void deleteMutex(MutexRef mutex);
-
#ifndef _MSC_VER
#include <unistd.h>
#endif
Modified: residual/trunk/timer.cpp
===================================================================
--- residual/trunk/timer.cpp 2006-02-13 21:02:31 UTC (rev 20676)
+++ residual/trunk/timer.cpp 2006-02-13 21:15:32 UTC (rev 20677)
@@ -28,7 +28,7 @@
_timerHandler(0),
_lastTime(0) {
- _mutex = createMutex();
+ _mutex = g_driver->createMutex();
g_timer = this;
@@ -56,7 +56,7 @@
}
}
- deleteMutex(_mutex);
+ g_driver->deleteMutex(_mutex);
}
int Timer::timer_handler(int t) {
More information about the Scummvm-git-logs
mailing list