LogCabin
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Classes | Public Member Functions | Private Member Functions | Private Attributes | Friends
LogCabin::Event::Loop Class Reference

This class contains an event loop based on Linux's epoll interface. More...

#include <Loop.h>

List of all members.

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 &)
Loopoperator= (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

Detailed Description

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.

Definition at line 38 of file Loop.h.


Constructor & Destructor Documentation

Constructor.

Definition at line 97 of file Loop.cc.

Destructor.

The caller must ensure that no events still exist and that the event loop is not running.

Definition at line 113 of file Loop.cc.

LogCabin::Event::Loop::Loop ( const Loop ) [private]

Member Function Documentation

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.

Definition at line 124 of file Loop.cc.

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.

Definition at line 168 of file Loop.cc.

Loop& LogCabin::Event::Loop::operator= ( const Loop ) [private]

Friends And Related Function Documentation

friend class Event::File [friend]

Definition at line 194 of file Loop.h.


Member Data Documentation

The file descriptor used in epoll calls to monitor other files.

Definition at line 109 of file Loop.h.

Used by Event::Loop::Lock to break runForever() out of epoll_wait.

Definition at line 114 of file Loop.h.

This is a flag to runForever() to exit, set by exit().

Protected by Event::Loop::Lock (or mutex directly inside runForever()).

Definition at line 120 of file Loop.h.

std::mutex LogCabin::Event::Loop::mutex [private]

This mutex protects all of the members of this class defined below this point, except breakTimerMonitor.

Definition at line 126 of file Loop.h.

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.

Definition at line 135 of file Loop.h.

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.

Definition at line 142 of file Loop.h.

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.

Definition at line 149 of file Loop.h.

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.

Definition at line 156 of file Loop.h.

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.

Definition at line 163 of file Loop.h.

Signaled when there are no longer any Locks active.

Definition at line 168 of file Loop.h.

Watches breakTimer for events.

Definition at line 192 of file Loop.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines