]> git.ipfire.org Git - thirdparty/squid.git/blame - src/base/AsyncCallQueue.cc
Policy: Include config.h first in all .cc
[thirdparty/squid.git] / src / base / AsyncCallQueue.cc
CommitLineData
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
13AsyncCallQueue *AsyncCallQueue::TheInstance = 0;
14
15
16AsyncCallQueue::AsyncCallQueue(): theHead(NULL), theTail(NULL)
17{
18}
19
20void 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.
35bool
36AsyncCallQueue::fire()
37{
38 const bool made = theHead != NULL;
39 while (theHead != NULL)
40 fireNext();
41 return made;
42}
43
44void
45AsyncCallQueue::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
58AsyncCallQueue &
59AsyncCallQueue::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