]> git.ipfire.org Git - thirdparty/squid.git/blame - src/AsyncCallQueue.cc
Cleanup: zap CVS Id tags
[thirdparty/squid.git] / src / AsyncCallQueue.cc
CommitLineData
cfa20cf5 1
2/*
262a0e14 3 * $Id$
cfa20cf5 4 *
5 * DEBUG: section 41 Event Processing
6 *
7 */
8
9#include "AsyncCallQueue.h"
10#include "AsyncCall.h"
11
12AsyncCallQueue *AsyncCallQueue::TheInstance = 0;
13
14
15AsyncCallQueue::AsyncCallQueue(): theHead(NULL), theTail(NULL)
16{
17}
18
19void 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.
34bool
35AsyncCallQueue::fire()
36{
37 const bool made = theHead != NULL;
38 while (theHead != NULL)
39 fireNext();
40 return made;
41}
42
43void
44AsyncCallQueue::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
57AsyncCallQueue &
58AsyncCallQueue::Instance()
59{
60 // TODO: how to remove this frequent check while supporting early calls?
26ac0430 61 if (!TheInstance)
cfa20cf5 62 TheInstance = new AsyncCallQueue();
63
64 return *TheInstance;
65}
66