ScopedLock takes Mutex as reference not as pointer

master
Denes Matetelki 14 years ago
parent f2e7c786c4
commit f6493685d1

@ -35,7 +35,7 @@ class ConcurrentQueue {
void push(const T task) void push(const T task)
{ {
TRACE(this); TRACE(this);
ScopedLock sl(&m_mutex); ScopedLock sl(m_mutex);
if (m_cancelled) throw CancelledException(); if (m_cancelled) throw CancelledException();
m_queue.push( task ); m_queue.push( task );
m_condition.signal(); m_condition.signal();
@ -45,7 +45,7 @@ class ConcurrentQueue {
bool tryPop(T &popped_value) bool tryPop(T &popped_value)
{ {
TRACE(this); TRACE(this);
ScopedLock sl(&m_mutex); ScopedLock sl(m_mutex);
if (m_cancelled) throw CancelledException(); if (m_cancelled) throw CancelledException();
if ( m_queue.empty() ) return false; if ( m_queue.empty() ) return false;
@ -58,7 +58,7 @@ class ConcurrentQueue {
T waitAndPop() T waitAndPop()
{ {
TRACE(this); TRACE(this);
ScopedLock sl(&m_mutex); ScopedLock sl(m_mutex);
while ( m_queue.empty() and not m_cancelled) { while ( m_queue.empty() and not m_cancelled) {
m_condition.wait(); m_condition.wait();
@ -74,7 +74,7 @@ class ConcurrentQueue {
bool empty() const bool empty() const
{ {
TRACE(this); TRACE(this);
ScopedLock sl(&m_mutex); ScopedLock sl(m_mutex);
if (m_cancelled) throw CancelledException(); if (m_cancelled) throw CancelledException();
return m_queue.empty(); return m_queue.empty();
} }
@ -83,7 +83,7 @@ class ConcurrentQueue {
void cancel() void cancel()
{ {
TRACE(this); TRACE(this);
ScopedLock sl(&m_mutex); ScopedLock sl(m_mutex);
m_cancelled = true; m_cancelled = true;
m_condition.broadcast(); m_condition.broadcast();
} }

@ -9,7 +9,7 @@ class ScopedLock
public: public:
ScopedLock( const Mutex* const mutex ); ScopedLock( Mutex& mutex );
~ScopedLock(); ~ScopedLock();
private: private:
@ -17,7 +17,7 @@ private:
ScopedLock(const ScopedLock&); ScopedLock(const ScopedLock&);
ScopedLock& operator=(const ScopedLock&); ScopedLock& operator=(const ScopedLock&);
const Mutex* const m_mutex; Mutex& m_mutex;
}; };

@ -2,15 +2,15 @@
#include "Common.hpp" #include "Common.hpp"
ScopedLock::ScopedLock( const Mutex* const mutex) : m_mutex(mutex) ScopedLock::ScopedLock( Mutex& mutex) : m_mutex(mutex)
{ {
TRACE(this); TRACE(this);
const_cast<Mutex*>(m_mutex)->lock(); m_mutex.lock();
} }
ScopedLock::~ScopedLock() ScopedLock::~ScopedLock()
{ {
TRACE(this); TRACE(this);
const_cast<Mutex*>(m_mutex)->unlock(); m_mutex.unlock();
} }

Loading…
Cancel
Save