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

Function adjustRead

packages/effect/src/internal/stm/tReentrantLock.ts:156–181  ·  view source on GitHub ↗
(self: TReentrantLock.TReentrantLock, delta: number)

Source from the content-addressed store, hash-verified

154}
155
156const adjustRead = (self: TReentrantLock.TReentrantLock, delta: number): STM.STM<number> =>
157 core.withSTMRuntime((runtime) => {
158 const lock = tRef.unsafeGet(self.state, runtime.journal)
159 if (isReadLock(lock)) {
160 const result = adjustReadLock(lock, runtime.fiberId, delta)
161 tRef.unsafeSet(self.state, result, runtime.journal)
162 return core.succeed(result.readLocksHeld(runtime.fiberId))
163 }
164 if (isWriteLock(lock) && Equal.equals(runtime.fiberId)(lock.fiberId)) {
165 const newTotal = lock.readLocks + delta
166 if (newTotal < 0) {
167 throw new Error(
168 `Defect: Fiber ${
169 FiberId.threadName(runtime.fiberId)
170 } releasing read locks it does not hold, newTotal: ${newTotal}`
171 )
172 }
173 tRef.unsafeSet(
174 self.state,
175 new WriteLock(newTotal, lock.writeLocks, runtime.fiberId),
176 runtime.journal
177 )
178 return core.succeed(newTotal)
179 }
180 return core.retry
181 })
182
183/** @internal */
184export const acquireRead = (self: TReentrantLock.TReentrantLock): STM.STM<number> => adjustRead(self, 1)

Callers 2

acquireReadFunction · 0.85
releaseReadFunction · 0.85

Calls 5

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

Tested by

no test coverage detected