18 #ifndef UTHREADS_IOHANDLER_H_ 19 #define UTHREADS_IOHANDLER_H_ 21 #include <unordered_map> 23 #include <sys/socket.h> 25 #include "../runtime/uThread.h" 26 #include "../runtime/kThread.h" 27 #include "../generic/Semaphore.h" 29 #define POLL_READY ((uThread*)1) 30 #define POLL_WAIT ((uThread*)2) 39 class PollData :
public Link<PollData>{
79 bool isBlockingOnRead;
107 PollData(
int fd) : fd(fd), closing(false), opened(false), isBlockingOnRead(false){};
114 PollData(): fd(-1), closing(false), opened(false), isBlockingOnRead(false){};
115 PollData(
const PollData&) =
delete;
116 const PollData& operator=(
const PollData&) =
delete;
135 friend class IOHandler;
138 IntrusiveQueue<PollData> cache;
141 PollData* getPollData(){
142 std::unique_lock<std::mutex> mlock(mtx);
144 for(
int i=0 ; i < 128; i++){
145 PollData* pd =
new PollData();
149 PollData* pd = cache.front();
154 void pushPollData(PollData* pd){
155 std::unique_lock<std::mutex> mlock(mtx);
159 #if defined (__linux__) 160 #include "EpollIOHandler.h" 162 #error unsupported system: only __linux__ supported at this moment 175 friend class ReadyQueue;
177 friend class Scheduler;
181 static IOHandler iohandler;
184 size_t unblockCounter;
186 std::atomic_flag isPolling;
202 void block(PollData &pd,
bool isRead);
203 bool inline unblock(PollData &pd,
bool isRead);
205 static void postSwitchFunc(
void* ut,
void* args);
208 static void pollerFunc(
void*) __noreturn;
211 void PollReady(PollData &pd,
int flag);
216 void open(PollData &pd);
217 int close(PollData &pd);
218 void wait(PollData& pd,
int flag);
219 ssize_t poll(
int timeout,
int flag);
220 ssize_t nonblockingPoll();
221 void reset(PollData &pd);
Definition: EpollIOHandler.h:13
Object to represent kernel threads.
Definition: kThread.h:54
user-level threads (fiber)
Definition: uThread.h:63
Scheduler and Cluster of kThreads.
Definition: Cluster.h:61
Represents a network connection.
Definition: Network.h:33