diff --git a/io/fd-events.h b/io/fd-events.h index d201a5be..71fa2e4f 100644 --- a/io/fd-events.h +++ b/io/fd-events.h @@ -138,7 +138,7 @@ DECLARE_MASTER_AND_CASCADING_ENGINE(select); DECLARE_MASTER_AND_CASCADING_ENGINE(iouring); DECLARE_MASTER_AND_CASCADING_ENGINE(kqueue); -inline int fd_events_init(int master_engine) { +inline int fd_events_init(uint64_t master_engine) { switch (master_engine) { #ifdef __linux__ case INIT_EVENT_EPOLL: diff --git a/photon.cpp b/photon.cpp index c3162a88..25c04835 100644 --- a/photon.cpp +++ b/photon.cpp @@ -39,20 +39,25 @@ static thread_local uint64_t g_event_engine = 0, g_io_engine = 0; #define FINI_IO(name, prefix) if (INIT_IO_##name & g_io_engine) { prefix##_fini(); } // Try to init master engine with the recommended order +static const uint8_t recommended_order[] = { #if defined(__linux__) -static const int recommended_order[] = {INIT_EVENT_EPOLL, INIT_EVENT_IOURING, INIT_EVENT_SELECT}; + __builtin_ctz(INIT_EVENT_EPOLL), __builtin_ctz(INIT_EVENT_IOURING), __builtin_ctz(INIT_EVENT_SELECT)}; #else // macOS, FreeBSD ... -static const int recommended_order[] = {INIT_EVENT_KQUEUE, INIT_EVENT_SELECT}; + __builtin_ctz(INIT_EVENT_KQUEUE), __builtin_ctz(INIT_EVENT_SELECT)}; #endif int __photon_init(uint64_t event_engine, uint64_t io_engine) { if (vcpu_init() < 0) return -1; - if (event_engine != INIT_EVENT_NONE) { + const uint64_t ALL_ENGINES = INIT_EVENT_EPOLL | + INIT_EVENT_IOURING | INIT_EVENT_KQUEUE | + INIT_EVENT_SELECT | INIT_EVENT_IOCP; + if (event_engine & ALL_ENGINES) { bool ok = false; for (auto each : recommended_order) { - if ((each & event_engine) && fd_events_init(each) == 0) { + auto x = 1ul << each; + if ((x & event_engine) && fd_events_init(x) == 0) { ok = true; break; } diff --git a/test/ci-tools.cpp b/test/ci-tools.cpp index 5453ad65..24c50fe5 100644 --- a/test/ci-tools.cpp +++ b/test/ci-tools.cpp @@ -73,8 +73,9 @@ int init(uint64_t event_engine, uint64_t io_engine) { LOG_INFO("argument specified: ` (`)", get_engine_names(arg_specified), arg_specified); LOG_INFO("environment specified: '`'", _engine_name); if (_engine && arg_specified) { - event_engine &= ~all_engines | _engine; - LOG_INFO("environment overridden: ", get_engine_names(event_engine & all_engines)); + event_engine &= ~all_engines; + event_engine |= _engine; + LOG_INFO("event engine overridden to: ", get_engine_names(event_engine & all_engines)); } return __photon_init(event_engine, io_engine); }