]>
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_
);
41 /// Clear one lock / reference against this object.
42 /// All locks must be cleared before it may be destroyed.
43 unsigned unlock() const {
44 #if defined(LOCKCOUNT_DEBUG)
45 old_debug(0,1)("Decrementing this %p from count %u\n",this,count_
);
51 /// Inspect the current count of references.
52 unsigned LockCount() const { return count_
; }
55 mutable unsigned count_
; ///< number of references currently being tracked
58 // For clarity we provide some aliases for the tracking mechanisms
59 // using Lock so that we can easily see what type of smart pointers
60 // are to be used for the child object.
61 // NP: CbcPointer<> and RefCount<> pointers should be used consistently
62 // for any given child class type
64 /// The locking interface for use on Reference-Counted classes
65 #define RefCountable virtual Lock
67 #endif /* SQUID_SRC_BASE_LOCK_H */