Squid Web Cache v8/master
Loading...
Searching...
No Matches
CodeContext.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2025 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 code_contexts for details.
7 */
8
9#include "squid.h"
10#include "base/CodeContext.h"
11#include "debug/Stream.h"
12
15{
16public:
17 /* CodeContext API */
18 ScopedId codeContextGist() const override { return gist; }
19 std::ostream &detailCodeContext(std::ostream &os) const override { return os << gist; }
20
22};
23
27{
28 static const auto Instance = new CodeContext::Pointer(nullptr);
29 return *Instance;
30}
31
34{
35 return Instance();
36}
37
41void
43{
44 static const RefCount<FadingCodeContext> fadingCodeContext = new FadingCodeContext();
45 auto &current = Instance();
46 assert(current);
47 current->busyTime.pause();
48 fadingCodeContext->gist = current->codeContextGist();
49 current = fadingCodeContext;
50}
51
54void
56{
57 auto &current = Instance();
58 if (current)
59 ForgetCurrent(); // ensure orderly closure of the old context
60 current = codeCtx;
61 codeCtx->busyTime.resume();
62 debugs(1, 5, codeCtx->codeContextGist());
63}
64
67void
69{
71 auto &current = Instance();
72 debugs(1, 7, *current);
73 current = nullptr;
74}
75
76void
78{
79 if (Instance())
80 Leaving();
81}
82
83void
85{
86 if (codeCtx == Current())
87 return; // context has not actually changed
88
89 if (!codeCtx)
90 return Leaving();
91
92 Entering(codeCtx);
93}
94
95std::ostream &
96CurrentCodeContextDetail(std::ostream &os)
97{
98 if (const auto ctx = CodeContext::Current())
99 ctx->detailCodeContext(os);
100 return os;
101}
102
static CodeContext::Pointer & Instance()
guarantees the forever existence of the pointer, starting from the first use
std::ostream & CurrentCodeContextDetail(std::ostream &os)
#define assert(EX)
Definition assert.h:17
Stopwatch busyTime
time spent in this context (see also: busy_time)
Definition CodeContext.h:76
static const Pointer & Current()
RefCount< CodeContext > Pointer
Definition CodeContext.h:55
static void Leaving()
virtual ScopedId codeContextGist() const =0
static void Entering(const Pointer &codeCtx)
static void ForgetCurrent()
static void Reset()
forgets the current context, setting it to nil/unknown
represents a being-forgotten CodeContext (while it may be being destroyed)
ScopedId gist
identifies the being-forgotten CodeContext
std::ostream & detailCodeContext(std::ostream &os) const override
appends human-friendly context description line(s) to a cache.log record
ScopedId codeContextGist() const override
void resume()
Definition Stopwatch.cc:31
#define debugs(SECTION, LEVEL, CONTENT)
Definition Stream.h:192
code related to Squid Instance and PID file management
Definition Instance.h:19