按根目录 新规范 迁移 R1/R2/R3/R4/R6/R7/R8/R9:指针 T* 后缀、内建类型短别名、c.Addr/c.Deref 单目化、c.Asm 改 __asm__、t.CDefine 改 define 软关键字、t.CEnum 改 enum。R4 对内建 cast 多参实参保留 c.Deref 原写法(单目化会致 TPC 类型退化)。验证:includes 52/52 编译通过,TransPyV 自举产物顺序回归 77/77 全通过。
54 lines
1.4 KiB
Plaintext
54 lines
1.4 KiB
Plaintext
import t, c
|
|
from stdint import *
|
|
from w32.win32base import *
|
|
from w32.win32sync import (
|
|
CRITICAL_SECTION,
|
|
CONDITION_VARIABLE,
|
|
InitializeCriticalSection, EnterCriticalSection, LeaveCriticalSection, DeleteCriticalSection,
|
|
InitializeConditionVariable, SleepConditionVariableCS,
|
|
WakeConditionVariable, WakeAllConditionVariable
|
|
)
|
|
|
|
|
|
class Condition:
|
|
"""Windows condition variable backed primitive, internally bundled with CRITICAL_SECTION.
|
|
|
|
Usage:
|
|
cond: Condition = Condition()
|
|
with cond:
|
|
while not ready:
|
|
cond.wait()
|
|
cond.notify()
|
|
"""
|
|
cond_var: CONDITION_VARIABLE
|
|
cs: CRITICAL_SECTION
|
|
|
|
def __init__(self):
|
|
InitializeCriticalSection(&self.cs)
|
|
InitializeConditionVariable(&self.cond_var)
|
|
|
|
def wait(self, timeout_ms: ULONG = INFINITE) -> BOOL:
|
|
return SleepConditionVariableCS(&self.cond_var, &self.cs, timeout_ms)
|
|
|
|
def notify(self):
|
|
WakeConditionVariable(&self.cond_var)
|
|
|
|
def notify_all(self):
|
|
WakeAllConditionVariable(&self.cond_var)
|
|
|
|
def acquire(self):
|
|
EnterCriticalSection(&self.cs)
|
|
|
|
def release(self):
|
|
LeaveCriticalSection(&self.cs)
|
|
|
|
def __enter__(self) -> 'Condition' | t.CPtr:
|
|
self.acquire()
|
|
return self
|
|
|
|
def __exit__(self):
|
|
self.release()
|
|
|
|
def delete(self):
|
|
DeleteCriticalSection(&self.cs)
|