Resolve a #define clash with the template argument LOCK.
This commit is contained in:
parent
a6ac06c47a
commit
29dfc5bd3c
@ -6,16 +6,16 @@
|
|||||||
* An SGGuard object locks its synchronization object during creation and
|
* An SGGuard object locks its synchronization object during creation and
|
||||||
* automatically unlocks it when it goes out of scope.
|
* automatically unlocks it when it goes out of scope.
|
||||||
*/
|
*/
|
||||||
template<class LOCK>
|
template<class SGLOCK>
|
||||||
class SGGuard
|
class SGGuard
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create an SGGuard object and lock the passed lockable object.
|
* Create an SGGuard object and lock the passed lockable object.
|
||||||
* @param LOCK A lockable object.
|
* @param SGLOCK A lockable object.
|
||||||
*/
|
*/
|
||||||
inline SGGuard( LOCK& l ) : lock(l) { lock.lock(); }
|
inline SGGuard( SGLOCK& l ) : lock(l) { lock.lock(); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destroy this object and unlock the locakable object.
|
* Destroy this object and unlock the locakable object.
|
||||||
@ -27,12 +27,12 @@ private:
|
|||||||
/**
|
/**
|
||||||
* A lockable object.
|
* A lockable object.
|
||||||
*/
|
*/
|
||||||
LOCK& lock;
|
SGLOCK& lock;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Disable copying.
|
// Disable copying.
|
||||||
SGGuard(const LOCK&);
|
SGGuard(const SGLOCK&);
|
||||||
LOCK& operator= (const LOCK&);
|
SGLOCK& operator= (const SGLOCK&);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SGGUARD_HXX_INCLUDED
|
#endif // SGGUARD_HXX_INCLUDED
|
||||||
|
@ -64,7 +64,7 @@ protected:
|
|||||||
/**
|
/**
|
||||||
* A simple thread safe queue. All access functions are guarded with a mutex.
|
* A simple thread safe queue. All access functions are guarded with a mutex.
|
||||||
*/
|
*/
|
||||||
template<class T, class LOCK=SGMutex>
|
template<class T, class SGLOCK=SGMutex>
|
||||||
class SGLockedQueue : public SGQueue<T>
|
class SGLockedQueue : public SGQueue<T>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -85,7 +85,7 @@ public:
|
|||||||
* @return bool True if queue is empty, otherwisr false.
|
* @return bool True if queue is empty, otherwisr false.
|
||||||
*/
|
*/
|
||||||
virtual bool empty() {
|
virtual bool empty() {
|
||||||
SGGuard<LOCK> g(mutex);
|
SGGuard<SGLOCK> g(mutex);
|
||||||
return fifo.empty();
|
return fifo.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,7 +95,7 @@ public:
|
|||||||
* @param T object to add.
|
* @param T object to add.
|
||||||
*/
|
*/
|
||||||
virtual void push( const T& item ) {
|
virtual void push( const T& item ) {
|
||||||
SGGuard<LOCK> g(mutex);
|
SGGuard<SGLOCK> g(mutex);
|
||||||
fifo.push( item );
|
fifo.push( item );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,7 +105,7 @@ public:
|
|||||||
* @return T next available object.
|
* @return T next available object.
|
||||||
*/
|
*/
|
||||||
virtual T pop() {
|
virtual T pop() {
|
||||||
SGGuard<LOCK> g(mutex);
|
SGGuard<SGLOCK> g(mutex);
|
||||||
//if (fifo.empty()) throw NoSuchElementException();
|
//if (fifo.empty()) throw NoSuchElementException();
|
||||||
assert( ! fifo.empty() );
|
assert( ! fifo.empty() );
|
||||||
// if (fifo.empty())
|
// if (fifo.empty())
|
||||||
@ -122,7 +122,7 @@ private:
|
|||||||
/**
|
/**
|
||||||
* Mutex to serialise access.
|
* Mutex to serialise access.
|
||||||
*/
|
*/
|
||||||
LOCK mutex;
|
SGLOCK mutex;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Prevent copying.
|
// Prevent copying.
|
||||||
|
Loading…
Reference in New Issue
Block a user