diff options
| author | Machiavelli <none@none> | 2010-06-25 00:18:01 +0200 |
|---|---|---|
| committer | Machiavelli <none@none> | 2010-06-25 00:18:01 +0200 |
| commit | 0f7657b68c8b6444fadb480cdd0f87631391afa5 (patch) | |
| tree | a5ffdaecbb1332ffbc655916842a23a622340c98 /src/server/shared/Policies | |
| parent | a6b9e716a61334e218cff227f66b0c51053e72f3 (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/Policies')
| -rw-r--r-- | src/server/shared/Policies/CreationPolicy.h | 110 | ||||
| -rw-r--r-- | src/server/shared/Policies/ObjectLifeTime.cpp | 36 | ||||
| -rw-r--r-- | src/server/shared/Policies/ObjectLifeTime.h | 53 | ||||
| -rw-r--r-- | src/server/shared/Policies/Singleton.h | 65 | ||||
| -rw-r--r-- | src/server/shared/Policies/SingletonImp.h | 93 | ||||
| -rw-r--r-- | src/server/shared/Policies/ThreadingModel.h | 130 |
6 files changed, 0 insertions, 487 deletions
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 - |
