(self: TReentrantLock.TReentrantLock)
| 185 | |
| 186 | /** @internal */ |
| 187 | export const acquireWrite = (self: TReentrantLock.TReentrantLock): STM.STM<number> => |
| 188 | core.withSTMRuntime((runtime) => { |
| 189 | const lock = tRef.unsafeGet(self.state, runtime.journal) |
| 190 | if (isReadLock(lock) && noOtherHolder(lock, runtime.fiberId)) { |
| 191 | tRef.unsafeSet( |
| 192 | self.state, |
| 193 | new WriteLock(lock.readLocksHeld(runtime.fiberId), 1, runtime.fiberId), |
| 194 | runtime.journal |
| 195 | ) |
| 196 | return core.succeed(1) |
| 197 | } |
| 198 | if (isWriteLock(lock) && Equal.equals(runtime.fiberId)(lock.fiberId)) { |
| 199 | tRef.unsafeSet( |
| 200 | self.state, |
| 201 | new WriteLock(lock.readLocks, lock.writeLocks + 1, runtime.fiberId), |
| 202 | runtime.journal |
| 203 | ) |
| 204 | return core.succeed(lock.writeLocks + 1) |
| 205 | } |
| 206 | return core.retry |
| 207 | }) |
| 208 | |
| 209 | /** @internal */ |
| 210 | export const fiberReadLocks = (self: TReentrantLock.TReentrantLock): STM.STM<number> => |
no test coverage detected