26 #include "IPollLoop.h"
30 #include <sys/timerfd.h>
63 PollLoop(
const std::string& name,
int maxSources = 512,
long deferredTimeInterval = 20);
67 virtual bool start(
int priority = -1)
override;
68 virtual void stop()
override;
70 virtual bool addSource(
const std::shared_ptr<IPollSource>& source,
int fd, uint32_t events)
override;
71 virtual bool modSource(
const std::shared_ptr<IPollSource>& source, uint32_t events)
override;
72 virtual void delSource(
const std::shared_ptr<IPollSource>& source,
int fd = -1)
override;
73 virtual bool hasSource(
const std::shared_ptr<IPollSource>& source)
override;
75 virtual std::thread::id
threadId()
const override;
76 virtual pid_t
gettid()
const override;
80 void run(
const std::string& name,
int priority);
87 const std::string mName;
89 std::thread mEPollThread;
92 std::atomic<pid_t> mEPollThreadId;
105 const struct itimerspec mDeferTimerSpec;
111 const int mMaxSources;
114 int mDeferredSources;
125 std::weak_ptr<IPollSource> source;
131 std::list<PollSourceWrapper> mSources;
Definition: IPollLoop.h:49
A wrapper around epoll that allows for adding, modifying & deleting of source events.
Definition: PollLoop.h:61
virtual bool addSource(const std::shared_ptr< IPollSource > &source, int fd, uint32_t events) override
Adds a new event source to the poll loop.
Definition: PollLoop.cpp:182
virtual bool start(int priority=-1) override
Starts the poll thread.
Definition: PollLoop.cpp:423
virtual bool hasSource(const std::shared_ptr< IPollSource > &source) override
Returns true if the specified source is currently installed in the pollLoop.
Definition: PollLoop.cpp:391
PollLoop(const std::string &name, int maxSources=512, long deferredTimeInterval=20)
Constructs a poll loop with the given name and restrictions.
Definition: PollLoop.cpp:62
void enableDeferredTimer()
Enables the deferred timer event source.
Definition: PollLoop.cpp:99
virtual ~PollLoop()
Destructs the poll loop, tears down the thread if the loop is running.
Definition: PollLoop.cpp:84
virtual void stop() override
Stops the poll loop thread.
Definition: PollLoop.cpp:546
void run(const std::string &name, int priority)
The poll loop thread function.
Definition: PollLoop.cpp:618
void disableDeferredTimer()
Disables the deferred timer event source.
Definition: PollLoop.cpp:135
virtual pid_t gettid() const override
Returns the linux thread id of the poll loop thread.
Definition: PollLoop.cpp:605
virtual std::thread::id threadId() const override
Returns the thread id of the poll loop thread.
Definition: PollLoop.cpp:593
Definition: SpinLock.h:42
Definition: PollLoop.h:118