this repo has no description
at trunk 107 lines 1.9 kB view raw
1#!/usr/bin/env python3 2# Copyright (c) Facebook, Inc. and its affiliates. (http://www.facebook.com) 3 4from _builtins import _builtin, _Unbound, _unimplemented 5 6 7# TODO(T53322979): Re-write to be thread-safe 8class LockType: 9 def __exit__(self, t, v, tb): 10 self.release() 11 12 def __init__(self): 13 self._locked = False 14 15 def acquire(self, blocking=True, timeout=-1): 16 if self._locked: 17 if not blocking: 18 return False 19 # No implementation of timeout 20 _unimplemented() 21 self._locked = True 22 return True 23 24 __enter__ = acquire 25 26 acquire_lock = acquire 27 28 def locked(self): 29 return self._locked 30 31 def release(self): 32 if not self._locked: 33 raise RuntimeError("release unlocked lock") 34 self._locked = False 35 36 release_lock = release 37 38 39class RLock: 40 """Recursive (pseudo) Lock assuming single-threaded execution.""" 41 42 def __init__(self): 43 self._count = 0 44 45 def acquire(self, blocking=True, timeout=-1): 46 self._count += 1 47 48 __enter__ = acquire 49 50 def release(self): 51 if self._count == 0: 52 raise RuntimeError("cannot release un-acquired lock") 53 self._count -= 1 54 55 def __exit__(self, t, v, tb): 56 self.release() 57 58 59def _count(): 60 _unimplemented() 61 62 63class _local: 64 pass 65 66 67def _set_sentinel(): 68 _unimplemented() 69 70 71def allocate(): 72 _unimplemented() 73 74 75allocate_lock = LockType 76 77 78error = RuntimeError 79 80 81def exit(): 82 _unimplemented() 83 84 85def exit_thread(): 86 _unimplemented() 87 88 89def get_ident(): 90 _builtin() 91 92 93def interrupt_main(): 94 _unimplemented() 95 96 97def stack_size(size=0): 98 _unimplemented() 99 100 101def start_new(function, args, kwargs=_Unbound): 102 """Obsolete synonym of start_new_thread""" 103 _builtin() 104 105 106def start_new_thread(function, args, kwargs=_Unbound): 107 _builtin()