add LockMutex::Unlock

This commit is contained in:
Glenn Maynard
2002-12-27 22:11:55 +00:00
parent 0c55e8d4bc
commit 0698b2580d
2 changed files with 17 additions and 1 deletions
+12 -1
View File
@@ -79,11 +79,13 @@ LockMutex::LockMutex(RageMutex &mut, const char *file_, int line_):
locked_at(RageTimer::GetTimeSinceStart()) locked_at(RageTimer::GetTimeSinceStart())
{ {
mutex.Lock(); mutex.Lock();
locked = true;
} }
LockMutex::~LockMutex() LockMutex::~LockMutex()
{ {
mutex.Unlock(); if(locked)
mutex.Unlock();
if(file) if(file)
{ {
@@ -93,6 +95,15 @@ LockMutex::~LockMutex()
} }
} }
void LockMutex::Unlock()
{
ASSERT(locked);
locked = false;
mutex.Unlock();
}
/* /*
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
File: RageThreads File: RageThreads
+5
View File
@@ -30,12 +30,17 @@ class LockMutex
const char *file; const char *file;
int line; int line;
float locked_at; float locked_at;
bool locked;
public: public:
LockMutex(RageMutex &mut, const char *file, int line); LockMutex(RageMutex &mut, const char *file, int line);
LockMutex(RageMutex &mut): mutex(mut), file(NULL), line(-1), locked_at(0) { mutex.Lock(); } LockMutex(RageMutex &mut): mutex(mut), file(NULL), line(-1), locked_at(0) { mutex.Lock(); }
~LockMutex(); ~LockMutex();
LockMutex(LockMutex &cpy): mutex(cpy.mutex), file(cpy.file), line(cpy.line), locked_at(cpy.locked_at) { mutex.Lock(); } 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 /* Double-abstracting __LINE__ lets us append it to other text, to generate