00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef LIBMUTH_EPOLLSCHEDULER_H
00020 #define LIBMUTH_EPOLLSCHEDULER_H
00021
00022 #ifndef USE_EPOLL
00023 #error this file must be compiled with -DUSE_EPOLL
00024 #endif
00025
00026 #include <map>
00027 #include <sys/epoll.h>
00028 #include "basescheduler_decls.h"
00029 #include "callback_decls.h"
00030 #include "lock.h"
00031 #include "timeval_decls.h"
00032 #include "waitqueue.h"
00033
00034 #define EPOLL_MAX_EVENTS 256
00035
00039 class EpollScheduler : public BaseScheduler {
00040 private:
00041
00042
00043
00044 Lock datalock;
00045
00046
00047
00048
00049
00050
00051
00052
00053 std::map<int, Callback*> rfds, wfds;
00054 WaitQueue waits;
00055
00056 Lock notifylock;
00057 bool notified;
00058 int rpipe, wpipe;
00059 void notifyme();
00063 int efd;
00064 void epoll_ctl(int op, int fd, struct epoll_event *event);
00065 struct epoll_event events[EPOLL_MAX_EVENTS];
00066 protected:
00071 EpollScheduler(BlockingQueue<Microthread*> *q=NULL);
00072 public:
00078 static EpollScheduler &create(
00079 BlockingQueue<Microthread*> *q=NULL);
00080 void addReadCallback(Callback &cb, int fd);
00081 void addWriteCallback(Callback &cb, int fd);
00082 void addWaitCallback(Callback &cb, const timeval &tv);
00083 void run();
00084 };
00085
00086 #endif