LogCabin
|
Registers a File handler to be monitored by the Event::Loop. More...
#include <File.h>
Public Member Functions | |
Monitor (Event::Loop &eventLoop, File &file, uint32_t fileEvents) | |
Constructor; begins monitoring events on a file. | |
virtual | ~Monitor () |
Destructor; disables monitoring the file. | |
void | disableForever () |
Stop monitoring this file. | |
void | setEvents (uint32_t events) |
Specify the events of interest for the file. | |
Public Attributes | |
Event::Loop & | eventLoop |
Event::Loop that will monitor the file. | |
Private Member Functions | |
Monitor (const Monitor &) | |
Monitor & | operator= (const Monitor &) |
Private Attributes | |
std::mutex | mutex |
Protects file from concurrent access/modification. | |
File * | file |
Pointer to file being monitored, or NULL if disableForever() has been called. |
Registers a File handler to be monitored by the Event::Loop.
Once this is constructed, the Event::Loop will call the File's event handler appropriately.
This object must be destroyed or disableForever() called BEFORE the File object can be destroyed safely.
Details: That Monitor objects have distinct lifetimes from File objects is the key reason why they exist. The registration functionality used to be integrated in File itself, but that posed a problem on destruction. Suppose class MyFile derives from File. ~File() is called after MyFile::handleFileEvent() is no longer safe to call (since MyFile members are already destroyed). So ~File() is too late to block the Event::Loop; it needs to happen before all this. See also https://github.com/logcabin/logcabin/issues/82
LogCabin::Event::File::Monitor::Monitor | ( | Event::Loop & | eventLoop, |
File & | file, | ||
uint32_t | fileEvents | ||
) |
Constructor; begins monitoring events on a file.
eventLoop | Event::Loop that will monitor the File object. |
file | The file to monitor for events. |
fileEvents | The files handler will be invoked when any of the events specified by this parameter occur (OR-ed combination of EPOLL_EVENTS values). If this is 0 then the file handler starts off inactive; it will not trigger until setEvents() has been called (except possibly for errors such as EPOLLHUP; these events are always active). |
LogCabin::Event::File::Monitor::~Monitor | ( | ) | [virtual] |
Destructor; disables monitoring the file.
See disableForever().
Reimplemented in LogCabin::Event::Signal::Monitor, and LogCabin::Event::Timer::Monitor.
LogCabin::Event::File::Monitor::Monitor | ( | const Monitor & | ) | [private] |
Stop monitoring this file.
To guarantee that the event loop thread is no longer operating on the File, this method takes an Event::Loop::Lock internally. Once this returns, it is safe to destroy the File object, and it is guaranteed that the event loop thread is no longer operating on the File (unless the caller is running in the context of the File's event handler).
void LogCabin::Event::File::Monitor::setEvents | ( | uint32_t | events | ) |
Specify the events of interest for the file.
This method is safe to call concurrently with file events triggering and disableForever. If called outside an event handler and no Event::Loop::Lock is taken, this may have a short delay while active handlers continue to be called.
events | Indicates the conditions under which this object should be invoked (OR-ed combination of EPOLL_EVENTS values). If this is 0 then the file handler is set to inactive; it will not trigger until setEvents() has been called (except possibly for errors such as EPOLLHUP; these events are always active). |
Event::Loop that will monitor the file.
std::mutex LogCabin::Event::File::Monitor::mutex [private] |
File* LogCabin::Event::File::Monitor::file [private] |
Pointer to file being monitored, or NULL if disableForever() has been called.