diff --git a/stepmania/src/RageThreads.cpp b/stepmania/src/RageThreads.cpp index bc8211f195..0775923fd4 100644 --- a/stepmania/src/RageThreads.cpp +++ b/stepmania/src/RageThreads.cpp @@ -79,11 +79,13 @@ LockMutex::LockMutex(RageMutex &mut, const char *file_, int line_): locked_at(RageTimer::GetTimeSinceStart()) { mutex.Lock(); + locked = true; } LockMutex::~LockMutex() { - mutex.Unlock(); + if(locked) + mutex.Unlock(); if(file) { @@ -93,6 +95,15 @@ LockMutex::~LockMutex() } } +void LockMutex::Unlock() +{ + ASSERT(locked); + locked = false; + + mutex.Unlock(); +} + + /* ----------------------------------------------------------------------------- File: RageThreads diff --git a/stepmania/src/RageThreads.h b/stepmania/src/RageThreads.h index 0ae02abeeb..a220d2986e 100644 --- a/stepmania/src/RageThreads.h +++ b/stepmania/src/RageThreads.h @@ -30,12 +30,17 @@ class LockMutex const char *file; int line; float locked_at; + bool locked; public: LockMutex(RageMutex &mut, const char *file, int line); LockMutex(RageMutex &mut): mutex(mut), file(NULL), line(-1), locked_at(0) { mutex.Lock(); } ~LockMutex(); LockMutex(LockMutex &cpy): mutex(cpy.mutex), file(cpy.file), line(cpy.line), locked_at(cpy.locked_at) { mutex.Lock(); } + + /* Unlock the mutex (before this would normally go out of scope). This can + * only be called once. */ + void Unlock(); }; /* Double-abstracting __LINE__ lets us append it to other text, to generate