tevent: let tevent_loop_once() just run one fd event
authorStefan Metzmacher <metze@samba.org>
Mon, 16 Mar 2009 11:34:23 +0000 (12:34 +0100)
committerStefan Metzmacher <metze@samba.org>
Tue, 17 Mar 2009 18:58:55 +0000 (19:58 +0100)
This makes the logic much simpler for the callers,
and matches the samba3 behavior.

If needed we can add performance tunning for tevent_loop_wait()
later.

metze

lib/tevent/tevent_epoll.c
lib/tevent/tevent_select.c
lib/tevent/tevent_standard.c

index b63d299d94272efec09d28c06c89a02720a7ce22..38a14883ccc13866cb519b19b30d78be0030b72b 100644 (file)
@@ -35,14 +35,6 @@ struct epoll_event_context {
        /* a pointer back to the generic event_context */
        struct tevent_context *ev;
 
-       /* this is changed by the destructors for the fd event
-          type. It is used to detect event destruction by event
-          handlers, which means the code that is calling the event
-          handler needs to assume that the linked list is no longer
-          valid
-       */
-       uint32_t destruction_count;
-
        /* when using epoll this is the handle from epoll_create */
        int epoll_fd;
 
@@ -242,9 +234,8 @@ static void epoll_change_event(struct epoll_event_context *epoll_ev, struct teve
 static int epoll_event_loop(struct epoll_event_context *epoll_ev, struct timeval *tvalp)
 {
        int ret, i;
-#define MAXEVENTS 32
+#define MAXEVENTS 1
        struct epoll_event events[MAXEVENTS];
-       uint32_t destruction_count = ++epoll_ev->destruction_count;
        int timeout = -1;
 
        if (epoll_ev->epoll_fd == -1) return -1;
@@ -305,9 +296,7 @@ static int epoll_event_loop(struct epoll_event_context *epoll_ev, struct timeval
                if (events[i].events & EPOLLOUT) flags |= TEVENT_FD_WRITE;
                if (flags) {
                        fde->handler(epoll_ev->ev, fde, flags, fde->private_data);
-                       if (destruction_count != epoll_ev->destruction_count) {
-                               break;
-                       }
+                       break;
                }
        }
 
@@ -351,8 +340,6 @@ static int epoll_event_fd_destructor(struct tevent_fd *fde)
 
                epoll_check_reopen(epoll_ev);
 
-               epoll_ev->destruction_count++;
-
                epoll_del_event(epoll_ev, fde);
        }
 
index cdddb601c42ce78094a46280d869958e8e660ea7..bbbb95fce8bf156dcf82618ce161552024d9baef 100644 (file)
@@ -38,10 +38,6 @@ struct select_event_context {
 
        /* information for exiting from the event loop */
        int exit_code;
-
-       /* this is incremented when the loop over events causes something which
-          could change the events yet to be processed */
-       uint32_t destruction_count;
 };
 
 /*
@@ -95,8 +91,6 @@ static int select_event_fd_destructor(struct tevent_fd *fde)
                if (select_ev->maxfd == fde->fd) {
                        select_ev->maxfd = EVENT_INVALID_MAXFD;
                }
-
-               select_ev->destruction_count++;
        }
 
        return tevent_common_fd_destructor(fde);
@@ -138,7 +132,6 @@ static int select_event_loop_select(struct select_event_context *select_ev, stru
        fd_set r_fds, w_fds;
        struct tevent_fd *fde;
        int selrtn;
-       uint32_t destruction_count = ++select_ev->destruction_count;
 
        /* we maybe need to recalculate the maxfd */
        if (select_ev->maxfd == EVENT_INVALID_MAXFD) {
@@ -200,15 +193,13 @@ static int select_event_loop_select(struct select_event_context *select_ev, stru
                        if (FD_ISSET(fde->fd, &w_fds)) flags |= TEVENT_FD_WRITE;
                        if (flags) {
                                fde->handler(select_ev->ev, fde, flags, fde->private_data);
-                               if (destruction_count != select_ev->destruction_count) {
-                                       break;
-                               }
+                               break;
                        }
                }
        }
 
        return 0;
-}              
+}
 
 /*
   do a single event loop using the events defined in ev 
index 73a45e8c20fe327d75d35b1b0fd1149c860f0f04..0ee99ca56b26bb0e4e2537b286cf65c1a9ecd5d0 100644 (file)
@@ -48,14 +48,6 @@ struct std_event_context {
        /* information for exiting from the event loop */
        int exit_code;
 
-       /* this is changed by the destructors for the fd event
-          type. It is used to detect event destruction by event
-          handlers, which means the code that is calling the event
-          handler needs to assume that the linked list is no longer
-          valid
-       */
-       uint32_t destruction_count;
-
        /* when using epoll this is the handle from epoll_create */
        int epoll_fd;
 
@@ -253,9 +245,8 @@ static void epoll_change_event(struct std_event_context *std_ev, struct tevent_f
 static int epoll_event_loop(struct std_event_context *std_ev, struct timeval *tvalp)
 {
        int ret, i;
-#define MAXEVENTS 8
+#define MAXEVENTS 1
        struct epoll_event events[MAXEVENTS];
-       uint32_t destruction_count = ++std_ev->destruction_count;
        int timeout = -1;
 
        if (std_ev->epoll_fd == -1) return -1;
@@ -316,9 +307,7 @@ static int epoll_event_loop(struct std_event_context *std_ev, struct timeval *tv
                if (events[i].events & EPOLLOUT) flags |= TEVENT_FD_WRITE;
                if (flags) {
                        fde->handler(std_ev->ev, fde, flags, fde->private_data);
-                       if (destruction_count != std_ev->destruction_count) {
-                               break;
-                       }
+                       break;
                }
        }
 
@@ -390,8 +379,6 @@ static int std_event_fd_destructor(struct tevent_fd *fde)
                        std_ev->maxfd = EVENT_INVALID_MAXFD;
                }
 
-               std_ev->destruction_count++;
-
                epoll_del_event(std_ev, fde);
        }
 
@@ -459,7 +446,6 @@ static int std_event_loop_select(struct std_event_context *std_ev, struct timeva
        fd_set r_fds, w_fds;
        struct tevent_fd *fde;
        int selrtn;
-       uint32_t destruction_count = ++std_ev->destruction_count;
 
        /* we maybe need to recalculate the maxfd */
        if (std_ev->maxfd == EVENT_INVALID_MAXFD) {
@@ -521,9 +507,7 @@ static int std_event_loop_select(struct std_event_context *std_ev, struct timeva
                        if (FD_ISSET(fde->fd, &w_fds)) flags |= TEVENT_FD_WRITE;
                        if (flags) {
                                fde->handler(std_ev->ev, fde, flags, fde->private_data);
-                               if (destruction_count != std_ev->destruction_count) {
-                                       break;
-                               }
+                               break;
                        }
                }
        }