CodeContext.cc
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 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
Definition: CodeContext.cc:26
std::ostream & CurrentCodeContextDetail(std::ostream &os)
Definition: CodeContext.cc:96
#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()
Definition: CodeContext.cc:33
RefCount< CodeContext > Pointer
Definition: CodeContext.h:55
static void Leaving()
Definition: CodeContext.cc:68
virtual ScopedId codeContextGist() const =0
static void Entering(const Pointer &codeCtx)
Definition: CodeContext.cc:55
static void ForgetCurrent()
Definition: CodeContext.cc:42
static void Reset()
forgets the current context, setting it to nil/unknown
Definition: CodeContext.cc:77
represents a being-forgotten CodeContext (while it may be being destroyed)
Definition: CodeContext.cc:15
ScopedId gist
identifies the being-forgotten CodeContext
Definition: CodeContext.cc:21
std::ostream & detailCodeContext(std::ostream &os) const override
appends human-friendly context description line(s) to a cache.log record
Definition: CodeContext.cc:19
ScopedId codeContextGist() const override
Definition: CodeContext.cc:18
void resume()
Definition: Stopwatch.cc:31
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Stream.h:194
code related to Squid Instance and PID file management
Definition: Instance.h:17

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors