]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/base/Lock.h
1 #ifndef SQUID_SRC_BASE_LOCK_H
2 #define SQUID_SRC_BASE_LOCK_H
5 * This class provides a tracking counter and presents
6 * lock(), unlock() and LockCount() accessors.
8 * All locks must be cleared with unlock() before this object
11 * Accessors provided by this interface are not private,
12 * to allow class hierarchies.
14 * Build with -DLOCKCOUNT_DEBUG flag to enable lock debugging.
15 * It is disabled by default due to the cost of debug output.
22 virtual ~Lock() { assert(count_
== 0); }
24 /// Register one lock / reference against this object.
25 /// All locks must be cleared before it may be destroyed.
27 #if defined(LOCKCOUNT_DEBUG)
28 old_debug(0,1)("Incrementing this %p from count %u\n",this,count_
);
33 /// Clear one lock / reference against this object.
34 /// All locks must be cleared before it may be destroyed.
35 unsigned unlock() const {
36 #if defined(LOCKCOUNT_DEBUG)
37 old_debug(0,1)("Decrementing this %p from count %u\n",this,count_
);
43 /// Inspect the current count of references.
44 unsigned LockCount() const { return count_
; }
47 mutable unsigned count_
; ///< number of references currently being tracked
50 // For clarity we provide some aliases for the tracking mechanisms
51 // using Lock so that we can easily see what type of smart pointers
52 // are to be used for the child object.
53 // NP: CbcPointer<> and RefCount<> pointers should be used consistently
54 // for any given child class type
56 /// The locking interface for use on Reference-Counted classes
57 #define RefCountable virtual Lock
59 #endif /* SQUID_SRC_BASE_LOCK_H */