Lock.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
3 *
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.
7 */
8
9#ifndef SQUID_SRC_BASE_LOCK_H
10#define SQUID_SRC_BASE_LOCK_H
11
25class Lock
26{
27public:
28 Lock():count_(0) {}
29
30 virtual ~Lock() { assert(count_ == 0); }
31
34 void lock() const {
35#if defined(LOCKCOUNT_DEBUG)
36 debugs(0,1, "Incrementing this " << static_cast<void*>(this) << " from count " << count_);
37#endif
39 ++count_;
40 }
41
44 uint32_t unlock() const {
45#if defined(LOCKCOUNT_DEBUG)
46 debugs(0,1, "Decrementing this " << static_cast<void*>(this) << " from count " << count_);
47#endif
48 assert(count_ > 0);
49 return --count_;
50 }
51
53 uint32_t LockCount() const { return count_; }
54
55private:
56 mutable uint32_t count_;
57};
58
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
64
66#define RefCountable virtual Lock
67
68#endif /* SQUID_SRC_BASE_LOCK_H */
69
#define assert(EX)
Definition: assert.h:17
Definition: Lock.h:26
void lock() const
Definition: Lock.h:34
virtual ~Lock()
Definition: Lock.h:30
Lock()
Definition: Lock.h:28
uint32_t count_
number of references currently being tracked
Definition: Lock.h:56
uint32_t unlock() const
Definition: Lock.h:44
uint32_t LockCount() const
Inspect the current count of references.
Definition: Lock.h:53
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Stream.h:194
#define UINT32_MAX
Definition: types.h:66

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors