]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/base/Lock.h
2 * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
9 #ifndef SQUID_SRC_BASE_LOCK_H
10 #define SQUID_SRC_BASE_LOCK_H
13 * This class provides a tracking counter and presents
14 * lock(), unlock() and LockCount() accessors.
16 * All locks must be cleared with unlock() before this object
19 * Accessors provided by this interface are not private,
20 * to allow class hierarchies.
22 * Build with -DLOCKCOUNT_DEBUG flag to enable lock debugging.
23 * It is disabled by default due to the cost of debug output.
30 virtual ~Lock() { assert(count_
== 0); }
32 /// Register one lock / reference against this object.
33 /// All locks must be cleared before it may be destroyed.
35 #if defined(LOCKCOUNT_DEBUG)
36 old_debug(0,1)("Incrementing this %p from count %u\n",this,count_
);
38 assert(count_
< UINT32_MAX
);
42 /// Clear one lock / reference against this object.
43 /// All locks must be cleared before it may be destroyed.
44 uint32_t unlock() const {
45 #if defined(LOCKCOUNT_DEBUG)
46 old_debug(0,1)("Decrementing this %p from count %u\n",this,count_
);
52 /// Inspect the current count of references.
53 uint32_t LockCount() const { return count_
; }
56 mutable uint32_t count_
; ///< number of references currently being tracked
59 // For clarity we provide some aliases for the tracking mechanisms
60 // using Lock so that we can easily see what type of smart pointers
61 // are to be used for the child object.
62 // NP: CbcPointer<> and RefCount<> pointers should be used consistently
63 // for any given child class type
65 /// The locking interface for use on Reference-Counted classes
66 #define RefCountable virtual Lock
68 #endif /* SQUID_SRC_BASE_LOCK_H */