[dovecot-cvs] dovecot/src/lib ioloop-internal.h,1.7,1.8 ioloop-poll.c,1.14,1.15 ioloop-select.c,1.11,1.12 ioloop.c,1.16,1.17 ioloop.h,1.9,1.10 ostream-file.c,1.19,1.20 ostream.h,1.6,1.7

cras at procontrol.fi cras at procontrol.fi
Fri May 23 18:40:52 EEST 2003


Update of /home/cvs/dovecot/src/lib
In directory danu:/tmp/cvs-serv28910/lib

Modified Files:
	ioloop-internal.h ioloop-poll.c ioloop-select.c ioloop.c 
	ioloop.h ostream-file.c ostream.h 
Log Message:
Removed I/O priorities. They were pretty much useless and were just getting
in way.



Index: ioloop-internal.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib/ioloop-internal.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- ioloop-internal.h	7 May 2003 12:21:02 -0000	1.7
+++ ioloop-internal.h	23 May 2003 14:40:50 -0000	1.8
@@ -18,10 +18,9 @@
 };
 
 struct io {
-	struct io *prev, *next;
+	struct io *next;
 
 	int fd;
-        int priority;
 	int condition;
 
 	unsigned int destroyed:1;
@@ -34,9 +33,10 @@
 	struct timeout *next;
 
 	struct timeval next_run;
-        int msecs;
-	int run_now;
-        int destroyed;
+        unsigned int msecs;
+
+	unsigned int run_now:1;
+	unsigned int destroyed:1;
 
 	timeout_callback_t *callback;
         void *context;
@@ -47,9 +47,9 @@
 void io_loop_handle_timeouts(struct ioloop *ioloop);
 
 /* call only when io->destroyed is TRUE */
-void io_destroy(struct ioloop *ioloop, struct io *io);
+void io_destroy(struct ioloop *ioloop, struct io **io_p);
 /* call only when timeout->destroyed is TRUE */
-void timeout_destroy(struct ioloop *ioloop, struct timeout *timeout);
+void timeout_destroy(struct ioloop *ioloop, struct timeout **timeout_p);
 
 /* I/O handler calls */
 void io_loop_handle_add(struct ioloop *ioloop, int fd, int condition);

Index: ioloop-poll.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib/ioloop-poll.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- ioloop-poll.c	23 May 2003 14:12:43 -0000	1.14
+++ ioloop-poll.c	23 May 2003 14:40:50 -0000	1.15
@@ -149,9 +149,9 @@
 	struct ioloop_handler_data *data = ioloop->handler_data;
         struct pollfd *pollfd;
         struct timeval tv;
-	struct io *io, *next;
+	struct io *io, **io_p;
 	unsigned int t_id;
-	int msecs, ret;
+	int msecs, ret, call;
 
         /* get the time left for next timeout task */
 	msecs = io_loop_get_wait_time(ioloop->timeouts, &tv, NULL);
@@ -168,53 +168,52 @@
 		return;
 	}
 
