From f473b8cf2f49ebec3c5069d9381a83b9f5957f11 Mon Sep 17 00:00:00 2001 From: exflikt Date: Fri, 29 Nov 2024 15:28:56 +0900 Subject: [PATCH] Refactor the condflag class --- app/store/placement.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/app/store/placement.py b/app/store/placement.py index 62cb15c..434c1b3 100644 --- a/app/store/placement.py +++ b/app/store/placement.py @@ -38,8 +38,12 @@ class ModifiedFlag(Flag): class ModifiedCondFlag: - _condvar: asyncio.Condition = asyncio.Condition() - flag: ModifiedFlag = ModifiedFlag.ORIGINAL + _condvar: asyncio.Condition + _flag: ModifiedFlag + + def __init__(self): + self._condvar = asyncio.Condition() + self._flag = ModifiedFlag.ORIGINAL async def __aenter__(self): await self._condvar.__aenter__() @@ -49,15 +53,14 @@ async def __aexit__(self, exc_type, exc, tb) -> None: async def wait(self) -> ModifiedFlag: await self._condvar.wait() - flag = self.flag + flag = self._flag if len(self._condvar._waiters) == 0: - self.flag = ModifiedFlag.ORIGINAL + self._flag = ModifiedFlag.ORIGINAL return flag - def notify_all(self, flag: ModifiedFlag | None = None): + def notify_all(self, flag: ModifiedFlag): + self._flag |= flag self._condvar.notify_all() - if flag is not None: - self.flag |= flag class Table: