AsyncCall.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 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.h"
15 #include <ostream>
16 
18 
19 /* AsyncCall */
20 
21 AsyncCall::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 
38 void
40 {
41  debugs(debugSection, debugLevel, HERE << "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, HERE << "will not call " << name <<
52  " [" << id << ']' << " because of " << isCanceled);
53 }
54 
55 bool
56 AsyncCall::cancel(const char *reason)
57 {
58  debugs(debugSection, debugLevel, HERE << "will not call " << name <<
59  " [" << id << "] " << (isCanceled ? "also " : "") <<
60  "because " << reason);
61 
62  isCanceled = reason;
63  return false;
64 }
65 
66 bool
68 {
69  return !isCanceled;
70 }
71 
72 // TODO: make this method const by providing a const getDialer()
73 void
74 AsyncCall::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 
83 void
85 {
86  if (prev != NULL)
87  prev->setNext(Next());
88  else
89  head = Next();
90  setNext(NULL);
91 }
92 
93 bool
94 ScheduleCall(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 
bool cancel(const char *reason)
Definition: AsyncCall.cc:56
void schedule(AsyncCall::Pointer &call)
CodeContext::Pointer codeContext
what the callee is expected to work on
Definition: AsyncCall.h:75
void setNext(AsyncCall::Pointer aNext)
Definition: AsyncCall.h:63
virtual CallDialer * getDialer()=0
static AsyncCallQueue & Instance()
virtual bool canFire()
Definition: AsyncCall.cc:67
InstanceIdDefinitions(AsyncCall, "call")
void print(std::ostream &os)
Definition: AsyncCall.cc:74
virtual ~AsyncCall()
Definition: AsyncCall.cc:33
#define NULL
Definition: types.h:166
const int debugLevel
Definition: AsyncCall.h:78
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Debug.h:128
const InstanceId< AsyncCall > id
Definition: AsyncCall.h:79
virtual void fire()=0
std::ostream & HERE(std::ostream &s)
Definition: Debug.h:157
const int debugSection
Definition: AsyncCall.h:77
#define assert(EX)
Definition: assert.h:19
bool ScheduleCall(const char *fileName, int fileLine, AsyncCall::Pointer &call)
Definition: AsyncCall.cc:94
const char *const name
Definition: AsyncCall.h:72
void make()
Definition: AsyncCall.cc:39
static const Pointer & Current()
Definition: CodeContext.cc:33
squidaio_request_t * head
Definition: aiops.cc:127
const char * isCanceled
Definition: AsyncCall.h:89
AsyncCall::Pointer & Next()
Definition: AsyncCall.h:67
AsyncCall::Pointer theNext
Definition: AsyncCall.h:86
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

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors