#include <errno.h>
#include <sys/select.h>
#include "file.h"
+#include "threaded_log.h"
#ifdef __linux__
#include <sys/epoll.h>
aio_callback::~aio_callback() {}
-poll_mgr poll_mgr::shared_mgr;
-
class wait_manager {
public:
virtual void watch_fd(int fd, poll_flag flag) = 0;
th_ = thread(&poll_mgr::wait_loop, this);
}
-poll_mgr::~poll_mgr()
-{
+poll_mgr::~poll_mgr() {
+ shutdown();
+}
+
+void poll_mgr::shutdown() {
lock ml(m_);
+ if (shutdown_)
+ return;
for (auto p : callbacks_)
aio_->unwatch_fd(p.first, CB_RDWR);
pending_change_ = true;
th_.join();
}
-void
-poll_mgr::add_callback(int fd, poll_flag flag, aio_callback *ch)
-{
+void poll_mgr::add_callback(int fd, poll_flag flag, aio_callback *ch) {
lock ml(m_);
aio_->watch_fd(fd, flag);