CodeContext.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2020 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.h"
12 
15 {
16 public:
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 
25 static CodeContext::Pointer &
27 {
28  static const auto Instance = new CodeContext::Pointer(nullptr);
29  return *Instance;
30 }
31 
34 {
35  return Instance();
36 }
37 
41 void
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 
53 void
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 
65 void
67 {
68  ForgetCurrent();
69  auto &current = Instance();
70  debugs(1, 7, *current);
71  current = nullptr;
72 }
73 
74 void
76 {
77  if (Instance())
78  Leaving();
79 }
80 
81 void
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 
93 std::ostream &
94 CurrentCodeContextDetail(std::ostream &os)
95 {
96  if (const auto ctx = CodeContext::Current())
97  ctx->detailCodeContext(os);
98  return os;
99 }
100 
virtual ScopedId codeContextGist() const override
Definition: CodeContext.cc:18
static CodeContext::Pointer & Instance()
guarantees the forever existence of the pointer, starting from the first use
Definition: CodeContext.cc:26
static void Leaving()
Definition: CodeContext.cc:66
static void Entering(const Pointer &codeCtx)
Definition: CodeContext.cc:54
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 =0
RefCount< CodeContext > Pointer
Definition: CodeContext.h:23
static void Reset()
forgets the current context, setting it to nil/unknown
Definition: CodeContext.cc:75
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Debug.h:128
code related to Squid Instance and PID file management
Definition: Instance.h:17
#define assert(EX)
Definition: assert.h:19
std::ostream & CurrentCodeContextDetail(std::ostream &os)
Definition: CodeContext.cc:94
represents a being-forgotten CodeContext (while it may be being destroyed)
Definition: CodeContext.cc:14
static const Pointer & Current()
Definition: CodeContext.cc:33
ScopedId gist
identifies the being-forgotten CodeContext
Definition: CodeContext.cc:21
static void ForgetCurrent()
Definition: CodeContext.cc:42

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors