From 9412bbe3a33fd2801ea1729978de961e0c0a6321 Mon Sep 17 00:00:00 2001 From: syntheticpp Date: Mon, 30 Jan 2006 20:33:01 +0000 Subject: [PATCH] use policies from SmartPtr.h, clean up git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@526 7ec92016-0320-0410-acc4-a06ded1c099a --- include/loki/LockingPtr.h | 89 ++++----------------------------------- 1 file changed, 8 insertions(+), 81 deletions(-) diff --git a/include/loki/LockingPtr.h b/include/loki/LockingPtr.h index 8d706ed..03671f2 100755 --- a/include/loki/LockingPtr.h +++ b/include/loki/LockingPtr.h @@ -16,23 +16,10 @@ #ifndef LOKI_LOCKING_PTR_INC_ #define LOKI_LOCKING_PTR_INC_ +#include + namespace Loki { - - template - struct NonConstObject - { - typedef T Type; - }; - - template - struct ConstObject - { - typedef const T Type; - }; - - - /** @class LockingPtr Locks a volatile object and casts away volatility so that the object can be safely used in a single-threaded region of code. @@ -42,7 +29,7 @@ namespace Loki LockingPolicy class are to provide Lock and Unlock methods. */ template < typename SharedObject, typename LockingPolicy = LOKI_DEFAULT_MUTEX, - template class ConstPolicy = NonConstObject > + template class ConstPolicy = LOKI_DEFAULT_CONSTNESS > class LockingPtr { public: @@ -101,73 +88,10 @@ namespace Loki template struct Locking { - typedef LockingPtr Ptr; - typedef LockingPtr ConstPtr; + typedef LockingPtr Ptr; + typedef LockingPtr ConstPtr; }; - -#if 0 - /** @class ConstLockingPtr - Similar to LockingPtr, except that it returns pointers and references to - a const SharedObject instead of a mutuable SharedObject. - @see LockingPtr - */ - template < typename SharedObject, typename LockingPolicy = LOKI_DEFAULT_MUTEX > - class ConstLockingPtr - { - public: - - /** Constructor locks mutex associated with an object. - @param obj Reference to const object. - @param mtx Mutex used to control thread access to object. - */ - ConstLockingPtr( volatile const SharedObject & object, - LockingPolicy & mutex ) - : pObject_( const_cast< const SharedObject * >( &object ) ), - pMutex_( &mutex ) - { - mutex.Lock(); - } - - /// Destructor unlocks the mutex. - ~ConstLockingPtr() - { - pMutex_->Unlock(); - } - - /// Star-operator dereferences pointer. - const SharedObject & operator * () - { - return *pObject_; - } - - /// Point-operator returns pointer to object. - const SharedObject * operator -> () - { - return pObject_; - } - - private: - - /// Default constructor is not implemented. - ConstLockingPtr(); - - /// Copy-constructor is not implemented. - ConstLockingPtr( const ConstLockingPtr & ); - - /// Copy-assignment-operator is not implemented. - ConstLockingPtr & operator = ( const ConstLockingPtr & ); - - /// Pointer to the shared object. - const SharedObject * pObject_; - - /// Pointer to the mutex. - LockingPolicy * pMutex_; - - }; // end class ConstLockingPtr -#endif - - } // namespace Loki #endif // end file guardian @@ -175,6 +99,9 @@ namespace Loki // $Log$ +// Revision 1.8 2006/01/30 20:33:01 syntheticpp +// use policies from SmartPtr.h, clean up +// // Revision 1.7 2006/01/22 13:37:33 syntheticpp // use macro LOKI_DEFAULT_MUTEX for Mutex default value, defined in Threads.h //