]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/base/AsyncJob.cc
34c5bc57edd0eeb66e12c3ba0b164aa1f8138542
2 * DEBUG: section 93 ICAP (RFC 3507) Client
6 #include "base/AsyncCall.h"
7 #include "base/AsyncJob.h"
8 #include "base/AsyncJobCalls.h"
9 #include "base/TextException.h"
15 InstanceIdDefinitions(AsyncJob
, "job");
17 AsyncJob::Pointer
AsyncJob::Start(AsyncJob
*j
)
19 AsyncJob::Pointer
job(j
);
20 CallJobHere(93, 5, job
, AsyncJob
, start
);
24 AsyncJob::AsyncJob(const char *aTypeName
): typeName(aTypeName
), inCall(NULL
)
26 debugs(93,5, "AsyncJob constructed, this=" << this <<
27 " type=" << typeName
<< " [" << id
<< ']');
32 debugs(93,5, "AsyncJob destructed, this=" << this <<
33 " type=" << typeName
<< " [" << id
<< ']');
36 void AsyncJob::start()
40 // XXX: temporary code to replace calls to "delete this" in jobs-in-transition.
41 // Will be replaced with calls to mustStop() when transition is complete.
42 void AsyncJob::deleteThis(const char *aReason
)
47 // if we are in-call, then the call wrapper will delete us
48 debugs(93, 4, typeName
<< " will NOT delete in-call job, reason: " << stopReason
);
52 // there is no call wrapper waiting for our return, so we fake it
53 debugs(93, 5, typeName
<< " will delete this, reason: " << stopReason
);
54 CbcPointer
<AsyncJob
> self(this);
55 AsyncCall::Pointer fakeCall
= asyncCall(93,4, "FAKE-deleteThis",
56 JobMemFun(self
, &AsyncJob::deleteThis
, aReason
));
62 void AsyncJob::mustStop(const char *aReason
)
64 // XXX: temporary code to catch cases where mustStop is called outside
65 // of an async call context. Will be removed when that becomes impossible.
66 // Until then, this will cause memory leaks and possibly other problems.
69 debugs(93, 5, typeName
<< " will STALL, reason: " << stopReason
);
73 Must(inCall
!= NULL
); // otherwise nobody will delete us if we are done()
77 debugs(93, 5, typeName
<< " will stop, reason: " << stopReason
);
79 debugs(93, 5, typeName
<< " will stop, another reason: " << aReason
);
83 bool AsyncJob::done() const
85 // stopReason, set in mustStop(), overwrites all other conditions
86 return stopReason
!= NULL
|| doneAll();
89 bool AsyncJob::doneAll() const
91 return true; // so that it is safe for kids to use
94 bool AsyncJob::canBeCalled(AsyncCall
&call
) const
97 // This may happen when we have bugs or some module is not calling
98 // us asynchronously (comm used to do that).
99 debugs(93, 5, HERE
<< inCall
<< " is in progress; " <<
100 call
<< " canot reenter the job.");
101 return call
.cancel("reentrant job call");
107 void AsyncJob::callStart(AsyncCall
&call
)
109 // we must be called asynchronously and hence, the caller must lock us
110 Must(cbdataReferenceValid(toCbdata()));
112 Must(!inCall
); // see AsyncJob::canBeCalled
114 inCall
= &call
; // XXX: ugly, but safe if callStart/callEnd,Ex are paired
115 debugs(inCall
->debugSection
, inCall
->debugLevel
,
116 typeName
<< " status in:" << status());
119 void AsyncJob::callException(const std::exception
&e
)
121 // we must be called asynchronously and hence, the caller must lock us
122 Must(cbdataReferenceValid(toCbdata()));
124 mustStop("exception");
127 void AsyncJob::callEnd()
130 debugs(93, 5, *inCall
<< " ends job" << status());
132 AsyncCall::Pointer inCallSaved
= inCall
;
133 void *thisSaved
= this;
137 delete this; // this is the only place where the object is deleted
139 // careful: this object does not exist any more
140 debugs(93, 6, HERE
<< *inCallSaved
<< " ended " << thisSaved
);
144 debugs(inCall
->debugSection
, inCall
->debugLevel
,
145 typeName
<< " status out:" << status());
149 // returns a temporary string depicting transaction status, for debugging
150 const char *AsyncJob::status() const
156 if (stopReason
!= NULL
) {
157 buf
.Printf("Stopped, reason:");
158 buf
.Printf("%s",stopReason
);
160 buf
.Printf(" %s%u]", id
.Prefix
, id
.value
);
163 return buf
.content();