Added full checkpoint support
This commit is contained in:
parent
cbbe8cc114
commit
52daf54ee3
|
@ -141,6 +141,9 @@ class FIFOKernel(BaseKernel):
|
||||||
def check_cancelled(self):
|
def check_cancelled(self):
|
||||||
if self.current_task.pending_cancellation:
|
if self.current_task.pending_cancellation:
|
||||||
self.cancel_task(self.current_task)
|
self.cancel_task(self.current_task)
|
||||||
|
else:
|
||||||
|
# We reschedule the caller immediately!
|
||||||
|
self.run_queue.appendleft(self.current_task)
|
||||||
|
|
||||||
def schedule_point(self):
|
def schedule_point(self):
|
||||||
self.reschedule_running()
|
self.reschedule_running()
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
# Task synchronization primitives
|
# Task synchronization primitives
|
||||||
from structio.core.syscalls import suspend
|
from structio.core.syscalls import suspend, checkpoint
|
||||||
from structio.core.run import current_task, current_loop
|
from structio.core.run import current_task, current_loop
|
||||||
from structio.core.abc import ChannelReader, ChannelWriter, Channel
|
from structio.core.abc import ChannelReader, ChannelWriter, Channel
|
||||||
from structio.util.ki import enable_ki_protection
|
from structio.util.ki import enable_ki_protection
|
||||||
|
@ -36,6 +36,7 @@ class Event:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if self.is_set():
|
if self.is_set():
|
||||||
|
await checkpoint()
|
||||||
return
|
return
|
||||||
self.waiters.append(current_task())
|
self.waiters.append(current_task())
|
||||||
await suspend() # We get re-scheduled by set()
|
await suspend() # We get re-scheduled by set()
|
||||||
|
@ -46,6 +47,7 @@ class Event:
|
||||||
Sets the event, awaking all tasks
|
Sets the event, awaking all tasks
|
||||||
that called wait() on it
|
that called wait() on it
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if self.is_set():
|
if self.is_set():
|
||||||
raise RuntimeError("the event has already been set")
|
raise RuntimeError("the event has already been set")
|
||||||
self._set = True
|
self._set = True
|
||||||
|
@ -105,6 +107,7 @@ class Queue:
|
||||||
enough space for the queue
|
enough space for the queue
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
await checkpoint()
|
||||||
if self.getters:
|
if self.getters:
|
||||||
self.getters.popleft().set()
|
self.getters.popleft().set()
|
||||||
self.container.append(item)
|
self.container.append(item)
|
||||||
|
@ -123,6 +126,7 @@ class Queue:
|
||||||
is empty
|
is empty
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
await checkpoint()
|
||||||
if self.putters:
|
if self.putters:
|
||||||
self.putters.popleft().set()
|
self.putters.popleft().set()
|
||||||
if not self.container:
|
if not self.container:
|
||||||
|
@ -165,6 +169,7 @@ class MemorySendChannel(ChannelWriter):
|
||||||
|
|
||||||
@enable_ki_protection
|
@enable_ki_protection
|
||||||
async def close(self):
|
async def close(self):
|
||||||
|
await checkpoint()
|
||||||
if self._closed:
|
if self._closed:
|
||||||
raise IOError("cannot operate on a closed channel")
|
raise IOError("cannot operate on a closed channel")
|
||||||
self._closed = True
|
self._closed = True
|
||||||
|
@ -189,6 +194,7 @@ class MemoryReceiveChannel(ChannelReader):
|
||||||
|
|
||||||
@enable_ki_protection
|
@enable_ki_protection
|
||||||
async def close(self):
|
async def close(self):
|
||||||
|
await checkpoint()
|
||||||
if self._closed:
|
if self._closed:
|
||||||
raise IOError("cannot operate on a closed channel")
|
raise IOError("cannot operate on a closed channel")
|
||||||
self._closed = True
|
self._closed = True
|
||||||
|
@ -236,6 +242,7 @@ class Semaphore:
|
||||||
self.waiters.append(Event())
|
self.waiters.append(Event())
|
||||||
await self.waiters[-1].wait()
|
await self.waiters[-1].wait()
|
||||||
self.owners.add(current)
|
self.owners.add(current)
|
||||||
|
await checkpoint()
|
||||||
|
|
||||||
@enable_ki_protection
|
@enable_ki_protection
|
||||||
async def release(self):
|
async def release(self):
|
||||||
|
@ -252,6 +259,7 @@ class Semaphore:
|
||||||
self.owners.remove(current)
|
self.owners.remove(current)
|
||||||
if self.waiters:
|
if self.waiters:
|
||||||
self.waiters.popleft().set()
|
self.waiters.popleft().set()
|
||||||
|
await checkpoint()
|
||||||
|
|
||||||
async def __aenter__(self):
|
async def __aenter__(self):
|
||||||
await self.acquire()
|
await self.acquire()
|
||||||
|
|
Loading…
Reference in New Issue