[07/14] eal: interrupts close epoll fd on shutdown
Checks
Commit Message
Use pthread callbacks to ensure that the epoll fd is closed
when rte_eal_cleanup is called.
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
lib/librte_eal/linux/eal/eal_interrupts.c | 26 ++++++++++++++++++-----
1 file changed, 21 insertions(+), 5 deletions(-)
@@ -1032,6 +1032,19 @@ eal_intr_handle_interrupts(int pfd, unsigned totalfds)
}
}
+
+/**
+ * Callback at end of intr_thread loop or if thread is cancelled
+ * that closes the epoll file descriptor
+ */
+static void
+eal_intr_thread_close(void *arg)
+{
+ int pfd = (int)(unsigned long)arg;
+
+ close(pfd);
+}
+
/**
* It builds/rebuilds up the epoll file descriptor with all the
* file descriptors being waited on. Then handles the interrupts.
@@ -1061,6 +1074,12 @@ eal_intr_thread_main(__rte_unused void *arg)
if (pfd < 0)
rte_panic("Cannot create epoll instance\n");
+ /* close pfd on thread exit or cancel_pop
+ * see man page for restrictions on this macro.
+ */
+ pthread_cleanup_push(eal_intr_thread_close,
+ (void *)(unsigned long)pfd);
+
pipe_event.data.fd = intr_pipe.readfd;
/**
* add pipe fd into wait list, this pipe is used to
@@ -1100,11 +1119,8 @@ eal_intr_thread_main(__rte_unused void *arg)
/* serve the interrupt */
eal_intr_handle_interrupts(pfd, numfds);
- /**
- * when we return, we need to rebuild the
- * list of fds to monitor.
- */
- close(pfd);
+ /* close pfd and rebuild the list */
+ pthread_cleanup_pop(1);
}
}