-	/* execute the I/O handlers in prioritized order */
-	for (io = ioloop->ios; io != NULL && ret > 0; io = next) {
-		next = io->next;
-
+	io_p = &ioloop->ios;
+	for (io = ioloop->ios; io != NULL && ret > 0; io = *io_p) {
 		if (io->destroyed) {
 			/* we were destroyed, and io->fd points to
 			   -1 now, so we can't know if there was any
 			   revents left. */
-			io_destroy(ioloop, io);
+			io_destroy(ioloop, io_p);
 			continue;
 		}
 
 		i_assert(io->fd >= 0);
 
 		pollfd = &data->fds[data->fd_index[io->fd]];
-		if (pollfd->revents == 0)
-			continue;
-		ret--;
+		if (pollfd->revents != 0) {
+			ret--;
 
-		if (pollfd->revents & POLLNVAL) {
-			i_error("invalid I/O fd %d, callback %p",
-				io->fd, (void *) io->callback);
-			pollfd->events &= ~POLLNVAL;
-			pollfd->revents &= ~POLLNVAL;
-			continue;
-		}
+			if (pollfd->revents & POLLNVAL) {
+				i_error("invalid I/O fd %d, callback %p",
+					io->fd, (void *) io->callback);
+				pollfd->events &= ~POLLNVAL;
+				pollfd->revents &= ~POLLNVAL;
+				call = FALSE;
+			} else if ((io->condition &
+				    (IO_READ|IO_WRITE)) == (IO_READ|IO_WRITE)) {
+				call = TRUE;
+				pollfd->revents = 0;
+			} else if (io->condition & IO_READ) {
+				call = (pollfd->revents & IO_POLL_INPUT) != 0;
+				pollfd->revents &= ~IO_POLL_INPUT;
+			} else if (io->condition & IO_WRITE) {
+				call = (pollfd->revents & IO_POLL_OUTPUT) != 0;
+				pollfd->revents &= ~IO_POLL_OUTPUT;
+			}
 
-		if ((io->condition &
-		     (IO_READ|IO_WRITE)) == (IO_READ|IO_WRITE)) {
-			pollfd->revents = 0;
-		} else if (io->condition & IO_READ) {
-			if ((pollfd->revents & IO_POLL_INPUT) == 0)
-				continue;
-			pollfd->revents &= ~IO_POLL_INPUT;
-		} else if (io->condition & IO_WRITE) {
-			if ((pollfd->revents & IO_POLL_OUTPUT) == 0)
-				continue;
-                        pollfd->revents &= ~IO_POLL_OUTPUT;
-		}
+			if (call) {
+				t_id = t_push();
+				io->callback(io->context);
+				if (t_pop() != t_id)
+					i_panic("Leaked a t_pop() call!");
 
-		t_id = t_push();
-		io->callback(io->context);
-		if (t_pop() != t_id)
-			i_panic("Leaked a t_pop() call!");
+				if (io->destroyed)
+					io_destroy(ioloop, io_p);
+			}
+		}
 
-		if (io->destroyed)
-			io_destroy(ioloop, io);
+		io_p = &io->next;
 	}
 }
 

Index: ioloop-select.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib/ioloop-select.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- ioloop-select.c	27 Jan 2003 01:44:34 -0000	1.11
+++ ioloop-select.c	23 May 2003 14:40:50 -0000	1.12
@@ -107,10 +107,8 @@
 		return;
 	}
 
-	/* execute the I/O handlers in prioritized order */
-	for (io = ioloop->ios; io != NULL && ret > 0; io = next) {
-		next = io->next;
-
+	io_p = &ioloop->ios;
+	for (io = ioloop->ios; io != NULL && ret > 0; io = *io_p) {
 		if (io->destroyed) {
 			/* we were destroyed, and io->fd points to -1 now. */
 			io_destroy(ioloop, io);
@@ -122,18 +120,19 @@
 		fd = io->fd;
 		condition = io->condition;
 
-		if (!io_check_condition(fd, condition))
-                        continue;
+		if (io_check_condition(fd, condition)) {
+			t_id = t_push();
+			io->callback(io->context);
+			if (t_pop() != t_id)
+				i_panic("Leaked a t_pop() call!");
 
-		t_id = t_push();
-		io->callback(io->context);
-		if (t_pop() != t_id)
-			i_panic("Leaked a t_pop() call!");
+			if (io->destroyed)
+				io_destroy(ioloop, io_p);
 
-		if (io->destroyed)
-			io_destroy(ioloop, io);
+			ret--;
+		}
 
-		ret--;
+		io_p = &io->next;
 	}
 }
 

Index: ioloop.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib/ioloop.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- ioloop.c	16 May 2003 17:14:54 -0000	1.16
+++ ioloop.c	23 May 2003 14:40:50 -0000	1.17
@@ -23,9 +23,6 @@
     SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
 
-/* FIXME: inserting io is slow if there's lots of them. I should add a linked
-   list of priorities pointing to first item in the list with the priority. */
-
 #include "lib.h"
 #include "ioloop-internal.h"
 
@@ -59,38 +56,7 @@
 	}
 }
 
