-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove the dependency from TimeSystem to libevent by using the Event:…
…:Scheduler abstraction as a delegate. (#6240) Description: SimulatedTimeSystem and TimeSystem should not directly depend on libevent; they just need to be able to schedule events. This PR adds an abstraction boundary using the existing Scheduler interface. Risk Level: low -- just a refactor Testing: //test/... Docs Changes: n/a Release Notes: n/a Fixes #Issue: #5820 Signed-off-by: Joshua Marantz <jmarantz@google.com>
- Loading branch information
Showing
17 changed files
with
165 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include "common/event/libevent_scheduler.h" | ||
|
||
#include "common/common/assert.h" | ||
#include "common/event/timer_impl.h" | ||
|
||
namespace Envoy { | ||
namespace Event { | ||
|
||
LibeventScheduler::LibeventScheduler() : libevent_(event_base_new()) { | ||
// The dispatcher won't work as expected if libevent hasn't been configured to use threads. | ||
RELEASE_ASSERT(Libevent::Global::initialized(), ""); | ||
} | ||
|
||
TimerPtr LibeventScheduler::createTimer(const TimerCb& cb) { | ||
return std::make_unique<TimerImpl>(libevent_, cb); | ||
}; | ||
|
||
void LibeventScheduler::nonBlockingLoop() { event_base_loop(libevent_.get(), EVLOOP_NONBLOCK); } | ||
|
||
void LibeventScheduler::blockingLoop() { event_base_loop(libevent_.get(), 0); } | ||
|
||
void LibeventScheduler::loopExit() { event_base_loopexit(libevent_.get(), nullptr); } | ||
|
||
} // namespace Event | ||
} // namespace Envoy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#pragma once | ||
|
||
#include "envoy/event/timer.h" | ||
|
||
#include "common/event/libevent.h" | ||
|
||
#include "event2/event.h" | ||
|
||
namespace Envoy { | ||
namespace Event { | ||
|
||
// Implements Scheduler based on libevent. | ||
class LibeventScheduler : public Scheduler { | ||
public: | ||
LibeventScheduler(); | ||
|
||
// Scheduler | ||
TimerPtr createTimer(const TimerCb& cb) override; | ||
|
||
/** | ||
* Runs the libevent loop once, without blocking. | ||
*/ | ||
void nonBlockingLoop(); | ||
|
||
/** | ||
* Runs the libevent loop once, with block. | ||
*/ | ||
void blockingLoop(); | ||
|
||
/** | ||
* Exits the libevent loop. | ||
*/ | ||
void loopExit(); | ||
|
||
/** | ||
* TODO(jmarantz): consider strengthening this abstraction and instead of | ||
* exposing the libevent base pointer, provide API abstractions for the calls | ||
* into it. Among other benefits this might make it more tractable to someday | ||
* consider an alternative to libevent if the need arises. | ||
* | ||
* @return the underlying libevent structure. | ||
*/ | ||
event_base& base() { return *libevent_; } | ||
|
||
private: | ||
Libevent::BasePtr libevent_; | ||
}; | ||
|
||
} // namespace Event | ||
} // namespace Envoy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.