Created
February 1, 2020 06:35
-
-
Save kunigami/0ea27c0d37074d1623d8f5f74b029982 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ReadWait(SystemCall): | |
def __init__(self, file): | |
self.file = file | |
def handle(self): | |
fd = self.file.fileno() | |
self.sched.waitforread(self.task, fd) | |
class Scheduler(object): | |
# Add task and file descriptor to the list | |
# to be checked on polling | |
def waitforread(self, task, fd): | |
self.read_waiting[fd] = task | |
# select.select is an OS API to determine | |
# when a file descriptor is "ready" | |
def iopoll(self,timeout): | |
if self.read_waiting or self.write_waiting: | |
read_fds, write_fds, _x = select.select( | |
self.read_waiting, | |
# ... | |
) | |
for fd in read_fds: self.schedule(self.read_waiting.pop(fd)) | |
# ... | |
# Models polling as a regular task - whenever | |
# it gets run by the scheduler it counts as a | |
# poll | |
def iotask(self): | |
while True: | |
if self.ready.empty(): | |
self.iopoll(None) | |
else: | |
self.iopoll(0) | |
yield |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment