Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
lihuiba committed Jun 1, 2024
1 parent 821edda commit d112665
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion io/fd-events.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
13 changes: 9 additions & 4 deletions photon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
5 changes: 3 additions & 2 deletions test/ci-tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit d112665

Please sign in to comment.