aboutsummaryrefslogtreecommitdiff
path: root/src/server/shared
diff options
context:
space:
mode:
authorMachiavelli <none@none>2010-06-25 00:18:01 +0200
committerMachiavelli <none@none>2010-06-25 00:18:01 +0200
commit0f7657b68c8b6444fadb480cdd0f87631391afa5 (patch)
treea5ffdaecbb1332ffbc655916842a23a622340c98 /src/server/shared
parenta6b9e716a61334e218cff227f66b0c51053e72f3 (diff)
Get rid of Trinity Singleton and Threading patterns and replace them with ACE_Singletons and ACE_GUARD_x macro´s with ACE_Thread_Mutex´es respectively.
Also get rid of unused CountedReference class that used Trinity threading pattern. --HG-- branch : trunk
Diffstat (limited to 'src/server/shared')
-rw-r--r--src/server/shared/CMakeLists.txt2
-rw-r--r--src/server/shared/Configuration/Config.cpp3
-rw-r--r--src/server/shared/Configuration/Config.h7
-rw-r--r--src/server/shared/Database/Database.cpp1
-rw-r--r--src/server/shared/Database/Database.h1
-rw-r--r--src/server/shared/Debugging/MemoryLeaks.cpp3
-rw-r--r--src/server/shared/Debugging/MemoryLeaks.h5
-rw-r--r--src/server/shared/Dynamic/CountedReference/Reference.h100
-rw-r--r--src/server/shared/Dynamic/CountedReference/ReferenceHolder.h42
-rw-r--r--src/server/shared/Dynamic/CountedReference/ReferenceImpl.h133
-rw-r--r--src/server/shared/Dynamic/FactoryHolder.h8
-rw-r--r--src/server/shared/Dynamic/ObjectRegistry.h10
-rw-r--r--src/server/shared/Logging/Log.cpp3
-rw-r--r--src/server/shared/Logging/Log.h10
-rw-r--r--src/server/shared/Policies/CreationPolicy.h110
-rw-r--r--src/server/shared/Policies/ObjectLifeTime.cpp36
-rw-r--r--src/server/shared/Policies/ObjectLifeTime.h53
-rw-r--r--src/server/shared/Policies/Singleton.h65
-rw-r--r--src/server/shared/Policies/SingletonImp.h93
-rw-r--r--src/server/shared/Policies/ThreadingModel.h130
20 files changed, 20 insertions, 795 deletions
diff --git a/src/server/shared/CMakeLists.txt b/src/server/shared/CMakeLists.txt
index 04fbfbea60f..0fd58e63588 100644
--- a/src/server/shared/CMakeLists.txt
+++ b/src/server/shared/CMakeLists.txt
@@ -12,7 +12,6 @@
set(shared_STAT_SRCS
Logging/Log.cpp
- Policies/ObjectLifeTime.cpp
Threading/DelayExecutor.cpp
Threading/Threading.cpp
Utilities/ProgressBar.cpp
@@ -37,7 +36,6 @@ include_directories(
${CMAKE_SOURCE_DIR}/src/server/shared/Dynamic
${CMAKE_SOURCE_DIR}/src/server/shared/Logging
${CMAKE_SOURCE_DIR}/src/server/shared/Packets
- ${CMAKE_SOURCE_DIR}/src/server/shared/Policies
${CMAKE_SOURCE_DIR}/src/server/shared/Threading
${CMAKE_SOURCE_DIR}/src/server/shared/Utilities
${MYSQL_INCLUDE_DIR}
diff --git a/src/server/shared/Configuration/Config.cpp b/src/server/shared/Configuration/Config.cpp
index 39830104a7c..3979cbc36aa 100644
--- a/src/server/shared/Configuration/Config.cpp
+++ b/src/server/shared/Configuration/Config.cpp
@@ -19,9 +19,6 @@
*/
#include "ConfigEnv.h"
-#include "Policies/SingletonImp.h"
-
-INSTANTIATE_SINGLETON_1(Config);
Config::Config() : mIgnoreCase(true), mConf(NULL)
{
diff --git a/src/server/shared/Configuration/Config.h b/src/server/shared/Configuration/Config.h
index bfcb324ee62..50cd4609b25 100644
--- a/src/server/shared/Configuration/Config.h
+++ b/src/server/shared/Configuration/Config.h
@@ -21,15 +21,16 @@
#ifndef CONFIG_H
#define CONFIG_H
-#include <Policies/Singleton.h>
+#include <ace/Singleton.h>
#include "Define.h"
class DOTCONFDocument;
class Config
{
+ friend class ACE_Singleton<Config, ACE_Null_Mutex>;
+ Config();
public:
- Config();
~Config();
bool SetSource(const char *file, bool ignorecase = true);
@@ -47,7 +48,7 @@ class Config
DOTCONFDocument *mConf;
};
-#define sConfig Trinity::Singleton<Config>::Instance()
+#define sConfig (*ACE_Singleton<Config, ACE_Null_Mutex>::instance())
#endif
diff --git a/src/server/shared/Database/Database.cpp b/src/server/shared/Database/Database.cpp
index 2dd2f9bbda4..1fb2f831a9f 100644
--- a/src/server/shared/Database/Database.cpp
+++ b/src/server/shared/Database/Database.cpp
@@ -25,7 +25,6 @@
#include "Updates/UpdateFields.h"
#include "Utilities/Util.h"
-#include "Policies/SingletonImp.h"
#include "Define.h"
#include "Threading/Threading.h"
#include "Database/SqlDelayThread.h"
diff --git a/src/server/shared/Database/Database.h b/src/server/shared/Database/Database.h
index 655479c85fe..762abfd2ede 100644
--- a/src/server/shared/Database/Database.h
+++ b/src/server/shared/Database/Database.h
@@ -24,7 +24,6 @@
#include "Threading/Threading.h"
#include "Dynamic/UnorderedMap.h"
#include "Database/SqlDelayThread.h"
-#include "Policies/Singleton.h"
#include "ace/Thread_Mutex.h"
#include "ace/Guard_T.h"
diff --git a/src/server/shared/Debugging/MemoryLeaks.cpp b/src/server/shared/Debugging/MemoryLeaks.cpp
index ef7e36c3b57..c591dabb866 100644
--- a/src/server/shared/Debugging/MemoryLeaks.cpp
+++ b/src/server/shared/Debugging/MemoryLeaks.cpp
@@ -17,9 +17,6 @@
*/
#include "MemoryLeaks.h"
-#include "Policies/SingletonImp.h"
-
-INSTANTIATE_SINGLETON_1( MemoryManager ) ;
MemoryManager::MemoryManager( )
{
diff --git a/src/server/shared/Debugging/MemoryLeaks.h b/src/server/shared/Debugging/MemoryLeaks.h
index bc722f241bd..4b13e4d3d90 100644
--- a/src/server/shared/Debugging/MemoryLeaks.h
+++ b/src/server/shared/Debugging/MemoryLeaks.h
@@ -39,10 +39,11 @@
#endif
-#include "Policies/Singleton.h"
+#include "ace/Singleton.h"
-struct MemoryManager : public Trinity::Singleton < MemoryManager >
+struct MemoryManager
{
MemoryManager();
};
+#define sMemoryManager ACE_Singleton<MemoryManager, ACE_Null_Mutex>::instance()
#endif
diff --git a/src/server/shared/Dynamic/CountedReference/Reference.h b/src/server/shared/Dynamic/CountedReference/Reference.h
deleted file mode 100644
index bdc06a572c9..00000000000
--- a/src/server/shared/Dynamic/CountedReference/Reference.h
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
- *
- * Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * 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_REFERENCE_H
-#define TRINITY_REFERENCE_H
-
-/**
- * Referencer<T>
- * Referencer is an object that holds a reference holder that hold a reference
- * counted object. When an object's reference count drop to zero, it removes
- * the object. This is a non intrusive mechanism and any object at any point
- * in time can be referenced. When and object is reference counted, do not
- * pass the object directly to other methods but rather, pass its
- * reference around. Objects can be reference counted in both single threaded
- * model and multi-threaded model
- */
-
-#include <stdexcept>
-#include "Define.h"
-#include "ThreadingModel.h"
-#include "ReferenceHolder.h"
-
-template
-<
-typename T,
-class THREADING_MODEL = Trinity::SingleThreaded<T>
->
-class Referencer
-{
- typedef typename THREADING_MODEL::Lock Lock;
- typedef ReferenceHolder<T, THREADING_MODEL> ReferenceeHolder;
- public:
-
- /// Constructs a referencer.
- Referencer(T *ref = NULL);
-
- /// Copy constructor
- Referencer(const Referencer &obj) : i_holder(NULL) { *this = obj; }
-
- /// Destructor
- ~Referencer();
-
- /// Referencee accessor
- T* referencee(void) { return (i_holder == NULL ? NULL : i_holder->i_referencee); }
- const T* referencee(void) const { return (i_holder == NULL ? NULL : i_holder->i_referencee); }
-
- //T& referencee(void){ return _referencee(); }
- //const T& referencee(void) const { return const_cast<Referencer *>(this)->_referencee(); }
- operator T&(void) { return _referencee(); }
- operator const T&(void) const { return *const_cast<Referencer *>(this)->_referencee(); }
-
- /// cast operators
- T* operator*() { return (i_holder == NULL ? NULL : i_holder->i_referencee); }
- T const * operator*() const { return (i_holder == NULL ? NULL : i_holder->i_referencee); }
-
- /// overload operators
- T* operator->() { return (i_holder == NULL ? NULL : i_holder->i_referencee); }
- const T * operator->() const { return (i_holder == NULL ? NULL : i_holder->i_referencee); }
-
- /// operator =
- Referencer& operator=(const Referencer &obj);
- Referencer& operator=(T *);
-
- /// returns true if i_referencee is null
- bool isNull(void) const { return i_holder == NULL; }
-
- private:
-
- T& _referencee(void)
- {
- if( i_holder == NULL )
- throw std::runtime_error("Invalid access to null pointer");
- return *i_holder->i_referencee;
- }
-
- void deReference(ReferenceeHolder *);
- void addReference(ReferenceeHolder *);
-
- // private data
- ReferenceeHolder *i_holder;
-};
-#endif
-
diff --git a/src/server/shared/Dynamic/CountedReference/ReferenceHolder.h b/src/server/shared/Dynamic/CountedReference/ReferenceHolder.h
deleted file mode 100644
index 597e9854be0..00000000000
--- a/src/server/shared/Dynamic/CountedReference/ReferenceHolder.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
- *
- * Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * 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_REFERENCEHOLDER_H
-#define TRINITY_REFERENCEHOLDER_H
-
-/** ReferenceHolder holds the actualy referenced obejct as well the refence
- count. The ReferenecHolder implements as a policy base object and
- will decided by the Reference class to be consnsitent.
- */
-
-template
-<
-typename T,
-class THREADING_MODEL
->
-struct ReferenceHolder : public THREADING_MODEL
-{
- explicit ReferenceHolder(T *ref) : i_referencee(ref), i_referenceCount(0) {}
- T *i_referencee;
- unsigned int i_referenceCount;
- typedef typename THREADING_MODEL::Lock Lock;
-};
-#endif
-
diff --git a/src/server/shared/Dynamic/CountedReference/ReferenceImpl.h b/src/server/shared/Dynamic/CountedReference/ReferenceImpl.h
deleted file mode 100644
index cde330179e3..00000000000
--- a/src/server/shared/Dynamic/CountedReference/ReferenceImpl.h
+++ /dev/null
@@ -1,133 +0,0 @@
-/*
- * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
- *
- * Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * 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_REFERENCEIMPL_H
-#define TRINITY_REFERENCEIMPL_H
-
-#include "Reference.h"
-
-template
-<
-typename T,
-class THREADING_MODEL
->
-Referencer<T, THREADING_MODEL>::Referencer(T *ref)
-: i_holder(NULL)
-{
- if( ref != NULL )
- {
- i_holder = new ReferenceeHolder(ref);
- ++i_holder->i_referenceCount;
- }
-}
-
-template
-<
-typename T,
-class THREADING_MODEL
->
-Referencer<T, THREADING_MODEL>::~Referencer()
-{
- if( i_holder != NULL )
- deReference(i_holder);
- i_holder = NULL;
-}
-
-template
-<
-typename T,
-class THREADING_MODEL
->
-Referencer<T, THREADING_MODEL>&
-Referencer<T, THREADING_MODEL>::operator=(const Referencer<T, THREADING_MODEL> &obj)
-{
- if( i_holder != NULL )
- deReference(i_holder);
- if( obj.i_holder != NULL )
- addReference(obj.i_holder);
- i_holder = obj.i_holder;
- return *this;
-}
-
-template
-<
-typename T,
-class THREADING_MODEL
->
-Referencer<T, THREADING_MODEL>&
-Referencer<T, THREADING_MODEL>::operator=(T *ref)
-{
- if( i_holder != NULL )
- deReference(i_holder);
- i_holder = NULL;
- if( ref != NULL )
- {
- i_holder = new ReferenceeHolder(ref);
- ++i_holder->i_referenceCount;
- }
-
- return *this;
-}
-
-template
-<
-typename T,
-class THREADING_MODEL
->
-void
-Referencer<T, THREADING_MODEL>::deReference(ReferenceHolder<T, THREADING_MODEL> *holder)
-{
- assert( holder != NULL && holder->i_referenceCount > 0);
- bool delete_object = false;
-
- {
- // The guard is within the scope due to the guard
- // must release earlier than expected.
- Lock guard(*holder);
- Guard(&guard);
-
- --holder->i_referenceCount;
- if( holder->i_referenceCount == 0 )
- delete_object = true;
- }
-
- if( delete_object )
- {
- delete holder->i_referencee;
- delete holder;
- }
-}
-
-template
-<
-typename T,
-class THREADING_MODEL
->
-void
-Referencer<T, THREADING_MODEL>::addReference(ReferenceHolder<T, THREADING_MODEL> *holder)
-{
- assert( i_holder != NULL );
- Lock guard(*holder);
- Guard(&guard);
-
- ++holder->i_referenceCount;
-}
-#endif
-
diff --git a/src/server/shared/Dynamic/FactoryHolder.h b/src/server/shared/Dynamic/FactoryHolder.h
index fd5925f5f75..096bdad1783 100644
--- a/src/server/shared/Dynamic/FactoryHolder.h
+++ b/src/server/shared/Dynamic/FactoryHolder.h
@@ -24,7 +24,6 @@
#include "Define.h"
#include "Dynamic/TypeList.h"
#include "ObjectRegistry.h"
-#include "Policies/SingletonImp.h"
/** FactoryHolder holds a factory object of a specific type
*/
@@ -33,14 +32,15 @@ class FactoryHolder
{
public:
typedef ObjectRegistry<FactoryHolder<T, Key >, Key > FactoryHolderRegistry;
- typedef Trinity::Singleton<FactoryHolderRegistry > FactoryHolderRepository;
+ friend class ACE_Singleton<FactoryHolderRegistry, ACE_Null_Mutex>;
+ typedef ACE_Singleton<FactoryHolderRegistry, ACE_Null_Mutex> FactoryHolderRepository;
FactoryHolder(Key k) : i_key(k) {}
virtual ~FactoryHolder() {}
inline Key key() const { return i_key; }
- void RegisterSelf(void) { FactoryHolderRepository::Instance().InsertItem(this, i_key); }
- void DeregisterSelf(void) { FactoryHolderRepository::Instance().RemoveItem(this, false); }
+ void RegisterSelf(void) { FactoryHolderRepository::instance()->InsertItem(this, i_key); }
+ void DeregisterSelf(void) { FactoryHolderRepository::instance()->RemoveItem(this, false); }
/// Abstract Factory create method
virtual T* Create(void *data = NULL) const = 0;
diff --git a/src/server/shared/Dynamic/ObjectRegistry.h b/src/server/shared/Dynamic/ObjectRegistry.h
index eaf8e1acd2d..11052a9f0a7 100644
--- a/src/server/shared/Dynamic/ObjectRegistry.h
+++ b/src/server/shared/Dynamic/ObjectRegistry.h
@@ -23,7 +23,7 @@
#include "Define.h"
#include "Dynamic/UnorderedMap.h"
-#include "Policies/Singleton.h"
+#include "ace/Singleton.h"
#include <string>
#include <vector>
@@ -94,11 +94,6 @@ class ObjectRegistry
return i_registeredObjects;
}
- private:
- RegistryMapType i_registeredObjects;
- friend class Trinity::OperatorNew<ObjectRegistry<T, Key> >;
-
- // protected for friend use since it should be a singleton
ObjectRegistry() {}
~ObjectRegistry()
{
@@ -106,6 +101,9 @@ class ObjectRegistry
delete iter->second;
i_registeredObjects.clear();
}
+ private:
+ RegistryMapType i_registeredObjects;
+
};
#endif
diff --git a/src/server/shared/Logging/Log.cpp b/src/server/shared/Logging/Log.cpp
index 0f27400dce2..7a34eaa0c0d 100644
--- a/src/server/shared/Logging/Log.cpp
+++ b/src/server/shared/Logging/Log.cpp
@@ -20,15 +20,12 @@
#include "Common.h"
#include "Log.h"
-#include "Policies/SingletonImp.h"
#include "Configuration/ConfigEnv.h"
#include "Util.h"
#include <stdarg.h>
#include <stdio.h>
-INSTANTIATE_SINGLETON_1( Log );
-
Log::Log() :
raLogfile(NULL), logfile(NULL), gmLogfile(NULL), charLogfile(NULL),
dberLogfile(NULL), chatLogfile(NULL), m_gmlog_per_account(false),
diff --git a/src/server/shared/Logging/Log.h b/src/server/shared/Logging/Log.h
index 53ce4e601b5..fb584d42c27 100644
--- a/src/server/shared/Logging/Log.h
+++ b/src/server/shared/Logging/Log.h
@@ -22,7 +22,7 @@
#define TRINITYCORE_LOG_H
#include "Common.h"
-#include "Policies/Singleton.h"
+#include <ace/Singleton.h>
#include "Database/DatabaseEnv.h"
class Config;
@@ -82,9 +82,9 @@ enum ColorTypes
const int Colors = int(WHITE)+1;
-class Log : public Trinity::Singleton<Log, Trinity::ClassLevelLockable<Log, ACE_Thread_Mutex> >
+class Log
{
- friend class Trinity::OperatorNew<Log>;
+ friend class ACE_Singleton<Log, ACE_Thread_Mutex>;
Log();
~Log();
@@ -172,10 +172,10 @@ class Log : public Trinity::Singleton<Log, Trinity::ClassLevelLockable<Log, ACE_
std::string m_dumpsDir;
};
-#define sLog Trinity::Singleton<Log>::Instance()
+#define sLog (*ACE_Singleton<Log, ACE_Thread_Mutex>::instance())
#ifdef TRINITY_DEBUG
-#define DEBUG_LOG Trinity::Singleton<Log>::Instance().outDebug
+#define DEBUG_LOG sLog.outDebug
#else
#define DEBUG_LOG
#endif
diff --git a/src/server/shared/Policies/CreationPolicy.h b/src/server/shared/Policies/CreationPolicy.h
deleted file mode 100644
index cc38d704e99..00000000000
--- a/src/server/shared/Policies/CreationPolicy.h
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
- *
- * Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * 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_CREATIONPOLICY_H
-#define TRINITY_CREATIONPOLICY_H
-
-#include <stdlib.h>
-#include "Define.h"
-
-namespace Trinity
-{
- /**
- * OperatorNew policy creates an object on the heap using new.
- */
- template <class T>
- class OperatorNew
- {
- public:
- static T* Create(void) { return (new T); }
- static void Destroy(T *obj) { delete obj; }
- };
-
- /**
- * LocalStaticCreation policy creates an object on the stack
- * the first time call Create.
- */
- template <class T>
- class LocalStaticCreation
- {
- union MaxAlign
- {
- char t_[sizeof(T)];
- short int shortInt_;
- int int_;
- long int longInt_;
- float float_;
- double double_;
- long double longDouble_;
- struct Test;
- int Test::* pMember_;
- int (Test::*pMemberFn_)(int);
- };
- public:
- static T* Create(void)
- {
- static MaxAlign si_localStatic;
- return new(&si_localStatic) T;
- }
-
- static void Destroy(T *obj) { obj->~T(); }
- };
-
- /**
- * CreateUsingMalloc by pass the memory manger.
- */
- template<class T>
- class CreateUsingMalloc
- {
- public:
- static T* Create()
- {
- void* p = ::malloc(sizeof(T));
- if (!p) return 0;
- return new(p) T;
- }
-
- static void Destroy(T* p)
- {
- p->~T();
- ::free(p);
- }
- };
-
- /**
- * CreateOnCallBack creates the object base on the call back.
- */
- template<class T, class CALL_BACK>
- class CreateOnCallBack
- {
- public:
- static T* Create()
- {
- return CALL_BACK::createCallBack();
- }
-
- static void Destroy(T *p)
- {
- CALL_BACK::destroyCallBack(p);
- }
- };
-}
-#endif
-
diff --git a/src/server/shared/Policies/ObjectLifeTime.cpp b/src/server/shared/Policies/ObjectLifeTime.cpp
deleted file mode 100644
index fd16873ae92..00000000000
--- a/src/server/shared/Policies/ObjectLifeTime.cpp
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
- *
- * Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include <cstdlib>
-#include "ObjectLifeTime.h"
-
-namespace Trinity
-{
- extern "C" void external_wrapper(void *p)
- {
- std::atexit( (void (*)())p );
- }
-
- void at_exit( void (*func)() )
- {
- external_wrapper((void*)func);
- }
-}
-
diff --git a/src/server/shared/Policies/ObjectLifeTime.h b/src/server/shared/Policies/ObjectLifeTime.h
deleted file mode 100644
index 205434cb613..00000000000
--- a/src/server/shared/Policies/ObjectLifeTime.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
- *
- * Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * 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_OBJECTLIFETIME_H
-#define TRINITY_OBJECTLIFETIME_H
-
-#include <stdexcept>
-#include "Define.h"
-
-typedef void (* Destroyer)(void);
-
-namespace Trinity
-{
- void at_exit( void (*func)() );
-
- template <class T>
- class ObjectLifeTime
- {
- public:
- static void ScheduleCall(void (*destroyer)() )
- {
- at_exit( destroyer );
- }
-
- DECLSPEC_NORETURN static void OnDeadReference(void) ATTR_NORETURN;
-
- };
-
- template <class T>
- void ObjectLifeTime<T>::OnDeadReference(void) // We don't handle Dead Reference for now
- {
- throw std::runtime_error("Dead Reference");
- }
-}
-#endif
-
diff --git a/src/server/shared/Policies/Singleton.h b/src/server/shared/Policies/Singleton.h
deleted file mode 100644
index da898558ca5..00000000000
--- a/src/server/shared/Policies/Singleton.h
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
- *
- * Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * 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_SINGLETON_H
-#define TRINITY_SINGLETON_H
-
-/**
- * @brief class Singleton
- */
-
-#include "CreationPolicy.h"
-#include "ThreadingModel.h"
-#include "ObjectLifeTime.h"
-
-namespace Trinity
-{
- template
- <
- typename T,
- class ThreadingModel = Trinity::SingleThreaded<T>,
- class CreatePolicy = Trinity::OperatorNew<T>,
- class LifeTimePolicy = Trinity::ObjectLifeTime<T>
- >
- class Singleton
- {
- public:
- static T& Instance();
-
- protected:
- Singleton() {};
-
- private:
-
- // Prohibited actions...this does not prevent hijacking.
- Singleton(const Singleton &);
- Singleton& operator=(const Singleton &);
-
- // Singleton Helpers
- static void DestroySingleton();
-
- // data structure
- typedef typename ThreadingModel::Lock Guard;
- static T *si_instance;
- static bool si_destroyed;
- };
-}
-#endif
-
diff --git a/src/server/shared/Policies/SingletonImp.h b/src/server/shared/Policies/SingletonImp.h
deleted file mode 100644
index 3e985cd5c64..00000000000
--- a/src/server/shared/Policies/SingletonImp.h
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
- *
- * Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * 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_SINGLETONIMPL_H
-#define TRINITY_SINGLETONIMPL_H
-
-#include "Singleton.h"
-
-// avoid the using namespace here cuz
-// its a .h file afterall
-
-template
-<
-typename T,
-class ThreadingModel,
-class CreatePolicy,
-class LifeTimePolicy
->
-T&
-Trinity::Singleton<T, ThreadingModel, CreatePolicy, LifeTimePolicy >::Instance()
-{
- if( !si_instance )
- {
- // double-checked Locking pattern
- Guard();
- if( !si_instance )
- {
- if( si_destroyed )
- {
- si_destroyed = false;
- LifeTimePolicy::OnDeadReference();
- }
- si_instance = CreatePolicy::Create();
- LifeTimePolicy::ScheduleCall(&DestroySingleton);
- }
- }
-
- return *si_instance;
-}
-
-template
-<
-typename T,
-class ThreadingModel,
-class CreatePolicy,
-class LifeTimePolicy
->
-void
-Trinity::Singleton<T, ThreadingModel, CreatePolicy, LifeTimePolicy>::DestroySingleton()
-{
- CreatePolicy::Destroy(si_instance);
- si_instance = NULL;
- si_destroyed = true;
-}
-
-#define INSTANTIATE_SINGLETON_1(TYPE) \
- template class Trinity::Singleton<TYPE, Trinity::SingleThreaded<TYPE>, Trinity::OperatorNew<TYPE>, Trinity::ObjectLifeTime<TYPE> >; \
- template<> TYPE* Trinity::Singleton<TYPE, Trinity::SingleThreaded<TYPE>, Trinity::OperatorNew<TYPE>, Trinity::ObjectLifeTime<TYPE> >::si_instance = 0; \
- template<> bool Trinity::Singleton<TYPE, Trinity::SingleThreaded<TYPE>, Trinity::OperatorNew<TYPE>, Trinity::ObjectLifeTime<TYPE> >::si_destroyed = false
-
-#define INSTANTIATE_SINGLETON_2(TYPE, THREADINGMODEL) \
- template class Trinity::Singleton<TYPE, THREADINGMODEL, Trinity::OperatorNew<TYPE>, Trinity::ObjectLifeTime<TYPE> >; \
- template<> TYPE* Trinity::Singleton<TYPE, THREADINGMODEL, Trinity::OperatorNew<TYPE>, Trinity::ObjectLifeTime<TYPE> >::si_instance = 0; \
- template<> bool Trinity::Singleton<TYPE, THREADINGMODEL, Trinity::OperatorNew<TYPE>, Trinity::ObjectLifeTime<TYPE> >::si_destroyed = false
-
-#define INSTANTIATE_SINGLETON_3(TYPE, THREADINGMODEL, CREATIONPOLICY ) \
- template class Trinity::Singleton<TYPE, THREADINGMODEL, CREATIONPOLICY, Trinity::ObjectLifeTime<TYPE> >; \
- template<> TYPE* Trinity::Singleton<TYPE, THREADINGMODEL, CREATIONPOLICY, Trinity::ObjectLifeTime<TYPE> >::si_instance = 0; \
- template<> bool Trinity::Singleton<TYPE, THREADINGMODEL, CREATIONPOLICY, Trinity::ObjectLifeType<TYPE> >::si_destroyed = false
-
-#define INSTANTIATE_SINGLETON_4(TYPE, THREADINGMODEL, CREATIONPOLICY, OBJECTLIFETIME) \
- template class Trinity::Singleton<TYPE, THREADINGMODEL, CREATIONPOLICY, OBJECTLIFETIME >; \
- template<> TYPE* Trinity::Singleton<TYPE, THREADINGMODEL, CREATIONPOLICY, OBJECTLIFETIME >::si_instance = 0; \
- template<> bool Trinity::Singleton<TYPE, THREADINGMODEL, CREATIONPOLICY, OBJECTLIFETIME >::si_destroyed = false
-#endif
-
diff --git a/src/server/shared/Policies/ThreadingModel.h b/src/server/shared/Policies/ThreadingModel.h
deleted file mode 100644
index a792bf1b7d7..00000000000
--- a/src/server/shared/Policies/ThreadingModel.h
+++ /dev/null
@@ -1,130 +0,0 @@
-/*
- * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
- *
- * Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * 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 "Define.h"
-
-namespace Trinity
-{
- inline void Guard(void *) {}
-
- template<typename MUTEX> class GeneralLock
- {
- public:
- GeneralLock(MUTEX &m) : i_mutex(m)
- {
- i_mutex.acquire();
- }
-
- ~GeneralLock()
- {
- i_mutex.release();
- }
- private:
- GeneralLock(const GeneralLock &);
- GeneralLock& operator=(const GeneralLock &);
- MUTEX &i_mutex;
- };
-
- template <class T>
- class SingleThreaded
- {
- public:
-
- struct Lock // empty object
- {
- Lock() {}
- Lock(const T &) {}
- Lock(const SingleThreaded<T> &) // for single threaded we ignore this
- {
- }
- };
-
- typedef T VolatileType;
- };
-
- // object level lockable
- template<class T, class MUTEX>
- class 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 ClassLevelLockable
- {
- public:
- class Lock;
- friend class Lock;
- typedef volatile T VolatileType;
-
- ClassLevelLockable() {}
-
- class Lock
- {
- public:
- Lock(T& /*host*/) { ClassLevelLockable<T, MUTEX>::si_mtx.acquire(); }
- Lock(ClassLevelLockable<T, MUTEX> &) { ClassLevelLockable<T, MUTEX>::si_mtx.acquire(); }
- 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::ClassLevelLockable<CTYPE, MUTEX >
-#endif
-