Update of /cvsroot/pclasses/pclasses2/include/pclasses
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9449/include/pclasses
Modified Files:
AtomicTraits.h
Log Message:
Moved AtomicTraits<Type>::Mutex to AtomicMutex
Index: AtomicTraits.h
===================================================================
RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/AtomicTraits.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- AtomicTraits.h 23 Apr 2005 10:54:45 -0000 1.4
+++ AtomicTraits.h 23 Apr 2005 11:59:08 -0000 1.5
@@ -27,6 +27,34 @@
namespace Traits {
+//! AtomicMutex
+/*!
+ The AtomicMutex class is used by the default implementation of
+ AtomicTraits<> to provide atomicity for types that dont have a
+ AtomicTraits specialisation.
+*/
+class PCORE_EXPORT AtomicMutex {
+ public:
+ AtomicMutex();
+ ~AtomicMutex();
+
+ void lock() throw();
+ void unlock() throw();
+
+ class ScopedLock {
+ public:
+ ScopedLock(AtomicMutex& mtx);
+ ~ScopedLock();
+
+ private:
+ AtomicMutex& _mtx;
+ };
+
+ private:
+ unsigned long _handle;
+};
+
+
//! Atomic traits
/*!
The AtomicTraits template supplies the actual implementation for the
@@ -38,77 +66,49 @@
template <class Type>
struct AtomicTraits {
- //! AtomicTraits Mutex
- /*!
- The Mutex class is used by the default implementation of
- AtomicTraits<> to provide atomicity for types that dont have a
- AtomicTraits specialisation.
- */
- class Mutex {
- public:
- Mutex();
- ~Mutex();
-
- void lock() throw();
- void unlock() throw();
-
- class ScopedLock {
- public:
- ScopedLock(Mutex& mtx);
- ~ScopedLock();
-
- private:
- Mutex& _mtx;
- };
-
- private:
- unsigned long _handle;
- };
-
struct AtomicType {
Type value;
- Mutex lock;
+ AtomicMutex lock;
};
static void set(AtomicType* atomic, const Type& val) throw()
{
- Mutex::ScopedLock lck(atomic->lock);
+ AtomicMutex::ScopedLock lck(atomic->lock);
atomic->value = val;
}
static Type get(const AtomicType* atomic) throw()
{
- Mutex::ScopedLock lck(atomic->lock);
+ AtomicMutex::ScopedLock lck(atomic->lock);
return atomic->value;
}
static void inc(AtomicType* val) throw()
{
- Mutex::ScopedLock lck(val->lock);
+ AtomicMutex::ScopedLock lck(val->lock);
++val->value;
}
static bool incAndTest(AtomicType* val) throw()
{
- Mutex::ScopedLock lck(val->lock);
+ AtomicMutex::ScopedLock lck(val->lock);
return !(++val->value);
}
static void dec(AtomicType* val) throw()
{
- Mutex::ScopedLock lck(val->lock);
+ AtomicMutex::ScopedLock lck(val->lock);
--val->value;
}
static bool decAndTest(AtomicType* val) throw()
{
- Mutex::ScopedLock lck(val->lock);
+ AtomicMutex::ScopedLock lck(val->lock);
return !(--val->value);
}
};
-//@todo this comes from pclasses-config.h
-//#ifdef PCLASSES_HAVE_ATOMIC_INT
+#ifdef PCLASSES_HAVE_ATOMIC_INT
//! Atomic integer type-traits
template <>
struct PCORE_EXPORT AtomicTraits<int> {
@@ -123,7 +123,7 @@
static void dec(int* atomic) throw();
static bool decAndTest(int* atomic) throw();
};
-//#endif
+#endif
} // !namespace Traits
|