]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
extract async completion notification
authorrobertc <>
Thu, 9 Jan 2003 19:27:14 +0000 (19:27 +0000)
committerrobertc <>
Thu, 9 Jan 2003 19:27:14 +0000 (19:27 +0000)
src/comm.cc
src/comm.h
src/fs/aufs/aiops.cc

index 51e6880e1fe6537cae4b9178e8e3c55b40e31cf1..acbbc80d00ba9887caf48673cd812215c8bf3d65 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: comm.cc,v 1.360 2002/12/06 23:19:15 hno Exp $
+ * $Id: comm.cc,v 1.361 2003/01/09 12:27:14 robertc Exp $
  *
  * DEBUG: section 5     Socket Functions
  * AUTHOR: Harvest Derived
@@ -1885,3 +1885,46 @@ comm_accept(int fd, IOACB *handler, void *handler_data)
        commSetSelect(fd, COMM_SELECT_READ, comm_accept_try, NULL, 0);
 #endif
 }
+
+void CommIO::Initialise()
+{
+    /* Initialize done pipe signal */
+    int DonePipe[2];
+    pipe(DonePipe);
+    DoneFD = DonePipe[1];
+    DoneReadFD = DonePipe[0];
+    fd_open(DonePipe[0], FD_PIPE, "async-io completetion event: main");
+    fd_open(DonePipe[1], FD_PIPE, "async-io completetion event: threads");
+    commSetNonBlocking(DonePipe[0]);
+    commSetNonBlocking(DonePipe[1]);
+    commSetSelect(DonePipe[0], COMM_SELECT_READ, NULLFDHandler, NULL, 0);
+    Initialised = true;
+}
+
+bool CommIO::Initialised = false;
+bool CommIO::DoneSignalled = false;
+int CommIO::DoneFD = -1;
+int CommIO::DoneReadFD = -1;
+
+void
+CommIO::FlushPipe()
+{
+    char buf[256];
+    read(DoneReadFD, buf, sizeof(buf));
+}
+
+void
+CommIO::NULLFDHandler(int fd, void *data)
+{
+    FlushPipe();
+    commSetSelect(fd, COMM_SELECT_READ, NULLFDHandler, NULL, 0);
+}
+
+void
+CommIO::ResetNotifications() 
+{
+    if (DoneSignalled) {
+       FlushPipe();
+       DoneSignalled = false;
+    }
+}
index 7808d354c4049bc022ebfd01de98d48ee410bf96..6ce1bfbf695ceea9fc70ce7da4634fb0cb3247c3 100644 (file)
@@ -20,4 +20,30 @@ extern void comm_accept_setcheckperiod(int fd, int mdelay);
 
 extern void comm_write(int s, const char *buf, size_t len, IOWCB *callback, void *callback_data);
 
+/* Where should this belong? */
+class CommIO {
+public:
+  static inline void NotifyIOCompleted();
+  static void ResetNotifications();
+  static void Initialise();
+private:
+  static void NULLFDHandler(int, void *);
+  static void FlushPipe();
+  static bool Initialised;
+  static bool DoneSignalled;
+  static int DoneFD;
+  static int DoneReadFD;
+};
+
+/* Inline code. TODO: make structued approach to inlining */
+void
+CommIO::NotifyIOCompleted() {
+    if (!Initialised)
+       Initialise();
+    if (!DoneSignalled) {
+       DoneSignalled = true;
+       write(DoneFD, "!", 1);
+    }
+};
+
 #endif
index 6dfda731668273d08ab6c47a77b9d85573c05429..d397b5ffa377c3c7efda60b3700329f908733763 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: aiops.cc,v 1.20 2003/01/09 11:45:49 hno Exp $
+ * $Id: aiops.cc,v 1.21 2003/01/09 12:27:18 robertc Exp $
  *
  * DEBUG: section 43    AIOPS
  * AUTHOR: Stewart Forster <slf@connect.com.au>
@@ -46,6 +46,7 @@
 #if HAVE_SCHED_H
 #include       <sched.h>
 #endif
+#include "comm.h"
 
 #define RIDICULOUS_LENGTH      4096
 
@@ -146,9 +147,6 @@ static struct {
 
     NULL, &done_requests.head
 };
-static int done_fd = 0;
-static int done_fd_read = 0;
-static int done_signalled = 0;
 static pthread_attr_t globattr;
 #if HAVE_SCHED_H
 static struct sched_param globsched;
@@ -224,19 +222,10 @@ squidaio_xstrfree(char *str)
        xfree(str);
 }
 
-static void
-squidaio_fdhandler(int fd, void *data)
-{
-    char junk[256];
-    read(done_fd_read, junk, sizeof(junk));
-    commSetSelect(fd, COMM_SELECT_READ, squidaio_fdhandler, NULL, 0);
-}
-
 static void
 squidaio_init(void)
 {
     int i;
-    int done_pipe[2];
     squidaio_thread_t *threadp;
 
     if (squidaio_initialised)
@@ -280,16 +269,6 @@ squidaio_init(void)
     done_queue.requests = 0;
     done_queue.blocked = 0;
 
-    /* Initialize done pipe signal */
-    pipe(done_pipe);
-    done_fd = done_pipe[1];
-    done_fd_read = done_pipe[0];
-    fd_open(done_pipe[0], FD_PIPE, "async-io completetion event: main");
-    fd_open(done_pipe[1], FD_PIPE, "async-io completetion event: threads");
-    commSetNonBlocking(done_pipe[0]);
-    commSetNonBlocking(done_pipe[1]);
-    commSetSelect(done_pipe[0], COMM_SELECT_READ, squidaio_fdhandler, NULL, 0);
-
     /* Create threads and get them to sit in their wait loop */
     squidaio_thread_pool = memPoolCreate("aio_thread", sizeof(squidaio_thread_t));
     assert(NUMTHREADS);
@@ -411,10 +390,7 @@ squidaio_thread_loop(void *ptr)
        *done_queue.tailp = request;
        done_queue.tailp = &request->next;
        pthread_mutex_unlock(&done_queue.mutex);
-       if (!done_signalled) {
-           done_signalled = 1;
-           write(done_fd, "!", 1);
-       }
+       CommIO::NotifyIOCompleted();
        threadp->requests++;
     }                          /* while forever */
     return NULL;
@@ -829,11 +805,7 @@ squidaio_poll_done(void)
   AIO_REPOLL:
     request = done_requests.head;
     if (request == NULL && !polled) {
-       if (done_signalled) {
-           char junk[256];
-           read(done_fd_read, junk, sizeof(junk));
-           done_signalled = 0;
-       }
+       CommIO::ResetNotifications();
        squidaio_poll_queues();
        polled = 1;
        request = done_requests.head;