1
0
mirror of https://github.com/samba-team/samba.git synced 2025-03-11 16:58:40 +03:00

tevent: split out a tevent_common_fd_disarm() helper

It means tevent_trace_fd_callback(TEVENT_EVENT_TRACE_DETACH)
is always called and similar future changes are only
needed in one place.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
This commit is contained in:
Stefan Metzmacher 2023-08-31 18:09:28 +02:00 committed by Ralph Boehme
parent 7672a29feb
commit 95d6600a06
5 changed files with 25 additions and 37 deletions

View File

@ -410,10 +410,7 @@ int tevent_common_context_destructor(struct tevent_context *ev)
for (fd = ev->fd_events; fd; fd = fn) {
fn = fd->next;
tevent_trace_fd_callback(fd->event_ctx, fd, TEVENT_EVENT_TRACE_DETACH);
fd->wrapper = NULL;
fd->event_ctx = NULL;
DLIST_REMOVE(ev->fd_events, fd);
tevent_common_fd_disarm(fd);
}
ev->last_zero_timer = NULL;

View File

@ -316,12 +316,8 @@ static int epoll_add_multiplex_fd(struct epoll_event_context *epoll_ev,
"EPOLL_CTL_MOD EBADF for "
"add_fde[%p] mpx_fde[%p] fd[%d] - disabling\n",
add_fde, mpx_fde, add_fde->fd);
DLIST_REMOVE(epoll_ev->ev->fd_events, mpx_fde);
mpx_fde->wrapper = NULL;
mpx_fde->event_ctx = NULL;
DLIST_REMOVE(epoll_ev->ev->fd_events, add_fde);
add_fde->wrapper = NULL;
add_fde->event_ctx = NULL;
tevent_common_fd_disarm(mpx_fde);
tevent_common_fd_disarm(add_fde);
return 0;
} else if (ret != 0) {
return ret;
@ -382,13 +378,9 @@ static void epoll_add_event(struct epoll_event_context *epoll_ev, struct tevent_
"EPOLL_CTL_ADD EBADF for "
"fde[%p] mpx_fde[%p] fd[%d] - disabling\n",
fde, mpx_fde, fde->fd);
DLIST_REMOVE(epoll_ev->ev->fd_events, fde);
fde->wrapper = NULL;
fde->event_ctx = NULL;
tevent_common_fd_disarm(fde);
if (mpx_fde != NULL) {
DLIST_REMOVE(epoll_ev->ev->fd_events, mpx_fde);
mpx_fde->wrapper = NULL;
mpx_fde->event_ctx = NULL;
tevent_common_fd_disarm(mpx_fde);
}
return;
} else if (ret != 0 && errno == EEXIST && mpx_fde == NULL) {
@ -459,13 +451,9 @@ static void epoll_del_event(struct epoll_event_context *epoll_ev, struct tevent_
"EPOLL_CTL_DEL EBADF for "
"fde[%p] mpx_fde[%p] fd[%d] - disabling\n",
fde, mpx_fde, fde->fd);
DLIST_REMOVE(epoll_ev->ev->fd_events, fde);
fde->wrapper = NULL;
fde->event_ctx = NULL;
tevent_common_fd_disarm(fde);
if (mpx_fde != NULL) {
DLIST_REMOVE(epoll_ev->ev->fd_events, mpx_fde);
mpx_fde->wrapper = NULL;
mpx_fde->event_ctx = NULL;
tevent_common_fd_disarm(mpx_fde);
}
return;
} else if (ret != 0) {
@ -510,13 +498,9 @@ static void epoll_mod_event(struct epoll_event_context *epoll_ev, struct tevent_
"EPOLL_CTL_MOD EBADF for "
"fde[%p] mpx_fde[%p] fd[%d] - disabling\n",
fde, mpx_fde, fde->fd);
DLIST_REMOVE(epoll_ev->ev->fd_events, fde);
fde->wrapper = NULL;
fde->event_ctx = NULL;
tevent_common_fd_disarm(fde);
if (mpx_fde != NULL) {
DLIST_REMOVE(epoll_ev->ev->fd_events, mpx_fde);
mpx_fde->wrapper = NULL;
mpx_fde->event_ctx = NULL;
tevent_common_fd_disarm(mpx_fde);
}
return;
} else if (ret != 0) {

View File

@ -561,3 +561,16 @@ void tevent_trace_immediate_callback(struct tevent_context *ev,
void tevent_trace_queue_callback(struct tevent_context *ev,
struct tevent_queue_entry *qe,
enum tevent_event_trace_point);
#include "tevent_dlinklist.h"
static inline void tevent_common_fd_disarm(struct tevent_fd *fde)
{
if (fde->event_ctx != NULL) {
tevent_trace_fd_callback(fde->event_ctx, fde,
TEVENT_EVENT_TRACE_DETACH);
DLIST_REMOVE(fde->event_ctx->fd_events, fde);
fde->event_ctx = NULL;
}
fde->wrapper = NULL;
}

View File

@ -534,9 +534,7 @@ static int poll_event_loop_poll(struct tevent_context *ev,
fde, pfd->fd);
poll_ev->fdes[idx] = NULL;
poll_ev->deleted = true;
DLIST_REMOVE(ev->fd_events, fde);
fde->wrapper = NULL;
fde->event_ctx = NULL;
tevent_common_fd_disarm(fde);
continue;
}
@ -586,9 +584,7 @@ static int poll_event_loop_poll(struct tevent_context *ev,
poll_ev->fdes[i] = NULL;
poll_ev->deleted = true;
if (fde != NULL) {
DLIST_REMOVE(ev->fd_events, fde);
fde->wrapper = NULL;
fde->event_ctx = NULL;
tevent_common_fd_disarm(fde);
}
}
}

View File

@ -276,9 +276,7 @@ static int tevent_wrapper_context_destructor(struct tevent_context *wrap_ev)
tevent_fd_set_flags(fd, 0);
fd->wrapper = NULL;
fd->event_ctx = NULL;
DLIST_REMOVE(main_ev->fd_events, fd);
tevent_common_fd_disarm(fd);
}
for (te = main_ev->timer_events; te; te = tn) {