-static void io_list_insert(struct ioloop *ioloop, struct io *io)
-{
-	struct io *prev, *next;
-
-        prev = NULL;
-	for (next = ioloop->ios; next != NULL; next = next->next) {
-		if (next->priority >= io->priority)
-                        break;
-                prev = next;
-	}
-
-	if (prev == NULL)
-                ioloop->ios = io;
-	else {
-		io->prev = prev;
-                prev->next = io;
-	}
-
-	if (next != NULL) {
-		io->next = next;
-		next->prev = io;
-	}
-}
-
-struct io *io_add(int fd, int condition, io_callback_t *callback, void *data)
-{
-	return io_add_priority(fd, IO_PRIORITY_DEFAULT,
-			       condition, callback, data);
-}
-
-struct io *io_add_priority(int fd, int priority, int condition,
-			   io_callback_t *callback, void *context)
+struct io *io_add(int fd, int condition, io_callback_t *callback, void *context)
 {
 	struct io *io;
 
@@ -99,7 +65,6 @@
 
 	io = p_new(current_ioloop->pool, struct io, 1);
 	io->fd = fd;
-	io->priority = priority;
         io->condition = condition;
 
 	io->callback = callback;
@@ -109,8 +74,9 @@
                 current_ioloop->highest_fd = io->fd;
 
         io_loop_handle_add(current_ioloop, io->fd, io->condition);
-	io_list_insert(current_ioloop, io);
 
+	io->next = current_ioloop->ios;
+	current_ioloop->ios = io;
 	return io;
 }
 
@@ -131,17 +97,12 @@
 	io->fd = -1;
 }
 
-void io_destroy(struct ioloop *ioloop, struct io *io)
+void io_destroy(struct ioloop *ioloop, struct io **io_p)
 {
-        /* remove from list */
-	if (io->prev == NULL)
-                ioloop->ios = io->next;
-	else
-		io->prev->next = io->next;
-
-	if (io->next != NULL)
-		io->next->prev = io->prev;
+	struct io *io = *io_p;
 
+	/* remove from list */
+	*io_p = io->next;
 	p_free(ioloop->pool, io);
 }
 
@@ -183,7 +144,7 @@
 	}
 }
 
