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