#include <errno.h>
#include <sys/select.h>
#include "file.h"
+#include "threaded_log.h"
#ifdef __linux__
#include <sys/epoll.h>
#endif
-poll_mgr poll_mgr::shared_mgr;
+using std::vector;
+
+aio_callback::~aio_callback() {}
class wait_manager {
public:
virtual void watch_fd(int fd, poll_flag flag) = 0;
virtual bool unwatch_fd(int fd, poll_flag flag) = 0;
virtual void wait_ready(vector<int> & readable, vector<int> & writable) = 0;
- virtual ~wait_manager() noexcept {}
+ virtual ~wait_manager() noexcept;
};
+wait_manager::~wait_manager() noexcept {}
+
class SelectAIO : public wait_manager {
public :
SelectAIO();
fd_set rfds_, wfds_;
int highfds_;
file_t pipe_[2];
- mutex m_;
+ std::mutex m_;
};
#ifdef __linux__
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);
return;
else if (ret < 0) {
perror("select:");
- IF_LEVEL(0) LOG("select_loop failure errno " << errno);
+ IF_LEVEL(0) LOG << "select_loop failure errno " << errno;
VERIFY(0);
}