Lumiera  0.pre.03
»edit your freedom«
sync-classlock.hpp
Go to the documentation of this file.
1 /*
2  SYNC-CLASSLOCK.hpp - special case of object based locking tied directly to a type
3 
4  Copyright (C) Lumiera.org
5  2008, Christian Thaeter <ct@pipapo.org>
6  Hermann Vosseler <Ichthyostega@web.de>
7 
8  This program is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License as
10  published by the Free Software Foundation; either version 2 of
11  the License, or (at your option) any later version.
12 
13  This program is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 
22 */
23 
37 #ifndef LIB_SYNC_CLASSLOCK_H
38 #define LIB_SYNC_CLASSLOCK_H
39 
40 #include "lib/nobug-init.hpp"
41 #include "lib/zombie-check.hpp"
42 #include "lib/meta/util.hpp"
43 #include "lib/sync.hpp"
44 
45 
46 namespace lib {
47 
48 
63  template<class X, class CONF = RecursiveLock_NoWait>
64  class ClassLock
65  : public Sync<CONF>::Lock
66  {
67  using Lock = typename Sync<CONF>::Lock;
68  using Monitor = typename sync::Monitor<CONF>;
69 
70  struct PerClassMonitor : Monitor {};
71 
72  Monitor&
73  getPerClassMonitor()
74  {
75  static PerClassMonitor classMonitor;
76  static ZombieCheck zombieCheck{util::typeStr(this)};
77 
78  zombieCheck();
79  return classMonitor;
80  }
81 
82  public:
83  ClassLock()
84  : Lock{getPerClassMonitor()}
85  { }
86  };
87 
88 
89 } // namespace lib
90 #endif /*LIB_SYNC_CLASSLOCK_H*/
Facility for monitor object based locking.
Definition: sync.hpp:217
Trigger the basic NoBug initialisation by placing a static variable.
Simple and lightweight helpers for metaprogramming and type detection.
scoped guard to control the actual locking.
Definition: sync.hpp:234
Implementation namespace for support and library code.
Object Monitor based synchronisation.
Automatic lifecycle tracker, to produce an alarm when accessing objects after deletion.
A synchronisation protection guard employing a lock scoped to the parameter type as a whole...
Detector to set off alarm when (re)using deceased objects.