aboutsummaryrefslogtreecommitdiff
path: root/src/framework/Policies/ThreadingModel.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/framework/Policies/ThreadingModel.h')
-rw-r--r--src/framework/Policies/ThreadingModel.h23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/framework/Policies/ThreadingModel.h b/src/framework/Policies/ThreadingModel.h
index 3e0593789b5..a380fe78323 100644
--- a/src/framework/Policies/ThreadingModel.h
+++ b/src/framework/Policies/ThreadingModel.h
@@ -17,16 +17,21 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+
#ifndef TRINITY_THREADINGMODEL_H
#define TRINITY_THREADINGMODEL_H
+
/**
* @class ThreadingModel<T>
*
*/
+
#include "Platform/Define.h"
+
namespace Trinity
{
inline void Guard(void *) {}
+
template<typename MUTEX> class TRINITY_DLL_DECL GeneralLock
{
public:
@@ -34,6 +39,7 @@ namespace Trinity
{
i_mutex.acquire();
}
+
~GeneralLock()
{
i_mutex.release();
@@ -43,10 +49,12 @@ namespace Trinity
GeneralLock& operator=(const GeneralLock &);
MUTEX &i_mutex;
};
+
template <class T>
class TRINITY_DLL_DECL SingleThreaded
{
public:
+
struct Lock // empty object
{
Lock() {}
@@ -55,31 +63,40 @@ namespace Trinity
{
}
};
+
typedef T VolatileType;
};
+
// object level lockable
template<class T, class MUTEX>
class TRINITY_DLL_DECL ObjectLevelLockable
{
public:
ObjectLevelLockable() : i_mtx() {}
+
friend class Lock;
+
class Lock
{
public:
Lock(ObjectLevelLockable<T, MUTEX> &host) : i_lock(host.i_mtx)
{
}
+
private:
GeneralLock<MUTEX> i_lock;
};
+
typedef volatile T VolatileType;
+
private:
// prevent the compiler creating a copy construct
ObjectLevelLockable(const ObjectLevelLockable<T, MUTEX> &);
ObjectLevelLockable<T, MUTEX>& operator=(const ObjectLevelLockable<T, MUTEX> &);
+
MUTEX i_mtx;
};
+
template<class T, class MUTEX>
class TRINITY_DLL_DECL ClassLevelLockable
{
@@ -87,7 +104,9 @@ namespace Trinity
class Lock;
friend class Lock;
typedef volatile T VolatileType;
+
ClassLevelLockable() {}
+
class Lock
{
public:
@@ -96,11 +115,15 @@ namespace Trinity
Lock() { ClassLevelLockable<T, MUTEX>::si_mtx.acquire(); }
~Lock() { ClassLevelLockable<T, MUTEX>::si_mtx.release(); }
};
+
private:
static MUTEX si_mtx;
};
+
}
+
template<class T, class MUTEX> MUTEX Trinity::ClassLevelLockable<T, MUTEX>::si_mtx;
+
#define INSTANTIATE_CLASS_MUTEX(CTYPE,MUTEX) \
template class TRINITY_DLL_DECL Trinity::ClassLevelLockable<CTYPE, MUTEX >
#endif