Convert the main event loop to use the threading subsystem. The main
process now registers passt_worker() as thread #0 and starts it through
the threading infrastructure instead of running a manual epoll_wait loop.
Signed-off-by: Laurent Vivier
---
passt.c | 20 ++++----------------
threading.c | 3 ---
2 files changed, 4 insertions(+), 19 deletions(-)
diff --git a/passt.c b/passt.c
index 8a06838c5ed8..2cedb7ba0756 100644
--- a/passt.c
+++ b/passt.c
@@ -333,8 +333,7 @@ static void passt_worker(void *opaque, int nfds, struct epoll_event *events)
*/
int main(int argc, char **argv)
{
- struct epoll_event events[NUM_EPOLL_EVENTS];
- int nfds, devnull_fd = -1, fd;
+ int devnull_fd = -1, fd;
struct ctx *c = &passt_ctx;
struct rlimit limit;
struct timespec now;
@@ -377,9 +376,7 @@ int main(int argc, char **argv)
madvise(pkt_buf, sizeof(pkt_buf), MADV_HUGEPAGE);
threading_init();
- c->epollfd = epoll_create1(EPOLL_CLOEXEC);
- if (c->epollfd == -1)
- die_perror("Failed to create epoll file descriptor");
+ c->epollfd = threading_epollfd(THREADING_ID_DEFAULT);
if (getrlimit(RLIMIT_NOFILE, &limit))
die_perror("Failed to get maximum value of open files limit");
@@ -449,15 +446,6 @@ int main(int argc, char **argv)
isolate_postfork(c);
-loop:
- /* NOLINTBEGIN(bugprone-branch-clone): intervals can be the same */
- /* cppcheck-suppress [duplicateValueTernary, unmatchedSuppression] */
- nfds = epoll_wait(c->epollfd, events, NUM_EPOLL_EVENTS, TIMER_INTERVAL);
- /* NOLINTEND(bugprone-branch-clone) */
- if (nfds == -1 && errno != EINTR)
- die_perror("epoll_wait() failed in main loop");
-
- passt_worker(c, nfds, events);
-
- goto loop;
+ threading_worker_set(THREADING_ID_DEFAULT, passt_worker, c);
+ threading_start_thread(THREADING_ID_DEFAULT);
}
diff --git a/threading.c b/threading.c
index fd5b30ed7ff6..e1ed644f5864 100644
--- a/threading.c
+++ b/threading.c
@@ -66,7 +66,6 @@ void threading_init(void)
*
* Return: 0 on success, -1 if thread index is invalid
*/
-/* cppcheck-suppress unusedFunction */
int threading_worker_set(unsigned int threadid,
void (*worker)(void *, int, struct epoll_event *),
void *opaque)
@@ -90,7 +89,6 @@ int threading_worker_set(unsigned int threadid,
*
* Return: epoll file descriptor for the specified thread, -1 if index invalid
*/
-/* cppcheck-suppress unusedFunction */
int threading_epollfd(unsigned int threadid)
{
if (threadid >= ARRAY_SIZE(threads))
@@ -135,7 +133,6 @@ static void *threading_worker(void *opaque)
*
* #syscalls rt_sigaction rt_sigprocmask mprotect getrandom brk clone3 rseq set_robust_list clock_nanosleep
*/
-/* cppcheck-suppress unusedFunction */
void threading_start_thread(unsigned int threadid)
{
struct threading_context *tc;
--
2.54.0