Dobby
3.0
Dobby “Docker based Thingy” is a tool for managing and running OCI containers using crun
|
A wrapper around epoll that allows for adding, modifying & deleting of source events. More...
#include <PollLoop.h>
Classes | |
struct | tagPollSourceWrapper |
Public Member Functions | |
PollLoop (const std::string &name, int maxSources=512, long deferredTimeInterval=20) | |
Constructs a poll loop with the given name and restrictions. More... | |
virtual | ~PollLoop () |
Destructs the poll loop, tears down the thread if the loop is running. | |
virtual bool | start (int priority=-1) override |
Starts the poll thread. More... | |
virtual void | stop () override |
Stops the poll loop thread. More... | |
virtual bool | addSource (const std::shared_ptr< IPollSource > &source, int fd, uint32_t events) override |
Adds a new event source to the poll loop. More... | |
virtual bool | modSource (const std::shared_ptr< IPollSource > &source, uint32_t events) override |
virtual void | delSource (const std::shared_ptr< IPollSource > &source, int fd=-1) override |
virtual bool | hasSource (const std::shared_ptr< IPollSource > &source) override |
Returns true if the specified source is currently installed in the pollLoop. More... | |
virtual std::thread::id | threadId () const override |
Returns the thread id of the poll loop thread. More... | |
virtual pid_t | gettid () const override |
Returns the linux thread id of the poll loop thread. More... | |
Private Types | |
typedef struct AICommon::PollLoop::tagPollSourceWrapper | PollSourceWrapper |
Private Member Functions | |
void | init () |
void | run (const std::string &name, int priority) |
The poll loop thread function. More... | |
void | enableDeferredTimer () |
Enables the deferred timer event source. More... | |
void | disableDeferredTimer () |
Disables the deferred timer event source. | |
Private Attributes | |
const std::string | mName |
std::thread | mEPollThread |
std::atomic< pid_t > | mEPollThreadId |
int | mEPollFd |
int | mDeathEventFd |
int | mDeferTimerFd |
const struct itimerspec | mDeferTimerSpec |
Spinlock | mLock |
const int | mMaxSources |
int | mDeferredSources |
std::list< PollSourceWrapper > | mSources |
A wrapper around epoll that allows for adding, modifying & deleting of source events.
Poll loop sources are a tuple of a shared_ptr<IPollSource>, an fd and a bitmask of events to listen on. PollSource objects are store as weak_ptrs and only locked when they have been triggered and their process() function is to be called.
This should make the race conditions with calling an object that has been destroy safe, however it does means that PollSource objects shouldn't assume that their process() methods won't be called after they've been removed from the poll loop.
PollLoop::PollLoop | ( | const std::string & | name, |
int | maxSources = 512 , |
||
long | deferredTimeInterval = 20 |
||
) |
Constructs a poll loop with the given name and restrictions.
A constructed poll loop is not automatically started, rather the caller should call start to spawn a thread and run the poll loop inside it.
[in] | name | The name to give the poll loop thread (nb: thread names are limited to 16 characters). |
[in] | maxSources | The maximum number of event sources that can be installed on the poll loop. |
[in] | deferredTimeInterval | The time interval in milliseconds of the deferred timer |
|
overridevirtual |
Adds a new event source to the poll loop.
A source is a file descriptor, a bitmask of events to wait for and a IPollSource object that will be called when any of the events in the bitmask occur on the file descriptor.
This method may fail if the number of sources installed exceeds the maximum allowed.
[in] | source | The source object to call process() on when an event occurs |
[in] | fd | The file descriptor to poll on |
[in] | events | A bitmask of events to listen on |
Implements AICommon::IPollLoop.
|
inlineprivate |
Enables the deferred timer event source.
This is an internal function that is called when a source event has been 'deferred', i.e. a client has called modSource(..., EPOLLDEFERRED).
|
overridevirtual |
Returns the linux thread id of the poll loop thread.
If the poll loop /threa is not current running -1 will be returned.
Implements AICommon::IPollLoop.
|
overridevirtual |
Returns true if the specified source is currently installed in the pollLoop.
[in] | source | The source object to search for in the pollLoop |
Implements AICommon::IPollLoop.
|
private |
The poll loop thread function.
This is the thread that does all the epoll stuff.
|
overridevirtual |
Starts the poll thread.
If the poll loop was already running it is stopped and restarted.
[in] | priority | The SCRED_RR priority in which to run the poll loop, if -1 the priority is inherited from the calling thread |
Implements AICommon::IPollLoop.
|
overridevirtual |
Stops the poll loop thread.
Stops the poll loop and cleans up all the resources associated with it.
Implements AICommon::IPollLoop.
|
overridevirtual |
Returns the thread id of the poll loop thread.
If the poll loop /threa is not current running, a default constructed std::thread::id is returned.
Implements AICommon::IPollLoop.