(self: TReentrantLock.TReentrantLock)
| 267 | |
| 268 | /** @internal */ |
| 269 | export const releaseWrite = (self: TReentrantLock.TReentrantLock): STM.STM<number> => |
| 270 | core.withSTMRuntime((runtime) => { |
| 271 | const lock = tRef.unsafeGet(self.state, runtime.journal) |
| 272 | if (isWriteLock(lock) && lock.writeLocks === 1 && Equal.equals(runtime.fiberId)(lock.fiberId)) { |
| 273 | const result = makeReadLock(lock.fiberId, lock.readLocks) |
| 274 | tRef.unsafeSet(self.state, result, runtime.journal) |
| 275 | return core.succeed(result.writeLocksHeld(runtime.fiberId)) |
| 276 | } |
| 277 | if (isWriteLock(lock) && Equal.equals(runtime.fiberId)(lock.fiberId)) { |
| 278 | const result = new WriteLock(lock.readLocks, lock.writeLocks - 1, runtime.fiberId) |
| 279 | tRef.unsafeSet(self.state, result, runtime.journal) |
| 280 | return core.succeed(result.writeLocksHeld(runtime.fiberId)) |
| 281 | } |
| 282 | throw new Error( |
| 283 | `Defect: Fiber ${FiberId.threadName(runtime.fiberId)} releasing write lock it does not hold` |
| 284 | ) |
| 285 | }) |
| 286 | |
| 287 | /** @internal */ |
| 288 | export const withLock = dual< |
no test coverage detected