From a28817264e0aeef6d8b4781d8a39985e7be37c24 Mon Sep 17 00:00:00 2001 From: falkTX Date: Tue, 11 Oct 2022 15:37:01 +0100 Subject: [PATCH] Only use epoll on linux, clap posix-fd related Signed-off-by: falkTX --- source/backend/plugin/CarlaPluginCLAP.cpp | 33 +++++++++++------------ source/utils/CarlaThread.hpp | 4 --- 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/source/backend/plugin/CarlaPluginCLAP.cpp b/source/backend/plugin/CarlaPluginCLAP.cpp index 7cadfbeb4..0ea439d07 100644 --- a/source/backend/plugin/CarlaPluginCLAP.cpp +++ b/source/backend/plugin/CarlaPluginCLAP.cpp @@ -33,13 +33,12 @@ #include "water/misc/Time.h" #ifdef _POSIX_VERSION -# if defined(CARLA_OS_MAC) || defined(CARLA_OS_BSD) -# define CARLA_CLAP_POSIX_KQUEUE -# include -# include -# else +# if defined(CARLA_OS_LINUX) # define CARLA_CLAP_POSIX_EPOLL # include +# else +# include +# include # endif #endif @@ -2673,14 +2672,14 @@ protected: if (flags & (CLAP_POSIX_FD_READ|CLAP_POSIX_FD_WRITE)) { - #ifdef CARLA_CLAP_POSIX_KQUEUE - const int hostFd = ::kqueue(); - #else + #ifdef CARLA_CLAP_POSIX_EPOLL const int hostFd = ::epoll_create1(0); + #else + const int hostFd = ::kqueue(); #endif CARLA_SAFE_ASSERT_RETURN(hostFd >= 0, false); - #ifndef CARLA_CLAP_POSIX_KQUEUE + #ifdef CARLA_CLAP_POSIX_EPOLL struct epoll_event ev = {}; if (flags & CLAP_POSIX_FD_READ) ev.events |= EPOLLIN; @@ -2720,7 +2719,7 @@ protected: if (posixFD.flags == flags) return true; - #ifndef CARLA_CLAP_POSIX_KQUEUE + #ifdef CARLA_CLAP_POSIX_EPOLL struct epoll_event ev = {}; if (flags & CLAP_POSIX_FD_READ) ev.events |= EPOLLIN; @@ -2749,7 +2748,7 @@ protected: if (posixFD.pluginFd == fd) { - #ifndef CARLA_CLAP_POSIX_KQUEUE + #ifdef CARLA_CLAP_POSIX_EPOLL ::epoll_ctl(posixFD.hostFd, EPOLL_CTL_DEL, fd, nullptr); #endif ::close(posixFD.hostFd); @@ -3134,21 +3133,21 @@ private: { const HostPosixFileDescriptorDetails& posixFD(it.getValue(kPosixFileDescriptorFallback)); - #ifdef CARLA_CLAP_POSIX_KQUEUE + #ifdef CARLA_CLAP_POSIX_EPOLL + epoll_event event; + #else const int16_t filter = posixFD.flags & CLAP_POSIX_FD_WRITE ? EVFILT_WRITE : EVFILT_READ; struct kevent kev = {}, event; struct timespec timeout = {}; EV_SET(&kev, posixFD.pluginFd, filter, EV_ADD|EV_ENABLE, 0, 0, nullptr); - #else - epoll_event event; #endif for (int i=0; i<50; ++i) { - #ifdef CARLA_CLAP_POSIX_KQUEUE - switch (kevent(posixFD.hostFd, &kev, 1, &event, 1, &timeout)) - #else + #ifdef CARLA_CLAP_POSIX_EPOLL switch (::epoll_wait(posixFD.hostFd, &event, 1, 0)) + #else + switch (kevent(posixFD.hostFd, &kev, 1, &event, 1, &timeout)) #endif { case 1: diff --git a/source/utils/CarlaThread.hpp b/source/utils/CarlaThread.hpp index ef0d488ad..9701cb27f 100644 --- a/source/utils/CarlaThread.hpp +++ b/source/utils/CarlaThread.hpp @@ -22,10 +22,6 @@ #include "CarlaString.hpp" #include "CarlaProcessUtils.hpp" -#ifdef CARLA_OS_LINUX -# include -#endif - #ifdef CARLA_OS_WASM # error Threads do not work under wasm! #endif