| 2337 | |
| 2338 | |
| 2339 | class CounterLock: |
| 2340 | def __init__(self): |
| 2341 | self.lock = Lock() |
| 2342 | self.acquire_count = 0 |
| 2343 | self.release_count = 0 |
| 2344 | |
| 2345 | def acquire(self, blocking: bool = True, timeout: float = -1) -> bool: |
| 2346 | acquired = self.lock.acquire(blocking=blocking, timeout=timeout) |
| 2347 | if acquired: |
| 2348 | # int.__iadd__ is atomic on GIL-enabld interpreters; when the GIL is |
| 2349 | # disabled things are nuanced and hardware-dependent. Don't risk it. |
| 2350 | self.acquire_count += 1 |
| 2351 | return acquired |
| 2352 | |
| 2353 | def release(self) -> None: |
| 2354 | if self.lock.locked(): |
| 2355 | self.release_count += 1 |
| 2356 | self.lock.release() |
| 2357 | |
| 2358 | |
| 2359 | def test_store_locks_failure_lock_released(): |
no outgoing calls