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)
5  2008, Hermann Vosseler <Ichthyostega@web.de>
6  2023, Hermann Vosseler <Ichthyostega@web.de>
7 
8   **Lumiera** is free software; you can redistribute it and/or modify it
9   under the terms of the GNU General Public License as published by the
10   Free Software Foundation; either version 2 of the License, or (at your
11   option) any later version. See the file COPYING for further details.
12 
13 */
14 
28 #ifndef LIB_SYNC_CLASSLOCK_H
29 #define LIB_SYNC_CLASSLOCK_H
30 
31 #include "lib/nobug-init.hpp"
32 #include "lib/zombie-check.hpp"
33 #include "lib/meta/util.hpp"
34 #include "lib/sync.hpp"
35 
36 
37 namespace lib {
38 
39 
54  template<class X, class CONF = RecursiveLock_NoWait>
55  class ClassLock
56  : public Sync<CONF>::Lock
57  {
58  using Lock = typename Sync<CONF>::Lock;
59  using Monitor = typename sync::Monitor<CONF>;
60 
61  struct PerClassMonitor : Monitor {};
62 
63  Monitor&
64  getPerClassMonitor()
65  {
66  static PerClassMonitor classMonitor;
67  static ZombieCheck zombieCheck{util::typeStr(this)};
68 
69  zombieCheck();
70  return classMonitor;
71  }
72 
73  public:
74  ClassLock()
75  : Lock{getPerClassMonitor()}
76  { }
77  };
78 
79 
80 } // namespace lib
81 #endif /*LIB_SYNC_CLASSLOCK_H*/
Facility for monitor object based locking.
Definition: sync.hpp:209
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:226
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.