AsyncCall.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 files for details.
7 */
8
9#include "squid.h"
10#include "base/AsyncCall.h"
11#include "base/AsyncCallQueue.h"
12#include "base/CodeContext.h"
13#include "cbdata.h"
14#include "debug/Stream.h"
15#include <ostream>
16
18
19/* AsyncCall */
20
21AsyncCall::AsyncCall(int aDebugSection, int aDebugLevel, const char *aName):
22 name(aName),
23 codeContext(CodeContext::Current()),
24 debugSection(aDebugSection),
25 debugLevel(aDebugLevel),
26 theNext(nullptr),
27 isCanceled(nullptr)
28{
29 debugs(debugSection, debugLevel, "The AsyncCall " << name << " constructed, this=" << this <<
30 " [" << id << ']');
31}
32
34{
35 assert(!theNext); // AsyncCallQueue must clean
36}
37
38void
40{
41 debugs(debugSection, debugLevel, "make call " << name <<
42 " [" << id << ']');
43 if (canFire()) {
44 fire();
45 return;
46 }
47
48 if (!isCanceled) // we did not cancel() when returning false from canFire()
49 isCanceled = "unknown reason";
50
51 debugs(debugSection, debugLevel, "will not call " << name <<
52 " [" << id << ']' << " because of " << isCanceled);
53}
54
55bool
56AsyncCall::cancel(const char *reason)
57{
58 debugs(debugSection, debugLevel, "will not call " << name <<
59 " [" << id << "] " << (isCanceled ? "also " : "") <<
60 "because " << reason);
61
62 isCanceled = reason;
63 return false;
64}
65
66bool
68{
69 return !isCanceled;
70}
71
72// TODO: make this method const by providing a const getDialer()
73void
74AsyncCall::print(std::ostream &os)
75{
76 os << name;
77 if (const CallDialer *dialer = getDialer())
78 dialer->print(os);
79 else
80 os << "(?" << this << "?)";
81}
82
83void
85{
86 if (prev != nullptr)
87 prev->setNext(Next());
88 else
89 head = Next();
90 setNext(nullptr);
91}
92
93bool
94ScheduleCall(const char *fileName, int fileLine, AsyncCall::Pointer &call)
95{
96 debugs(call->debugSection, call->debugLevel, fileName << "(" << fileLine <<
97 ") will call " << *call << " [" << call->id << ']' );
98
99 // Support callback creators that did not get their context from service A,
100 // but the current caller (service B) got that context from another source.
101 if (!call->codeContext)
103
105 return true;
106}
107
InstanceIdDefinitions(AsyncCall, "call")
bool ScheduleCall(const char *fileName, int fileLine, AsyncCall::Pointer &call)
Definition: AsyncCall.cc:94
squidaio_request_t * head
Definition: aiops.cc:126
#define assert(EX)
Definition: assert.h:19
void schedule(const AsyncCallPointer &call)
static AsyncCallQueue & Instance()
const int debugLevel
Definition: AsyncCall.h:76
virtual bool canFire()
Definition: AsyncCall.cc:67
virtual void fire()=0
void dequeue(AsyncCall::Pointer &head, AsyncCall::Pointer &prev)
remove us from the queue; we are head unless we are queued after prev
Definition: AsyncCall.cc:84
const InstanceId< AsyncCall > id
Definition: AsyncCall.h:77
bool cancel(const char *reason)
Definition: AsyncCall.cc:56
AsyncCall::Pointer & Next()
Definition: AsyncCall.h:65
const int debugSection
Definition: AsyncCall.h:75
virtual ~AsyncCall()
Definition: AsyncCall.cc:33
void print(std::ostream &os)
Definition: AsyncCall.cc:74
virtual CallDialer * getDialer()=0
const char * isCanceled
Definition: AsyncCall.h:87
AsyncCall::Pointer theNext
for AsyncCallList and similar lists
Definition: AsyncCall.h:84
void make()
Definition: AsyncCall.cc:39
const char *const name
Definition: AsyncCall.h:70
CodeContext::Pointer codeContext
what the callee is expected to work on
Definition: AsyncCall.h:73
void setNext(AsyncCall::Pointer aNext)
Definition: AsyncCall.h:61
static const Pointer & Current()
Definition: CodeContext.cc:33
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Stream.h:196

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors