MCPcopy Index your code
hub / github.com/Effect-TS/effect / releaseWrite

Function releaseWrite

packages/effect/src/internal/stm/tReentrantLock.ts:269–285  ·  view source on GitHub ↗
(self: TReentrantLock.TReentrantLock)

Source from the content-addressed store, hash-verified

267
268/** @internal */
269export 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 */
288export const withLock = dual<

Callers 2

tReentrantLock.tsFile · 0.85
writeLockFunction · 0.85

Calls 4

writeLocksHeldMethod · 0.95
isWriteLockFunction · 0.85
makeReadLockFunction · 0.85
unsafeGetMethod · 0.80

Tested by

no test coverage detected