]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Merging async-call branch changes to HEAD:
authorrousskov <>
Wed, 13 Feb 2008 13:01:39 +0000 (13:01 +0000)
committerrousskov <>
Wed, 13 Feb 2008 13:01:39 +0000 (13:01 +0000)
Adding forgotten source files.

src/AsyncCallQueue.cc [new file with mode: 0644]
src/AsyncCallQueue.h [new file with mode: 0644]

diff --git a/src/AsyncCallQueue.cc b/src/AsyncCallQueue.cc
new file mode 100644 (file)
index 0000000..4d23b69
--- /dev/null
@@ -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 (file)
index 0000000..75ff36c
--- /dev/null
@@ -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 */