2006-01-16 19:05:09 +00:00
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// The Loki Library
|
|
|
|
|
// Copyright (c) 2001 by Andrei Alexandrescu
|
|
|
|
|
// This code accompanies the book:
|
|
|
|
|
// Alexandrescu, Andrei. "Modern C++ Design: Generic Programming and Design
|
|
|
|
|
// Patterns Applied". Copyright (c) 2001. Addison-Wesley.
|
|
|
|
|
// Permission to use, copy, modify, distribute and sell this software for any
|
|
|
|
|
// purpose is hereby granted without fee, provided that the above copyright
|
|
|
|
|
// notice appear in all copies and that both that copyright notice and this
|
|
|
|
|
// permission notice appear in supporting documentation.
|
|
|
|
|
// The author or Addison-Wesley Longman make no representations about the
|
|
|
|
|
// suitability of this software for any purpose. It is provided "as is"
|
|
|
|
|
// without express or implied warranty.
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2005-09-26 07:33:05 +00:00
|
|
|
|
#ifndef LOKI_THREADS_H_
|
|
|
|
|
#define LOKI_THREADS_H_
|
2002-08-11 05:49:45 +00:00
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2005-11-03 12:43:55 +00:00
|
|
|
|
|
2002-08-11 05:49:45 +00:00
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2005-07-28 14:26:10 +00:00
|
|
|
|
// $Header$
|
2005-07-28 14:04:07 +00:00
|
|
|
|
|
2005-11-03 12:43:55 +00:00
|
|
|
|
/// @defgroup ThreadingGroup Threading
|
|
|
|
|
/// Policies to for the threading model:
|
|
|
|
|
///
|
|
|
|
|
/// - SingleThreaded
|
|
|
|
|
/// - ObjectLevelLockable
|
|
|
|
|
/// - ClassLevelLockable
|
|
|
|
|
///
|
|
|
|
|
/// All classes in Loki have configurable threading model.
|
|
|
|
|
///
|
|
|
|
|
/// The macro LOKI_DEFAULT_THREADING selects the default
|
|
|
|
|
/// threading model for certain components of Loki
|
|
|
|
|
/// (it affects only default template arguments)
|
|
|
|
|
///
|
|
|
|
|
/// \par Usage:
|
|
|
|
|
///
|
|
|
|
|
/// To use a specific threading model define
|
|
|
|
|
///
|
|
|
|
|
/// - nothing, single-theading is default
|
|
|
|
|
/// - LOKI_OBJECT_LEVEL_THREADING for object-level-threading
|
|
|
|
|
/// - LOKI_CLASS_LEVEL_THREADING for class-level-threading
|
|
|
|
|
///
|
|
|
|
|
/// \par Supported platfroms:
|
|
|
|
|
///
|
|
|
|
|
/// - Windows (windows.h)
|
|
|
|
|
/// - POSIX (pthread.h)
|
|
|
|
|
|
|
|
|
|
|
2005-07-28 14:04:07 +00:00
|
|
|
|
|
2005-10-24 15:05:24 +00:00
|
|
|
|
#if defined(LOKI_CLASS_LEVEL_THREADING) || defined(LOKI_OBJECT_LEVEL_THREADING)
|
|
|
|
|
|
2005-09-26 07:33:05 +00:00
|
|
|
|
#define LOKI_DEFAULT_THREADING_NO_OBJ_LEVEL ::Loki::ClassLevelLockable
|
2005-10-24 15:05:24 +00:00
|
|
|
|
|
|
|
|
|
#if defined(LOKI_CLASS_LEVEL_THREADING) && !defined(LOKI_OBJECT_LEVEL_THREADING)
|
2005-09-26 07:33:05 +00:00
|
|
|
|
#define LOKI_DEFAULT_THREADING ::Loki::ClassLevelLockable
|
2005-07-28 14:13:46 +00:00
|
|
|
|
#else
|
2005-09-26 07:33:05 +00:00
|
|
|
|
#define LOKI_DEFAULT_THREADING ::Loki::ObjectLevelLockable
|
2005-07-28 14:13:46 +00:00
|
|
|
|
#endif
|
2005-10-24 15:05:24 +00:00
|
|
|
|
|
|
|
|
|
#if defined(_WIN32)
|
|
|
|
|
#include <windows.h>
|
|
|
|
|
#else
|
|
|
|
|
#include <pthread.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2005-07-28 14:04:07 +00:00
|
|
|
|
#else
|
2005-10-24 15:05:24 +00:00
|
|
|
|
|
2005-09-26 07:33:05 +00:00
|
|
|
|
#define LOKI_DEFAULT_THREADING ::Loki::SingleThreaded
|
2005-10-24 15:05:24 +00:00
|
|
|
|
#define LOKI_DEFAULT_THREADING_NO_OBJ_LEVEL ::Loki::SingleThreaded
|
|
|
|
|
|
2005-07-28 14:04:07 +00:00
|
|
|
|
#endif
|
2002-08-11 05:49:45 +00:00
|
|
|
|
|
2005-07-26 14:30:17 +00:00
|
|
|
|
#include <cassert>
|
|
|
|
|
|
2002-08-11 05:49:45 +00:00
|
|
|
|
namespace Loki
|
|
|
|
|
{
|
2005-11-03 12:43:55 +00:00
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
/// \class SingleThreaded
|
|
|
|
|
///
|
|
|
|
|
/// \ingroup ThreadingGroup
|
|
|
|
|
/// Implementation of the ThreadingModel policy used by various classes
|
|
|
|
|
/// Implements a single-threaded model; no synchronization
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2002-08-11 05:49:45 +00:00
|
|
|
|
template <class Host>
|
|
|
|
|
class SingleThreaded
|
|
|
|
|
{
|
|
|
|
|
public:
|
2005-11-03 12:43:55 +00:00
|
|
|
|
/// \struct Lock
|
|
|
|
|
/// Dummy Lock class
|
2002-08-11 05:49:45 +00:00
|
|
|
|
struct Lock
|
|
|
|
|
{
|
|
|
|
|
Lock() {}
|
2003-02-27 20:09:08 +00:00
|
|
|
|
explicit Lock(const SingleThreaded&) {}
|
2005-10-30 14:03:23 +00:00
|
|
|
|
explicit Lock(const SingleThreaded*) {}
|
2002-08-11 05:49:45 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
typedef Host VolatileType;
|
|
|
|
|
|
|
|
|
|
typedef int IntType;
|
|
|
|
|
|
|
|
|
|
static IntType AtomicAdd(volatile IntType& lval, IntType val)
|
|
|
|
|
{ return lval += val; }
|
|
|
|
|
|
|
|
|
|
static IntType AtomicSubtract(volatile IntType& lval, IntType val)
|
|
|
|
|
{ return lval -= val; }
|
|
|
|
|
|
|
|
|
|
static IntType AtomicMultiply(volatile IntType& lval, IntType val)
|
|
|
|
|
{ return lval *= val; }
|
|
|
|
|
|
|
|
|
|
static IntType AtomicDivide(volatile IntType& lval, IntType val)
|
|
|
|
|
{ return lval /= val; }
|
|
|
|
|
|
|
|
|
|
static IntType AtomicIncrement(volatile IntType& lval)
|
|
|
|
|
{ return ++lval; }
|
|
|
|
|
|
2002-08-15 02:49:29 +00:00
|
|
|
|
static IntType AtomicDecrement(volatile IntType& lval)
|
2002-11-07 18:53:47 +00:00
|
|
|
|
{ return --lval; }
|
2002-08-11 05:49:45 +00:00
|
|
|
|
|
|
|
|
|
static void AtomicAssign(volatile IntType & lval, IntType val)
|
|
|
|
|
{ lval = val; }
|
|
|
|
|
|
|
|
|
|
static void AtomicAssign(IntType & lval, volatile IntType & val)
|
|
|
|
|
{ lval = val; }
|
|
|
|
|
};
|
|
|
|
|
|
2005-07-28 14:04:07 +00:00
|
|
|
|
#if defined(_WINDOWS_) || defined(_WINDOWS_H)
|
2002-08-11 05:49:45 +00:00
|
|
|
|
|
2005-10-24 20:35:12 +00:00
|
|
|
|
#define LOKI_THREADS_MUTEX CRITICAL_SECTION
|
|
|
|
|
#define LOKI_THREADS_MUTEX_INIT ::InitializeCriticalSection
|
|
|
|
|
#define LOKI_THREADS_MUTEX_DELETE ::DeleteCriticalSection
|
|
|
|
|
#define LOKI_THREADS_MUTEX_LOCK ::EnterCriticalSection
|
|
|
|
|
#define LOKI_THREADS_MUTEX_UNLOCK ::LeaveCriticalSection
|
|
|
|
|
#define LOKI_THREADS_LONG LONG
|
2005-10-24 15:05:24 +00:00
|
|
|
|
|
|
|
|
|
#define LOKI_THREADS_ATOMIC_FUNCTIONS \
|
|
|
|
|
static IntType AtomicIncrement(volatile IntType& lval) \
|
|
|
|
|
{ return InterlockedIncrement(&const_cast<IntType&>(lval)); } \
|
|
|
|
|
\
|
|
|
|
|
static IntType AtomicDecrement(volatile IntType& lval) \
|
|
|
|
|
{ return InterlockedDecrement(&const_cast<IntType&>(lval)); } \
|
|
|
|
|
\
|
|
|
|
|
static void AtomicAssign(volatile IntType& lval, IntType val) \
|
|
|
|
|
{ InterlockedExchange(&const_cast<IntType&>(lval), val); } \
|
|
|
|
|
\
|
|
|
|
|
static void AtomicAssign(IntType& lval, volatile IntType& val) \
|
|
|
|
|
{ InterlockedExchange(&lval, val); }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#elif defined(_PTHREAD_H) //POSIX threads (pthread.h)
|
|
|
|
|
|
|
|
|
|
|
2005-10-24 20:35:12 +00:00
|
|
|
|
#define LOKI_THREADS_MUTEX pthread_mutex_t
|
|
|
|
|
#define LOKI_THREADS_MUTEX_INIT(x) ::pthread_mutex_init(x,0)
|
|
|
|
|
#define LOKI_THREADS_MUTEX_DELETE ::pthread_mutex_destroy
|
|
|
|
|
#define LOKI_THREADS_MUTEX_LOCK ::pthread_mutex_lock
|
|
|
|
|
#define LOKI_THREADS_MUTEX_UNLOCK ::pthread_mutex_unlock
|
|
|
|
|
#define LOKI_THREADS_LONG long
|
2005-10-24 15:05:24 +00:00
|
|
|
|
|
|
|
|
|
#define LOKI_THREADS_ATOMIC(x) \
|
|
|
|
|
pthread_mutex_lock(&atomic_mutex_); \
|
|
|
|
|
x; \
|
|
|
|
|
pthread_mutex_unlock(&atomic_mutex_)
|
|
|
|
|
|
|
|
|
|
#define LOKI_THREADS_ATOMIC_FUNCTIONS \
|
2005-10-30 14:03:23 +00:00
|
|
|
|
private: \
|
|
|
|
|
static pthread_mutex_t atomic_mutex_; \
|
|
|
|
|
public: \
|
2005-10-24 15:05:24 +00:00
|
|
|
|
static IntType AtomicIncrement(volatile IntType& lval) \
|
|
|
|
|
{ LOKI_THREADS_ATOMIC( lval++ ); return lval; } \
|
|
|
|
|
\
|
|
|
|
|
static IntType AtomicDecrement(volatile IntType& lval) \
|
|
|
|
|
{ LOKI_THREADS_ATOMIC(lval-- ); return lval; } \
|
|
|
|
|
\
|
|
|
|
|
static void AtomicAssign(volatile IntType& lval, IntType val) \
|
|
|
|
|
{ LOKI_THREADS_ATOMIC( lval = val ); } \
|
|
|
|
|
\
|
|
|
|
|
static void AtomicAssign(IntType& lval, volatile IntType& val) \
|
|
|
|
|
{ LOKI_THREADS_ATOMIC( lval = val ); }
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
2006-01-21 13:09:45 +00:00
|
|
|
|
#if defined(_WINDOWS_) || defined(_WINDOWS_H) || defined(_PTHREAD_H)
|
|
|
|
|
|
2006-01-21 01:02:12 +00:00
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
/// \class Mutex
|
|
|
|
|
//
|
|
|
|
|
/// \ingroup ThreadingGroup
|
|
|
|
|
/// A simple and portable Mutex. A default policy class for locking objects.
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
class Mutex
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
Mutex() { LOKI_THREADS_MUTEX_INIT ( &mtx_ ); }
|
|
|
|
|
~Mutex() { LOKI_THREADS_MUTEX_DELETE( &mtx_ ); }
|
|
|
|
|
void Lock() { LOKI_THREADS_MUTEX_LOCK ( &mtx_ ); }
|
|
|
|
|
void Unlock() { LOKI_THREADS_MUTEX_UNLOCK( &mtx_ ); }
|
|
|
|
|
private:
|
|
|
|
|
/// Copy-constructor not implemented.
|
|
|
|
|
Mutex( const Mutex & );
|
|
|
|
|
/// Copy-assignement operator not implemented.
|
|
|
|
|
Mutex & operator = ( const Mutex & );
|
|
|
|
|
LOKI_THREADS_MUTEX mtx_;
|
|
|
|
|
};
|
|
|
|
|
|
2005-10-24 15:05:24 +00:00
|
|
|
|
|
2005-07-31 14:00:48 +00:00
|
|
|
|
|
2005-11-03 12:43:55 +00:00
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
/// \class ObjectLevelLockable
|
|
|
|
|
///
|
|
|
|
|
/// \ingroup ThreadingGroup
|
|
|
|
|
/// Implementation of the ThreadingModel policy used by various classes
|
|
|
|
|
/// Implements a object-level locking scheme
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2006-01-21 01:02:12 +00:00
|
|
|
|
template < class Host, class MutexPolicy = Loki::Mutex >
|
2002-08-11 05:49:45 +00:00
|
|
|
|
class ObjectLevelLockable
|
|
|
|
|
{
|
2006-01-21 01:05:44 +00:00
|
|
|
|
mutable MutexPolicy mtx_;
|
2002-08-11 05:49:45 +00:00
|
|
|
|
|
|
|
|
|
public:
|
2006-01-21 01:02:12 +00:00
|
|
|
|
ObjectLevelLockable() : mtx_() {}
|
2002-08-11 05:49:45 +00:00
|
|
|
|
|
2006-01-21 01:02:12 +00:00
|
|
|
|
ObjectLevelLockable(const ObjectLevelLockable&) : mtx_() {}
|
|
|
|
|
|
|
|
|
|
~ObjectLevelLockable() {}
|
2002-08-11 05:49:45 +00:00
|
|
|
|
|
|
|
|
|
class Lock;
|
|
|
|
|
friend class Lock;
|
|
|
|
|
|
2005-11-03 12:43:55 +00:00
|
|
|
|
/// \struct Lock
|
|
|
|
|
/// Lock class to lock on object level
|
2002-08-11 05:49:45 +00:00
|
|
|
|
class Lock
|
2005-10-24 15:05:24 +00:00
|
|
|
|
{
|
2002-08-11 05:49:45 +00:00
|
|
|
|
public:
|
2005-11-03 12:43:55 +00:00
|
|
|
|
|
|
|
|
|
/// Lock object
|
2003-12-02 18:52:18 +00:00
|
|
|
|
explicit Lock(const ObjectLevelLockable& host) : host_(host)
|
2002-08-11 05:49:45 +00:00
|
|
|
|
{
|
2006-01-21 01:02:12 +00:00
|
|
|
|
host_.mtx_.Lock();
|
2002-08-11 05:49:45 +00:00
|
|
|
|
}
|
2003-02-27 20:09:08 +00:00
|
|
|
|
|
2005-11-03 12:43:55 +00:00
|
|
|
|
/// Lock object
|
2005-10-30 14:03:23 +00:00
|
|
|
|
explicit Lock(const ObjectLevelLockable* host) : host_(*host)
|
2005-10-24 20:35:12 +00:00
|
|
|
|
{
|
2006-01-21 01:02:12 +00:00
|
|
|
|
host_.mtx_.Lock();
|
2005-10-24 20:35:12 +00:00
|
|
|
|
}
|
2006-01-21 01:02:12 +00:00
|
|
|
|
|
2005-11-03 12:43:55 +00:00
|
|
|
|
/// Unlock object
|
2002-08-11 05:49:45 +00:00
|
|
|
|
~Lock()
|
|
|
|
|
{
|
2006-01-21 01:02:12 +00:00
|
|
|
|
host_.mtx_.Unlock();
|
2002-08-11 05:49:45 +00:00
|
|
|
|
}
|
2006-01-21 01:02:12 +00:00
|
|
|
|
|
2005-10-24 15:05:24 +00:00
|
|
|
|
private:
|
2005-11-03 12:43:55 +00:00
|
|
|
|
/// private by design of the object level threading
|
2005-10-30 14:03:23 +00:00
|
|
|
|
Lock();
|
2005-10-24 15:05:24 +00:00
|
|
|
|
Lock(const Lock&);
|
|
|
|
|
Lock& operator=(const Lock&);
|
2005-10-24 20:35:12 +00:00
|
|
|
|
const ObjectLevelLockable& host_;
|
2002-08-11 05:49:45 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
typedef volatile Host VolatileType;
|
|
|
|
|
|
2005-10-24 15:05:24 +00:00
|
|
|
|
typedef LOKI_THREADS_LONG IntType;
|
2002-08-11 05:49:45 +00:00
|
|
|
|
|
2005-10-24 15:05:24 +00:00
|
|
|
|
LOKI_THREADS_ATOMIC_FUNCTIONS
|
2002-08-11 05:49:45 +00:00
|
|
|
|
|
|
|
|
|
};
|
2005-10-24 20:35:12 +00:00
|
|
|
|
|
|
|
|
|
#if defined(_PTHREAD_H)
|
2006-01-21 14:11:09 +00:00
|
|
|
|
template <class Host, class MutexPolicy>
|
|
|
|
|
pthread_mutex_t ObjectLevelLockable<Host, MutexPolicy>::atomic_mutex_ = PTHREAD_MUTEX_INITIALIZER;
|
2005-10-24 20:35:12 +00:00
|
|
|
|
#endif
|
2002-08-11 05:49:45 +00:00
|
|
|
|
|
2005-11-03 12:43:55 +00:00
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
/// \class ClassLevelLockable
|
|
|
|
|
///
|
|
|
|
|
/// \ingroup ThreadingGroup
|
|
|
|
|
/// Implementation of the ThreadingModel policy used by various classes
|
|
|
|
|
/// Implements a class-level locking scheme
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2006-01-21 01:02:12 +00:00
|
|
|
|
template <class Host, class MutexPolicy = Loki::Mutex >
|
2002-08-11 05:49:45 +00:00
|
|
|
|
class ClassLevelLockable
|
|
|
|
|
{
|
|
|
|
|
struct Initializer
|
2003-02-27 20:09:08 +00:00
|
|
|
|
{
|
2005-07-26 15:11:48 +00:00
|
|
|
|
bool init_;
|
2006-01-21 01:05:44 +00:00
|
|
|
|
MutexPolicy mtx_;
|
2005-07-26 15:11:48 +00:00
|
|
|
|
|
2006-01-21 14:11:09 +00:00
|
|
|
|
Initializer() : init_(false), mtx_()
|
2002-08-11 05:49:45 +00:00
|
|
|
|
{
|
2005-10-24 15:05:24 +00:00
|
|
|
|
init_ = true;
|
2002-08-11 05:49:45 +00:00
|
|
|
|
}
|
|
|
|
|
~Initializer()
|
|
|
|
|
{
|
2005-07-27 16:32:20 +00:00
|
|
|
|
assert(init_);
|
2002-08-11 05:49:45 +00:00
|
|
|
|
}
|
|
|
|
|
};
|
2006-01-21 01:02:12 +00:00
|
|
|
|
|
2002-08-11 05:49:45 +00:00
|
|
|
|
static Initializer initializer_;
|
|
|
|
|
|
|
|
|
|
public:
|
2006-01-21 01:02:12 +00:00
|
|
|
|
|
2002-08-11 05:49:45 +00:00
|
|
|
|
class Lock;
|
|
|
|
|
friend class Lock;
|
2006-01-21 01:02:12 +00:00
|
|
|
|
|
2005-11-03 12:43:55 +00:00
|
|
|
|
/// \struct Lock
|
|
|
|
|
/// Lock class to lock on class level
|
2002-08-11 05:49:45 +00:00
|
|
|
|
class Lock
|
2005-10-24 15:05:24 +00:00
|
|
|
|
{
|
2002-08-11 05:49:45 +00:00
|
|
|
|
public:
|
2005-11-03 12:43:55 +00:00
|
|
|
|
|
|
|
|
|
/// Lock class
|
2002-08-11 05:49:45 +00:00
|
|
|
|
Lock()
|
|
|
|
|
{
|
2005-07-27 16:32:20 +00:00
|
|
|
|
assert(initializer_.init_);
|
2006-01-21 01:02:12 +00:00
|
|
|
|
initializer_.mtx_.Lock();
|
2002-08-11 05:49:45 +00:00
|
|
|
|
}
|
2006-01-21 01:02:12 +00:00
|
|
|
|
|
2005-11-03 12:43:55 +00:00
|
|
|
|
/// Lock class
|
2003-12-02 18:52:18 +00:00
|
|
|
|
explicit Lock(const ClassLevelLockable&)
|
2002-08-11 05:49:45 +00:00
|
|
|
|
{
|
2005-07-27 16:32:20 +00:00
|
|
|
|
assert(initializer_.init_);
|
2006-01-21 01:02:12 +00:00
|
|
|
|
initializer_.mtx_.Lock();
|
2002-08-11 05:49:45 +00:00
|
|
|
|
}
|
2006-01-21 01:02:12 +00:00
|
|
|
|
|
2005-11-03 12:43:55 +00:00
|
|
|
|
/// Lock class
|
2005-10-30 14:03:23 +00:00
|
|
|
|
explicit Lock(const ClassLevelLockable*)
|
2005-10-24 20:35:12 +00:00
|
|
|
|
{
|
|
|
|
|
assert(initializer_.init_);
|
2006-01-21 01:02:12 +00:00
|
|
|
|
initializer_.mtx_.Lock();
|
2005-10-24 20:35:12 +00:00
|
|
|
|
}
|
2006-01-21 01:02:12 +00:00
|
|
|
|
|
2005-11-03 12:43:55 +00:00
|
|
|
|
/// Unlock class
|
2002-08-11 05:49:45 +00:00
|
|
|
|
~Lock()
|
|
|
|
|
{
|
2005-07-27 16:32:20 +00:00
|
|
|
|
assert(initializer_.init_);
|
2006-01-21 01:02:12 +00:00
|
|
|
|
initializer_.mtx_.Unlock();
|
2002-08-11 05:49:45 +00:00
|
|
|
|
}
|
2006-01-21 01:02:12 +00:00
|
|
|
|
|
2005-10-24 15:05:24 +00:00
|
|
|
|
private:
|
|
|
|
|
Lock(const Lock&);
|
|
|
|
|
Lock& operator=(const Lock&);
|
2002-08-11 05:49:45 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
typedef volatile Host VolatileType;
|
|
|
|
|
|
2005-10-24 15:05:24 +00:00
|
|
|
|
typedef LOKI_THREADS_LONG IntType;
|
2002-08-11 05:49:45 +00:00
|
|
|
|
|
2005-10-24 15:05:24 +00:00
|
|
|
|
LOKI_THREADS_ATOMIC_FUNCTIONS
|
2002-08-11 05:49:45 +00:00
|
|
|
|
|
|
|
|
|
};
|
2005-10-24 15:05:24 +00:00
|
|
|
|
|
2005-10-24 20:35:12 +00:00
|
|
|
|
#if defined(_PTHREAD_H)
|
2006-01-21 14:11:09 +00:00
|
|
|
|
template <class Host, class MutexPolicy>
|
|
|
|
|
pthread_mutex_t ClassLevelLockable<Host, MutexPolicy>::atomic_mutex_ = PTHREAD_MUTEX_INITIALIZER;
|
2005-10-24 20:35:12 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2006-01-21 01:02:12 +00:00
|
|
|
|
template < class Host, class MutexPolicy >
|
|
|
|
|
typename ClassLevelLockable< Host, MutexPolicy >::Initializer
|
|
|
|
|
ClassLevelLockable< Host, MutexPolicy >::initializer_;
|
2005-10-24 15:05:24 +00:00
|
|
|
|
|
|
|
|
|
#endif // defined(_WINDOWS_) || defined(_WINDOWS_H) || defined(_PTHREAD_H)
|
|
|
|
|
|
|
|
|
|
} // namespace Loki
|
|
|
|
|
|
|
|
|
|
|
2002-08-11 05:49:45 +00:00
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Change log:
|
|
|
|
|
// June 20, 2001: ported by Nick Thurn to gcc 2.95.3. Kudos, Nick!!!
|
2005-07-26 14:30:17 +00:00
|
|
|
|
// July 26, 2005: some asserts by Peter K<>mmel
|
2002-08-11 05:49:45 +00:00
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2005-07-28 14:04:07 +00:00
|
|
|
|
|
2002-08-11 05:49:45 +00:00
|
|
|
|
#endif
|
2005-07-27 17:33:50 +00:00
|
|
|
|
|
2005-07-28 14:26:10 +00:00
|
|
|
|
// $Log$
|
2006-01-21 14:11:09 +00:00
|
|
|
|
// Revision 1.24 2006/01/21 14:11:09 syntheticpp
|
|
|
|
|
// complete usage of Loki::Mutex, gcc can't compile without these corrections
|
|
|
|
|
//
|
2006-01-21 13:09:45 +00:00
|
|
|
|
// Revision 1.23 2006/01/21 13:09:45 syntheticpp
|
|
|
|
|
// don't compile Mutex when multi threading is disabled
|
|
|
|
|
//
|
2006-01-21 01:05:44 +00:00
|
|
|
|
// Revision 1.22 2006/01/21 01:05:44 rich_sposato
|
|
|
|
|
// Removed volatile keyword from 2 data members.
|
|
|
|
|
//
|
2006-01-21 01:02:12 +00:00
|
|
|
|
// Revision 1.21 2006/01/21 01:02:12 rich_sposato
|
|
|
|
|
// Added Mutex class to Loki. Made it the default policy class for locking.
|
|
|
|
|
//
|
2006-01-16 19:05:09 +00:00
|
|
|
|
// Revision 1.20 2006/01/16 19:05:09 rich_sposato
|
|
|
|
|
// Added cvs keywords.
|
|
|
|
|
//
|
2005-11-15 11:08:57 +00:00
|
|
|
|
// Revision 1.19 2005/11/15 11:08:57 syntheticpp
|
|
|
|
|
// also compile with the original gnu pthread.h
|
|
|
|
|
//
|
2005-11-03 12:43:55 +00:00
|
|
|
|
// Revision 1.18 2005/11/03 12:43:35 syntheticpp
|
|
|
|
|
// more doxygen documentation, modules added
|
|
|
|
|
//
|
2005-11-02 20:01:11 +00:00
|
|
|
|
// Revision 1.17 2005/11/02 20:01:10 syntheticpp
|
|
|
|
|
// more doxygen documentation, modules added
|
|
|
|
|
//
|
2005-10-30 14:03:23 +00:00
|
|
|
|
// Revision 1.16 2005/10/30 14:03:23 syntheticpp
|
|
|
|
|
// replace tabs space
|
|
|
|
|
//
|
2005-10-24 20:35:12 +00:00
|
|
|
|
// Revision 1.15 2005/10/24 20:35:12 syntheticpp
|
|
|
|
|
// small changes for Threads; add compile test for Threads.h
|
|
|
|
|
//
|
2005-10-24 15:05:24 +00:00
|
|
|
|
// Revision 1.14 2005/10/24 15:05:24 syntheticpp
|
|
|
|
|
// adding support for POSIX threads (pthreads.h), Thanks to Ilya Volvovski
|
|
|
|
|
//
|
2005-09-26 07:33:05 +00:00
|
|
|
|
// Revision 1.13 2005/09/26 07:33:04 syntheticpp
|
|
|
|
|
// move macros into LOKI_ namespace
|
|
|
|
|
//
|
2005-07-31 14:00:48 +00:00
|
|
|
|
// Revision 1.12 2005/07/31 14:00:48 syntheticpp
|
|
|
|
|
// make object level threading possible
|
|
|
|
|
//
|
2005-07-28 14:26:10 +00:00
|
|
|
|
// Revision 1.11 2005/07/28 14:26:09 syntheticpp
|
|
|
|
|
// add cvs Header/Log
|
|
|
|
|
//
|
2005-07-28 14:13:46 +00:00
|
|
|
|
|