2 * Copyright (C) 2005-2008 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #ifndef MANGOS_THREADINGMODEL_H
20 #define MANGOS_THREADINGMODEL_H
23 * @class ThreadingModel<T>
27 #include "Platform/Define.h"
31 inline void Guard(void *) {}
33 template<typename MUTEX
> class MANGOS_DLL_DECL GeneralLock
36 GeneralLock(MUTEX
&m
) : i_mutex(m
)
46 GeneralLock(const GeneralLock
&);
47 GeneralLock
& operator=(const GeneralLock
&);
52 class MANGOS_DLL_DECL SingleThreaded
56 struct Lock
// empty object
60 Lock(const SingleThreaded
<T
> &) // for single threaded we ignore this
65 typedef T VolatileType
;
68 // object level lockable
69 template<class T
, class MUTEX
>
70 class MANGOS_DLL_DECL ObjectLevelLockable
73 ObjectLevelLockable() : i_mtx() {}
80 Lock(ObjectLevelLockable
<T
, MUTEX
> &host
) : i_lock(host
.i_mtx
)
85 GeneralLock
<MUTEX
> i_lock
;
88 typedef volatile T VolatileType
;
91 // prevent the compiler creating a copy construct
92 ObjectLevelLockable(const ObjectLevelLockable
<T
, MUTEX
> &);
93 ObjectLevelLockable
<T
, MUTEX
>& operator=(const ObjectLevelLockable
<T
, MUTEX
> &);
98 template<class T
, class MUTEX
>
99 class MANGOS_DLL_DECL ClassLevelLockable
104 typedef volatile T VolatileType
;
106 ClassLevelLockable() {}
111 Lock(T
& /*host*/) { ClassLevelLockable
<T
, MUTEX
>::si_mtx
.acquire(); }
112 Lock(ClassLevelLockable
<T
, MUTEX
> &) { ClassLevelLockable
<T
, MUTEX
>::si_mtx
.acquire(); }
113 Lock() { ClassLevelLockable
<T
, MUTEX
>::si_mtx
.acquire(); }
114 ~Lock() { ClassLevelLockable
<T
, MUTEX
>::si_mtx
.release(); }
123 template<class T
, class MUTEX
> MUTEX
MaNGOS::ClassLevelLockable
<T
, MUTEX
>::si_mtx
;
125 #define INSTANTIATE_CLASS_MUTEX(CTYPE,MUTEX) \
126 template class MANGOS_DLL_DECL MaNGOS::ClassLevelLockable<CTYPE, MUTEX >