JobWait.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2023 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/AsyncJobCalls.h"
11#include "base/JobWait.h"
12
13#include <cassert>
14#include <iostream>
15
16JobWaitBase::JobWaitBase() = default;
17
19{
20 cancel("owner gone");
21}
22
23void
25{
26 // Invariant: The wait will be over. We cannot guarantee that the job will
27 // call the callback, of course, but we can check these prerequisites.
28 assert(aCall);
29 assert(aJob.valid());
30
31 // "Double" waiting state leads to conflicting/mismatching callbacks
32 // detailed in finish(). Detect that bug ASAP.
33 assert(!waiting());
34
36 assert(!job_);
37 callback_ = aCall;
38 job_ = aJob;
39
41}
42
43void
45{
46 // Unexpected callbacks might result in disasters like secrets exposure,
47 // data corruption, or expensive message routing mistakes when the callback
48 // info is applied to the wrong message part or acted upon prematurely.
49 assert(waiting());
50 clear();
51}
52
53void
54JobWaitBase::cancel(const char *reason)
55{
56 if (callback_) {
57 callback_->cancel(reason);
58
59 // Instead of AsyncJob, the class parameter could be Job. That would
60 // avoid runtime child-to-parent CbcPointer conversion overheads, but
61 // complicate support for Jobs with virtual AsyncJob bases (GCC error:
62 // "pointer to member conversion via virtual base AsyncJob") and also
63 // cache-log "Job::handleStopRequest()" with a non-existent class name.
65
66 clear();
67 }
68}
69
70void
71JobWaitBase::print(std::ostream &os) const
72{
73 // use a backarrow to emphasize that this is a callback: call24<-job6
74 if (callback_)
75 os << callback_->id << "<-";
76 if (const auto rawJob = job_.get())
77 os << rawJob->id;
78 else
79 os << job_; // raw pointer of a gone job may still be useful for triage
80}
81
#define CallJobHere(debugSection, debugLevel, job, Class, method)
Definition: AsyncJobCalls.h:58
#define assert(EX)
Definition: assert.h:17
const int debugLevel
Definition: AsyncCall.h:77
const InstanceId< AsyncCall > id
Definition: AsyncCall.h:78
bool cancel(const char *reason)
Definition: AsyncCall.cc:56
const int debugSection
Definition: AsyncCall.h:76
static void Start(const Pointer &job)
Definition: AsyncJob.cc:37
Cbc * valid() const
was set and is valid
Definition: CbcPointer.h:41
Cbc * get() const
a temporary valid raw Cbc pointer or NULL
Definition: CbcPointer.h:159
void clear()
the common part of finish() and cancel()
Definition: JobWait.h:51
~JobWaitBase()
Definition: JobWait.cc:18
void finish()
Definition: JobWait.cc:44
void start_(AsyncJob::Pointer, AsyncCall::Pointer)
starts waiting for the given job to call the given callback
Definition: JobWait.cc:24
void cancel(const char *reason)
Definition: JobWait.cc:54
void print(std::ostream &) const
summarizes what we are waiting for (for debugging)
Definition: JobWait.cc:71
AsyncJob::Pointer job_
the job that we are waiting to call us back (or nil)
Definition: JobWait.h:54
bool waiting() const
Definition: JobWait.h:32
AsyncCall::Pointer callback_
the call we are waiting for the job_ to make (or nil)
Definition: JobWait.h:57

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors