diff --git a/stdlib/threading.codon b/stdlib/threading.codon index c47b4de9..de077b09 100644 --- a/stdlib/threading.codon +++ b/stdlib/threading.codon @@ -1,3 +1,6 @@ +# (c) 2022 Exaloop Inc. All rights reserved. + + @tuple class Lock: p: cobj @@ -5,20 +8,21 @@ class Lock: def __new__() -> Lock: return (_C.seq_lock_new(),) - def acquire(self, block: bool = True, timeout: float = -1.0): + def acquire(self, block: bool = True, timeout: float = -1.0) -> bool: if timeout >= 0.0 and not block: raise ValueError("can't specify a timeout for a non-blocking call") return _C.seq_lock_acquire(self.p, block, timeout) - def release(self): + def release(self) -> void: _C.seq_lock_release(self.p) - def __enter__(self): + def __enter__(self) -> void: self.acquire() - def __exit__(self): + def __exit__(self) -> void: self.release() + @tuple class RLock: p: cobj @@ -26,27 +30,32 @@ class RLock: def __new__() -> RLock: return (_C.seq_rlock_new(),) - def acquire(self, block: bool = True, timeout: float = -1.0): + def acquire(self, block: bool = True, timeout: float = -1.0) -> bool: if timeout >= 0.0 and not block: raise ValueError("can't specify a timeout for a non-blocking call") return _C.seq_rlock_acquire(self.p, block, timeout) - def release(self): + def release(self) -> void: _C.seq_rlock_release(self.p) - def __enter__(self): + def __enter__(self) -> void: self.acquire() - def __exit__(self): + def __exit__(self) -> void: self.release() -def active_count(): + +def active_count() -> int: from openmp import get_num_threads + return get_num_threads() -def get_native_id(): + +def get_native_id() -> int: from openmp import get_thread_num + return get_thread_num() -def get_ident(): + +def get_ident() -> int: return get_native_id() + 1