]> git.ipfire.org Git - thirdparty/squid.git/blob - src/AsyncCallQueue.cc
SourceFormat: Main reformat push
[thirdparty/squid.git] / src / AsyncCallQueue.cc
1
2 /*
3 * $Id: AsyncCallQueue.cc,v 1.1 2008/02/13 06:01:39 rousskov Exp $
4 *
5 * DEBUG: section 41 Event Processing
6 *
7 */
8
9 #include "AsyncCallQueue.h"
10 #include "AsyncCall.h"
11
12 AsyncCallQueue *AsyncCallQueue::TheInstance = 0;
13
14
15 AsyncCallQueue::AsyncCallQueue(): theHead(NULL), theTail(NULL)
16 {
17 }
18
19 void AsyncCallQueue::schedule(AsyncCall::Pointer &call)
20 {
21 assert(call != NULL);
22 assert(!call->theNext);
23 if (theHead != NULL) { // append
24 assert(!theTail->theNext);
25 theTail->theNext = call;
26 theTail = call;
27 } else { // create queue from cratch
28 theHead = theTail = call;
29 }
30 }
31
32 // Fire all scheduled calls; returns true if at least one call was fired.
33 // The calls may be added while the current call is in progress.
34 bool
35 AsyncCallQueue::fire()
36 {
37 const bool made = theHead != NULL;
38 while (theHead != NULL)
39 fireNext();
40 return made;
41 }
42
43 void
44 AsyncCallQueue::fireNext()
45 {
46 AsyncCall::Pointer call = theHead;
47 theHead = call->theNext;
48 call->theNext = NULL;
49 if (theTail == call)
50 theTail = NULL;
51
52 debugs(call->debugSection, call->debugLevel, "entering " << *call);
53 call->make();
54 debugs(call->debugSection, call->debugLevel, "leaving " << *call);
55 }
56
57 AsyncCallQueue &
58 AsyncCallQueue::Instance()
59 {
60 // TODO: how to remove this frequent check while supporting early calls?
61 if (!TheInstance)
62 TheInstance = new AsyncCallQueue();
63
64 return *TheInstance;
65 }
66