Skip to content

Commit

Permalink
SystemLayerImplSelect: consistently use #if/#elif for DISPATCH vs LIBEV
Browse files Browse the repository at this point in the history
- as discussed in #22043
- also add conditional definition for `ev_io_modify()` required for older libev versions (taken from current libev source, blown up to multiline by clang-format)
  • Loading branch information
plan44 committed Aug 29, 2022
1 parent 6a0d64c commit 5d66185
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions src/system/SystemLayerImplSelect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@
#define PTHREAD_NULL 0
#endif // CHIP_SYSTEM_CONFIG_POSIX_LOCKING && !defined(PTHREAD_NULL)

#if CHIP_SYSTEM_CONFIG_USE_LIBEV
// older libev do not yet have ev_io_modify
#ifndef ev_io_modify
#define ev_io_modify(ev, events_) \
do \
{ \
(ev)->events = ((ev)->events & EV__IOFDSET) | (events_); \
} while (0)
#endif // ev_io_modify
#endif // CHIP_SYSTEM_CONFIG_USE_LIBEV

namespace chip {
namespace System {

Expand Down Expand Up @@ -169,8 +180,7 @@ CHIP_ERROR LayerImplSelect::StartTimer(Clock::Timeout delay, TimerCompleteCallba
dispatch_resume(timerSource);
return CHIP_NO_ERROR;
}
#endif // CHIP_SYSTEM_CONFIG_USE_DISPATCH
#if CHIP_SYSTEM_CONFIG_USE_LIBEV
#elif CHIP_SYSTEM_CONFIG_USE_LIBEV
if (mLibEvLoopP == nullptr)
{
chipDie();
Expand All @@ -189,7 +199,7 @@ CHIP_ERROR LayerImplSelect::StartTimer(Clock::Timeout delay, TimerCompleteCallba
Signal();
}
return CHIP_NO_ERROR;
#endif // !CHIP_SYSTEM_CONFIG_USE_LIBEV
#endif // CHIP_SYSTEM_CONFIG_USE_DISPATCH/LIBEV
}

void LayerImplSelect::CancelTimer(TimerCompleteCallback onComplete, void * appState)
Expand Down Expand Up @@ -230,11 +240,12 @@ CHIP_ERROR LayerImplSelect::ScheduleWork(TimerCompleteCallback onComplete, void
});
return CHIP_NO_ERROR;
}
#endif // CHIP_SYSTEM_CONFIG_USE_DISPATCH
#if CHIP_SYSTEM_CONFIG_USE_LIBEV
#elif CHIP_SYSTEM_CONFIG_USE_LIBEV
// just a timer with no delay
return StartTimer(Clock::Timeout(0), onComplete, appState);
#else
#endif // CHIP_SYSTEM_CONFIG_USE_DISPATCH/LIBEV
#if !CHIP_SYSTEM_CONFIG_USE_LIBEV
// Note: DISPATCH needs this code as a fallback, LIBEV does not
CancelTimer(onComplete, appState);

TimerList::Node * timer = mTimerPool.Create(*this, SystemClock().GetMonotonicTimestamp(), onComplete, appState);
Expand Down Expand Up @@ -587,14 +598,14 @@ void LayerImplSelect::HandleEvents()
}

#if CHIP_SYSTEM_CONFIG_USE_DISPATCH

void LayerImplSelect::HandleTimerComplete(TimerList::Node * timer)
{
mTimerList.Remove(timer);
mTimerPool.Invoke(timer);
}
#endif
#elif CHIP_SYSTEM_CONFIG_USE_LIBEV

#if CHIP_SYSTEM_CONFIG_USE_LIBEV
void LayerImplSelect::HandleLibEvTimer(EV_P_ struct ev_timer * t, int revents)
{
TimerList::Node * timer = static_cast<TimerList::Node *>(t->data);
Expand Down Expand Up @@ -625,7 +636,8 @@ void LayerImplSelect::HandleLibEvIoWatcher(EV_P_ struct ev_io * i, int revents)
}
}
}
#endif // CHIP_SYSTEM_CONFIG_USE_LIBEV

#endif // CHIP_SYSTEM_CONFIG_USE_DISPATCH/LIBEV

void LayerImplSelect::SocketWatch::Clear()
{
Expand Down

0 comments on commit 5d66185

Please sign in to comment.