event/Loop: split InjectBreak() from Break()
This commit is contained in:
@@ -115,7 +115,7 @@ class EventLoop final
|
||||
bool alive;
|
||||
#endif
|
||||
|
||||
std::atomic_bool quit{false};
|
||||
bool quit = false;
|
||||
|
||||
/**
|
||||
* True when the object has been modified and another check is
|
||||
@@ -124,6 +124,8 @@ class EventLoop final
|
||||
bool again;
|
||||
|
||||
#ifdef HAVE_THREADED_EVENT_LOOP
|
||||
bool quit_injected = false;
|
||||
|
||||
/**
|
||||
* True when handling callbacks, false when waiting for I/O or
|
||||
* timeout.
|
||||
@@ -187,11 +189,30 @@ public:
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Stop execution of this #EventLoop at the next chance. This
|
||||
* method is thread-safe and non-blocking: after returning, it
|
||||
* is not guaranteed that the EventLoop has really stopped.
|
||||
* Stop execution of this #EventLoop at the next chance.
|
||||
*
|
||||
* This method is not thread-safe. For stopping the
|
||||
* #EventLoop from within another thread, use InjectBreak().
|
||||
*/
|
||||
void Break() noexcept;
|
||||
void Break() noexcept {
|
||||
quit = true;
|
||||
}
|
||||
|
||||
#ifdef HAVE_THREADED_EVENT_LOOP
|
||||
/**
|
||||
* Like Break(), but thread-safe. It is also non-blocking:
|
||||
* after returning, it is not guaranteed that the EventLoop
|
||||
* has really stopped.
|
||||
*/
|
||||
void InjectBreak() noexcept {
|
||||
{
|
||||
const std::scoped_lock lock{mutex};
|
||||
quit_injected = true;
|
||||
}
|
||||
|
||||
wake_fd.Write();
|
||||
}
|
||||
#endif // HAVE_THREADED_EVENT_LOOP
|
||||
|
||||
bool AddFD(int fd, unsigned events, SocketEvent &event) noexcept;
|
||||
bool ModifyFD(int fd, unsigned events, SocketEvent &event) noexcept;
|
||||
|
Reference in New Issue
Block a user