]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/base/CodeContext.cc
78faa024eb4664597d63b67538ef43f12831057f
2 * Copyright (C) 1996-2020 The Squid Software Foundation and contributors
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.
10 #include "base/CodeContext.h"
13 /// represents a being-forgotten CodeContext (while it may be being destroyed)
14 class FadingCodeContext
: public CodeContext
18 virtual ScopedId
codeContextGist() const override
{ return gist
; }
19 virtual std::ostream
&detailCodeContext(std::ostream
&os
) const override
{ return os
<< gist
; }
21 ScopedId gist
; ///< identifies the being-forgotten CodeContext
24 /// guarantees the forever existence of the pointer, starting from the first use
25 static CodeContext::Pointer
&
28 static const auto Instance
= new CodeContext::Pointer(nullptr);
32 const CodeContext::Pointer
&
33 CodeContext::Current()
38 /// Forgets the current known context, possibly triggering its destruction.
39 /// Preserves the gist of the being-forgotten context during its destruction.
40 /// Knows nothing about the next context -- the caller must set it.
42 CodeContext::ForgetCurrent()
44 static const RefCount
<FadingCodeContext
> fadingCodeContext
= new FadingCodeContext();
45 auto ¤t
= Instance();
47 fadingCodeContext
->gist
= current
->codeContextGist();
48 current
= fadingCodeContext
;
51 /// Switches the current context to the given known context. Improves debugging
52 /// output by replacing omni-directional "Reset" with directional "Entering".
54 CodeContext::Entering(const Pointer
&codeCtx
)
56 auto ¤t
= Instance();
58 ForgetCurrent(); // ensure orderly closure of the old context
60 debugs(1, 5, codeCtx
->codeContextGist());
63 /// Forgets the current known context. Improves debugging output by replacing
64 /// omni-directional "Reset" with directional "Leaving".
66 CodeContext::Leaving()
69 auto ¤t
= Instance();
70 debugs(1, 7, *current
);
82 CodeContext::Reset(const Pointer codeCtx
)
84 if (codeCtx
== Current())
85 return; // context has not actually changed
94 CurrentCodeContextDetail(std::ostream
&os
)
96 if (const auto ctx
= CodeContext::Current())
97 ctx
->detailCodeContext(os
);