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