/*
- * $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
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;
+ }
+}
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
/*
- * $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>
#if HAVE_SCHED_H
#include <sched.h>
#endif
+#include "comm.h"
#define RIDICULOUS_LENGTH 4096
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;
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)
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);
*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;
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;