-struct timeout *timeout_add(int msecs, timeout_callback_t *callback,
+struct timeout *timeout_add(unsigned int msecs, timeout_callback_t *callback,
 			    void *context)
 {
 	struct timeout *timeout;
@@ -207,16 +168,11 @@
 	timeout->destroyed = TRUE;
 }
 
-void timeout_destroy(struct ioloop *ioloop, struct timeout *timeout)
+void timeout_destroy(struct ioloop *ioloop, struct timeout **timeout_p)
 {
-	struct timeout **t;
-
-	for (t = &ioloop->timeouts; *t != NULL; t = &(*t)->next) {
-		if (*t == timeout)
-			break;
-	}
-	*t = timeout->next;
+        struct timeout *timeout = *timeout_p;
 
+	*timeout_p = timeout->next;
         p_free(ioloop->pool, timeout);
 }
 
@@ -256,7 +212,7 @@
 
 void io_loop_handle_timeouts(struct ioloop *ioloop)
 {
-	struct timeout *t, *next;
+	struct timeout *t, **t_p;
 	struct timeval tv;
         unsigned int t_id;
 
@@ -267,13 +223,13 @@
 	if (ioloop->timeouts == NULL || !ioloop->timeouts->run_now)
 		return;
 
-	for (t = ioloop->timeouts; t != NULL; t = next) {
-		next = t->next;
-
+	t_p = &ioloop->timeouts;
+	for (t = ioloop->timeouts; t != NULL; t = *t_p) {
 		if (t->destroyed) {
-                        timeout_destroy(ioloop, t);
+                        timeout_destroy(ioloop, t_p);
 			continue;
 		}
+		t_p = &t->next;
 
 		if (!t->run_now) {
 			io_loop_get_wait_time(t, &tv, &ioloop_timeval);
@@ -348,7 +304,7 @@
 				  (void *) io->callback, io->fd);
 			io_remove(io);
 		}
-		io_destroy(ioloop, io);
+		io_destroy(ioloop, &ioloop->ios);
 	}
 
 	while (ioloop->timeouts != NULL) {
@@ -358,7 +314,7 @@
 			i_warning("Timeout leak: %p", (void *) to->callback);
 			timeout_remove(to);
 		}
-                timeout_destroy(ioloop, to);
+                timeout_destroy(ioloop, &ioloop->timeouts);
 	}
 
         io_loop_handler_deinit(ioloop);

Index: ioloop.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib/ioloop.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- ioloop.h	7 May 2003 12:21:02 -0000	1.9
+++ ioloop.h	23 May 2003 14:40:50 -0000	1.10
@@ -7,10 +7,6 @@
 #define IO_READ			(1 << 0)
 #define IO_WRITE		(1 << 1)
 
-#define IO_PRIORITY_LOW		100
-#define IO_PRIORITY_DEFAULT	0
-#define IO_PRIORITY_HIGH	-100
-
 struct io;
 struct timeout;
 struct ioloop;
@@ -28,12 +24,10 @@
    but make sure you don't create multiple handlers of same type, it's not
    checked and removing one will stop the other from working as well. */
 struct io *io_add(int fd, int condition, io_callback_t *callback, void *context);
-struct io *io_add_priority(int fd, int priority, int condition,
-			   io_callback_t *callback, void *context);
 void io_remove(struct io *io);
 
 /* Timeout handlers */
-struct timeout *timeout_add(int msecs, timeout_callback_t *callback,
+struct timeout *timeout_add(unsigned int msecs, timeout_callback_t *callback,
 			    void *context);
 void timeout_remove(struct timeout *timeout);
 

Index: ostream-file.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib/ostream-file.c,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- ostream-file.c	19 May 2003 06:35:02 -0000	1.19
+++ ostream-file.c	23 May 2003 14:40:50 -0000	1.20
@@ -57,7 +57,6 @@
 	struct _ostream ostream;
 
 	int fd;
-	int priority;
 	struct io *io;
 
 	unsigned char *buffer; /* ring-buffer */
@@ -476,9 +475,8 @@
 
 	if (sent != 0 && fstream->io == NULL &&
 	    !fstream->corked && !fstream->file) {
-		fstream->io = io_add_priority(fstream->fd, fstream->priority,
-					      IO_WRITE, stream_send_io,
-					      fstream);
+		fstream->io = io_add(fstream->fd, IO_WRITE, stream_send_io,
+				     fstream);
 	}
 
 	i_assert(!STREAM_IS_BLOCKING(fstream) || sent == size);
@@ -840,7 +838,7 @@
 
 struct ostream *
 o_stream_create_file(int fd, pool_t pool, size_t max_buffer_size,
-		     int priority, int autoclose_fd)
+		     int autoclose_fd)
 {
 	struct file_ostream *fstream;
 	struct ostream *ostream;
@@ -849,7 +847,6 @@
 
 	fstream = p_new(pool, struct file_ostream, 1);
 	fstream->fd = fd;
-	fstream->priority = priority;
 	fstream->max_buffer_size = max_buffer_size;
 	fstream->autoclose_fd = autoclose_fd;
 	fstream->optimal_block_size = DEFAULT_OPTIMAL_BLOCK_SIZE;

Index: ostream.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib/ostream.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- ostream.h	19 Feb 2003 19:50:22 -0000	1.6
+++ ostream.h	23 May 2003 14:40:50 -0000	1.7
@@ -12,7 +12,7 @@
 
 struct ostream *
 o_stream_create_file(int fd, pool_t pool, size_t max_buffer_size,
-		     int priority, int autoclose_fd);
+		     int autoclose_fd);
 
 /* Reference counting. References start from 1, so calling o_stream_unref()
    destroys the stream if o_stream_ref() is never used. */



More information about the dovecot-cvs mailing list