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

Function acquireWrite

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

Source from the content-addressed store, hash-verified

185
186/** @internal */
187export 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 */
210export const fiberReadLocks = (self: TReentrantLock.TReentrantLock): STM.STM<number> =>

Callers 2

tReentrantLock.tsFile · 0.85
writeLockFunction · 0.85

Calls 5

isReadLockFunction · 0.85
noOtherHolderFunction · 0.85
isWriteLockFunction · 0.85
unsafeGetMethod · 0.80
readLocksHeldMethod · 0.65

Tested by

no test coverage detected