From cfa20cf5e70e72c956e98143263f76229ba55886 Mon Sep 17 00:00:00 2001 From: rousskov <> Date: Wed, 13 Feb 2008 13:01:39 +0000 Subject: [PATCH] Merging async-call branch changes to HEAD: Adding forgotten source files. --- src/AsyncCallQueue.cc | 66 +++++++++++++++++++++++++++++++++++++++++++ src/AsyncCallQueue.h | 40 ++++++++++++++++++++++++++ 2 files changed, 106 insertions(+) create mode 100644 src/AsyncCallQueue.cc create mode 100644 src/AsyncCallQueue.h diff --git a/src/AsyncCallQueue.cc b/src/AsyncCallQueue.cc new file mode 100644 index 0000000000..4d23b69692 --- /dev/null +++ b/src/AsyncCallQueue.cc @@ -0,0 +1,66 @@ + +/* + * $Id: AsyncCallQueue.cc,v 1.1 2008/02/13 06:01:39 rousskov Exp $ + * + * DEBUG: section 41 Event Processing + * + */ + +#include "AsyncCallQueue.h" +#include "AsyncCall.h" + +AsyncCallQueue *AsyncCallQueue::TheInstance = 0; + + +AsyncCallQueue::AsyncCallQueue(): theHead(NULL), theTail(NULL) +{ +} + +void AsyncCallQueue::schedule(AsyncCall::Pointer &call) +{ + assert(call != NULL); + assert(!call->theNext); + if (theHead != NULL) { // append + assert(!theTail->theNext); + theTail->theNext = call; + theTail = call; + } else { // create queue from cratch + theHead = theTail = call; + } +} + +// Fire all scheduled calls; returns true if at least one call was fired. +// The calls may be added while the current call is in progress. +bool +AsyncCallQueue::fire() +{ + const bool made = theHead != NULL; + while (theHead != NULL) + fireNext(); + return made; +} + +void +AsyncCallQueue::fireNext() +{ + AsyncCall::Pointer call = theHead; + theHead = call->theNext; + call->theNext = NULL; + if (theTail == call) + theTail = NULL; + + debugs(call->debugSection, call->debugLevel, "entering " << *call); + call->make(); + debugs(call->debugSection, call->debugLevel, "leaving " << *call); +} + +AsyncCallQueue & +AsyncCallQueue::Instance() +{ + // TODO: how to remove this frequent check while supporting early calls? + if (!TheInstance) + TheInstance = new AsyncCallQueue(); + + return *TheInstance; +} + diff --git a/src/AsyncCallQueue.h b/src/AsyncCallQueue.h new file mode 100644 index 0000000000..75ff36c5e1 --- /dev/null +++ b/src/AsyncCallQueue.h @@ -0,0 +1,40 @@ + +/* + * $Id: AsyncCallQueue.h,v 1.1 2008/02/13 06:01:39 rousskov Exp $ + * + */ + +#ifndef SQUID_ASYNCCALLQUEUE_H +#define SQUID_ASYNCCALLQUEUE_H + +#include "squid.h" +#include "AsyncCall.h" + +//class AsyncCall; + +// The queue of asynchronous calls. All calls are fired during a single main +// loop iteration until the queue is exhausted +class AsyncCallQueue +{ +public: + // there is only one queue + static AsyncCallQueue &Instance(); + + // make this async call when we get a chance + void schedule(AsyncCall::Pointer &call); + + // fire all scheduled calls; returns true if at least one was fired + bool fire(); + +private: + AsyncCallQueue(); + + void fireNext(); + + AsyncCall::Pointer theHead; + AsyncCall::Pointer theTail; + + static AsyncCallQueue *TheInstance; +}; + +#endif /* SQUID_ASYNCCALLQUEUE_H */ -- 2.47.2