LogCabin
|
This class contains an event loop based on Linux's epoll interface. More...
#include <Loop.h>
Classes | |
class | Lock |
Lock objects are used to synchronize between the Event::Loop thread and other threads. More... | |
struct | NoOpLockable |
Lockable type that compiles out entirely. More... | |
class | NullTimer |
Used in breakTimer, whose purpose is not to handle events but to break runForever() out of epoll_wait. More... | |
Public Member Functions | |
Loop () | |
Constructor. | |
~Loop () | |
Destructor. | |
void | runForever () |
Run the main event loop until exit() is called. | |
void | exit () |
Exit the main event loop, if one is running. | |
Private Member Functions | |
Loop (const Loop &) | |
Loop & | operator= (const Loop &) |
Private Attributes | |
int | epollfd |
The file descriptor used in epoll calls to monitor other files. | |
NullTimer | breakTimer |
Used by Event::Loop::Lock to break runForever() out of epoll_wait. | |
bool | shouldExit |
This is a flag to runForever() to exit, set by exit(). | |
std::mutex | mutex |
This mutex protects all of the members of this class defined below this point, except breakTimerMonitor. | |
uint64_t | runningThread |
The thread ID of the thread running the event loop, or Core::ThreadId::NONE if no thread is currently running the event loop. | |
uint32_t | numLocks |
The number of Lock instances, including those that are blocked and those that are active. | |
uint32_t | numActiveLocks |
The number of Locks that are active. | |
uint64_t | lockOwner |
The thread ID of the thread with active Locks, or Core::ThreadId::NONE if no thread currently has a Lock. | |
Core::ConditionVariable | safeToLock |
Signaled when it may be safe for a Lock constructor to complete. | |
Core::ConditionVariable | unlocked |
Signaled when there are no longer any Locks active. | |
struct LogCabin::Event::Loop::NoOpLockable | extraMutexToSatisfyRaceDetector |
Event::Timer::Monitor | breakTimerMonitor |
Watches breakTimer for events. | |
Friends | |
class | Event::File |
This class contains an event loop based on Linux's epoll interface.
It keeps track of interesting events such as timers and socket activity, and arranges for callbacks to be invoked when the events happen.
LogCabin::Event::Loop::Loop | ( | const Loop & | ) | [private] |
void LogCabin::Event::Loop::runForever | ( | ) |
Run the main event loop until exit() is called.
It is safe to call this again after it returns. The caller must ensure that only one thread is executing runForever() at a time.
void LogCabin::Event::Loop::exit | ( | ) |
Exit the main event loop, if one is running.
It may return before runForever() has returned but guarantees runForever() will return soon.
If the event loop is not running, then the next time it runs, it will exit right away (these semantics can be useful to avoid races).
This may be called from an event handler or from any thread.
friend class Event::File [friend] |
int LogCabin::Event::Loop::epollfd [private] |
NullTimer LogCabin::Event::Loop::breakTimer [private] |
Used by Event::Loop::Lock to break runForever() out of epoll_wait.
bool LogCabin::Event::Loop::shouldExit [private] |
This is a flag to runForever() to exit, set by exit().
Protected by Event::Loop::Lock (or mutex directly inside runForever()).
std::mutex LogCabin::Event::Loop::mutex [private] |
uint64_t LogCabin::Event::Loop::runningThread [private] |
The thread ID of the thread running the event loop, or Core::ThreadId::NONE if no thread is currently running the event loop.
This serves two purposes: First, it allows Lock to tell whether it's running under the event loop. Second, it allows Lock to tell if the event loop is running.
uint32_t LogCabin::Event::Loop::numLocks [private] |
The number of Lock instances, including those that are blocked and those that are active.
runForever() waits for this to drop to 0 before running again.
uint32_t LogCabin::Event::Loop::numActiveLocks [private] |
The number of Locks that are active.
This is used to support reentrant Lock objects, specifically to know when to set lockOwner back to Core::ThreadId::NONE.
uint64_t LogCabin::Event::Loop::lockOwner [private] |
The thread ID of the thread with active Locks, or Core::ThreadId::NONE if no thread currently has a Lock.
This allows for mutually exclusive yet reentrant Lock objects.
Signaled when it may be safe for a Lock constructor to complete.
This happens either because runForever() just reached its safe place or because some other Lock was destroyed.
struct LogCabin::Event::Loop::NoOpLockable LogCabin::Event::Loop::extraMutexToSatisfyRaceDetector [private] |