将 .py 和 .pyi 后缀名改为了 .vp 和 .vpi 后缀名

This commit is contained in:
2026-07-30 16:33:56 +08:00
parent f79c8ca643
commit cfc30d735c
322 changed files with 246 additions and 31772 deletions

46
includes/rwlock.vp Normal file
View File

@@ -0,0 +1,46 @@
import t, c
from stdint import *
from w32.win32base import *
from w32.win32sync import (
InitializeSRWLock,
AcquireSRWLockExclusive, ReleaseSRWLockExclusive,
AcquireSRWLockShared, ReleaseSRWLockShared
)
@t.Object
class RWLock:
"""SRWLock-based read-write lock that supports multiple readers and single writer, but does not support recursion.
Usage:
rwlock: RWLock = RWLock()
rwlock.acquire_read()
# ... read shared data
rwlock.release_read()
rwlock.acquire_write()
# ... modify shared data
rwlock.release_write()
"""
lock: VOIDPTR
def __init__(self):
InitializeSRWLock(c.Addr(self.lock))
def acquire_read(self):
AcquireSRWLockShared(c.Addr(self.lock))
def release_read(self):
ReleaseSRWLockShared(c.Addr(self.lock))
def acquire_write(self):
AcquireSRWLockExclusive(c.Addr(self.lock))
def release_write(self):
ReleaseSRWLockExclusive(c.Addr(self.lock))
def __enter__(self) -> 'RWLock' | t.CPtr:
self.acquire_write()
return self
def __exit__(self):
self.release_write()