@@ -222,21 +222,20 @@ class ComponentInstance:
222
222
table : Table
223
223
may_leave : bool
224
224
backpressure : bool
225
+ unblocked : asyncio .Event
225
226
calling_sync_export : bool
226
- calling_sync_import : bool
227
227
pending_tasks : list [tuple [Task , asyncio .Future ]]
228
228
starting_pending_task : bool
229
- async_waiting_tasks : asyncio .Condition
230
229
231
230
def __init__ (self ):
232
231
self .table = Table ()
233
232
self .may_leave = True
234
233
self .backpressure = False
234
+ self .unblocked = asyncio .Event ()
235
+ self .unblocked .set ()
235
236
self .calling_sync_export = False
236
- self .calling_sync_import = False
237
237
self .pending_tasks = []
238
238
self .starting_pending_task = False
239
- self .async_waiting_tasks = asyncio .Condition (scheduler )
240
239
241
240
#### Table State
242
241
@@ -519,7 +518,7 @@ def trap_if_on_the_stack(self, inst):
519
518
520
519
def may_enter (self , pending_task ):
521
520
return not self .inst .backpressure and \
522
- not self .inst .calling_sync_import and \
521
+ self .inst .unblocked . is_set () and \
523
522
not (self .inst .calling_sync_export and pending_task .opts .sync )
524
523
525
524
def maybe_start_pending_task (self ):
@@ -536,23 +535,22 @@ async def sync_wait(self, awaitable) -> None:
536
535
awaitable = asyncio .ensure_future (awaitable )
537
536
if awaitable .done () and not DETERMINISTIC_PROFILE and random .randint (0 ,1 ):
538
537
return
539
- assert (not self .inst .calling_sync_import )
540
- self .calling_sync_import = True
538
+ assert (self .inst .unblocked . is_set () )
539
+ self .inst . unblocked . clear ()
541
540
if await self .on_block (awaitable ) == Cancelled .TRUE :
542
541
assert (self .state == Task .State .INITIAL )
543
542
self .state = Task .State .PENDING_CANCEL
544
543
assert (await self .on_block (awaitable ) == Cancelled .FALSE )
545
- self .inst .calling_sync_import = False
546
- self .inst .async_waiting_tasks .notify_all ()
544
+ self .inst .unblocked .set ()
547
545
548
546
async def async_wait (self , awaitable ) -> Cancelled :
549
547
self .maybe_start_pending_task ()
550
548
awaitable = asyncio .ensure_future (awaitable )
551
549
if awaitable .done () and not DETERMINISTIC_PROFILE and random .randint (0 ,1 ):
552
550
return Cancelled .FALSE
553
551
cancelled = await self .on_block (awaitable )
554
- while self .inst .calling_sync_import :
555
- cancelled |= await self .on_block (self .inst .async_waiting_tasks .wait ())
552
+ while not self .inst .unblocked . is_set () :
553
+ cancelled |= await self .on_block (self .inst .unblocked .wait ())
556
554
if cancelled :
557
555
awaitable .cancel ()
558
556
return cancelled
@@ -565,11 +563,10 @@ async def sync_on_block(awaitable):
565
563
assert (await self .on_block (awaitable ) == Cancelled .FALSE )
566
564
return Cancelled .FALSE
567
565
568
- assert (not self .inst .calling_sync_import )
569
- self .inst .calling_sync_import = True
566
+ assert (self .inst .unblocked . is_set () )
567
+ self .inst .unblocked . clear ()
570
568
await callee (self , on_start , on_return , sync_on_block )
571
- self .inst .calling_sync_import = False
572
- self .inst .async_waiting_tasks .notify_all ()
569
+ self .inst .unblocked .set ()
573
570
574
571
async def wait_for_event (self , wset , sync ) -> EventTuple :
575
572
if self .state == Task .State .PENDING_CANCEL :
0 commit comments