CodeContext.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2022 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 virtual ScopedId codeContextGist() const override { return gist; }
19 virtual 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 fadingCodeContext->gist = current->codeContextGist();
48 current = fadingCodeContext;
49}
50
53void
55{
56 auto &current = Instance();
57 if (current)
58 ForgetCurrent(); // ensure orderly closure of the old context
59 current = codeCtx;
60 debugs(1, 5, codeCtx->codeContextGist());
61}
62
65void
67{
69 auto &current = Instance();
70 debugs(1, 7, *current);
71 current = nullptr;
72}
73
74void
76{
77 if (Instance())
78 Leaving();
79}
80
81void
83{
84 if (codeCtx == Current())
85 return; // context has not actually changed
86
87 if (!codeCtx)
88 return Leaving();
89
90 Entering(codeCtx);
91}
92
93std::ostream &
94CurrentCodeContextDetail(std::ostream &os)
95{
96 if (const auto ctx = CodeContext::Current())
97 ctx->detailCodeContext(os);
98 return os;
99}
100
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:94
#define assert(EX)
Definition: assert.h:19
static const Pointer & Current()
Definition: CodeContext.cc:33
RefCount< CodeContext > Pointer
Definition: CodeContext.h:54
static void Leaving()
Definition: CodeContext.cc:66
virtual ScopedId codeContextGist() const =0
static void Entering(const Pointer &codeCtx)
Definition: CodeContext.cc:54
static void ForgetCurrent()
Definition: CodeContext.cc:42
static void Reset()
forgets the current context, setting it to nil/unknown
Definition: CodeContext.cc:75
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
virtual std::ostream & detailCodeContext(std::ostream &os) const override
appends human-friendly context description line(s) to a cache.log record
Definition: CodeContext.cc:19
virtual ScopedId codeContextGist() const override
Definition: CodeContext.cc:18
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Stream.h:196
code related to Squid Instance and PID file management
Definition: Instance.h:17

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors