X-Git-Url: http://xvm.mit.edu/gitweb/invirt/third/libt4.git/blobdiff_plain/16e7c282c6fcec8189425bd15ec9e8a4a0ee857d..3abd3952c1f4441f0dd6eae9883b2d01ed9cd56b:/rpc/pollmgr.h diff --git a/rpc/pollmgr.h b/rpc/pollmgr.h index 2da3167..ede35f8 100644 --- a/rpc/pollmgr.h +++ b/rpc/pollmgr.h @@ -2,11 +2,6 @@ #define pollmgr_h #include "types.h" -#include - -#ifdef __linux__ -#include -#endif #define MAX_POLL_FDS 128 @@ -18,15 +13,6 @@ typedef enum { CB_MASK = ~0x11, } poll_flag; -class aio_mgr { - public: - virtual void watch_fd(int fd, poll_flag flag) = 0; - virtual bool unwatch_fd(int fd, poll_flag flag) = 0; - virtual bool is_watched(int fd, poll_flag flag) = 0; - virtual void wait_ready(vector *readable, vector *writable) = 0; - virtual ~aio_mgr() {} -}; - class aio_callback { public: virtual void read_cb(int fd) = 0; @@ -39,69 +25,22 @@ class PollMgr { PollMgr(); ~PollMgr(); - static PollMgr *Instance(); - static PollMgr *CreateInst(); + static PollMgr & Instance(); void add_callback(int fd, poll_flag flag, aio_callback *ch); void del_callback(int fd, poll_flag flag); - bool has_callback(int fd, poll_flag flag, aio_callback *ch); void block_remove_fd(int fd); void wait_loop(); - - static PollMgr *instance; - static int useful; - static int useless; - private: mutex m_; cond changedone_c_; - thread th_; - - aio_callback *callbacks_[MAX_POLL_FDS]; - aio_mgr *aio_; - bool pending_change_; - -}; - -class SelectAIO : public aio_mgr { - public : - - SelectAIO(); - ~SelectAIO(); - void watch_fd(int fd, poll_flag flag); - bool unwatch_fd(int fd, poll_flag flag); - bool is_watched(int fd, poll_flag flag); - void wait_ready(vector *readable, vector *writable); - private: - - fd_set rfds_; - fd_set wfds_; - int highfds_; - int pipefd_[2]; - - mutex m_; - -}; - -#ifdef __linux__ -class EPollAIO : public aio_mgr { - public: - EPollAIO(); - ~EPollAIO(); - void watch_fd(int fd, poll_flag flag); - bool unwatch_fd(int fd, poll_flag flag); - bool is_watched(int fd, poll_flag flag); - void wait_ready(vector *readable, vector *writable); - - private: - int pollfd_; - struct epoll_event ready_[MAX_POLL_FDS]; - int fdstatus_[MAX_POLL_FDS]; + map callbacks_; + class wait_manager *aio_; + bool pending_change_=false, shutdown_=false; + thread th_; }; -#endif /* __linux */ - -#endif /* pollmgr_h */ +#endif