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