~clint-fewbar/ubuntu/precise/squid3/ignore-sighup-early

« back to all changes in this revision

Viewing changes to src/base/AsyncCallQueue.cc

  • Committer: Bazaar Package Importer
  • Author(s): Luigi Gangitano
  • Date: 2010-05-04 11:15:49 UTC
  • mfrom: (1.3.1 upstream)
  • mto: (20.3.1 squeeze) (21.2.1 sid)
  • mto: This revision was merged to the branch mainline in revision 21.
  • Revision ID: james.westby@ubuntu.com-20100504111549-1apjh2g5sndki4te
Tags: upstream-3.1.3
ImportĀ upstreamĀ versionĀ 3.1.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/*
 
3
 * $Id$
 
4
 *
 
5
 * DEBUG: section 41    Event Processing
 
6
 *
 
7
 */
 
8
 
 
9
#include "base/AsyncCallQueue.h"
 
10
#include "base/AsyncCall.h"
 
11
 
 
12
AsyncCallQueue *AsyncCallQueue::TheInstance = 0;
 
13
 
 
14
 
 
15
AsyncCallQueue::AsyncCallQueue(): theHead(NULL), theTail(NULL)
 
16
{
 
17
}
 
18
 
 
19
void 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.
 
34
bool
 
35
AsyncCallQueue::fire()
 
36
{
 
37
    const bool made = theHead != NULL;
 
38
    while (theHead != NULL)
 
39
        fireNext();
 
40
    return made;
 
41
}
 
42
 
 
43
void
 
44
AsyncCallQueue::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
 
 
57
AsyncCallQueue &
 
58
AsyncCallQueue::Instance()
 
59
{
 
60
    // TODO: how to remove this frequent check while supporting early calls?
 
61
    if (!TheInstance)
 
62
        TheInstance = new AsyncCallQueue();
 
63
 
 
64
    return *TheInstance;
 
65
}
 
66