/** * MaNGOS is a full featured server for World of Warcraft, supporting * the following clients: 1.12.x, 2.4.3, 3.3.5a, 4.3.4a and 5.4.8 * * Copyright (C) 2005-2017 MaNGOS project * * 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 * * World of Warcraft, and all World of Warcraft or Warcraft art, images, * and lore are copyrighted by Blizzard Entertainment, Inc. */ #ifndef MANGOS_THREADINGMODEL_H #define MANGOS_THREADINGMODEL_H /** * @class ThreadingModel * */ #include "Platform/Define.h" namespace MaNGOS { template /** * @brief * */ class GeneralLock { public: /** * @brief * * @param m */ GeneralLock(MUTEX& m) : i_mutex(m) { i_mutex.acquire(); } /** * @brief * */ ~GeneralLock() { i_mutex.release(); } private: /** * @brief * * @param */ GeneralLock(const GeneralLock&); /** * @brief * * @param * @return GeneralLock &operator */ GeneralLock& operator=(const GeneralLock&); MUTEX& i_mutex; /**< TODO */ }; template /** * @brief * */ class SingleThreaded { public: /** * @brief empty object * */ struct Lock { /** * @brief * */ Lock() { } /** * @brief * * @param */ Lock(const T&) { } /** * @brief for single threaded we ignore this * * @param */ Lock(const SingleThreaded&) { } }; }; template /** * @brief * */ class ObjectLevelLockable { public: /** * @brief * */ ObjectLevelLockable() : i_mtx() { } friend class Lock; /** * @brief * */ class Lock { public: /** * @brief * * @param ObjectLevelLockable& host) : i_lock(host.i_mtx) { } private: GeneralLock i_lock; /**< TODO */ }; private: /** * @brief prevent the compiler creating a copy construct * * @param ObjectLevelLockable&); /** * @brief * * @param ObjectLevelLockable */ ObjectLevelLockable& operator=(const ObjectLevelLockable&); MUTEX i_mtx; /**< TODO */ }; template /** * @brief * */ class ClassLevelLockable { public: /** * @brief * */ ClassLevelLockable() { } friend class Lock; /** * @brief * */ class Lock { public: /** * @brief * * @param */ Lock(const T& /*host*/) { ClassLevelLockable::si_mtx.acquire(); } /** * @brief * * @param ClassLevelLockable&) { ClassLevelLockable::si_mtx.acquire(); } /** * @brief * */ Lock() { ClassLevelLockable::si_mtx.acquire(); } /** * @brief * */ ~Lock() { ClassLevelLockable::si_mtx.release(); } }; private: static MUTEX si_mtx; /**< TODO */ }; } template MUTEX MaNGOS::ClassLevelLockable::si_mtx; /**< TODO */ #define INSTANTIATE_CLASS_MUTEX(CTYPE, MUTEX) \ template class MaNGOS::ClassLevelLockable #endif