import * as tsplus_module_1 from "@tsplus/stdlib/collections/HashMap/remove";
import * as tsplus_module_2 from "@tsplus/stdlib/data/Maybe/definition";
import * as tsplus_module_3 from "@tsplus/stdlib/collections/HashMap/modify";
import * as tsplus_module_4 from "@effect/core/stm/TReentrantLock/definition";
import * as tsplus_module_5 from "@effect/core/stm/TReentrantLock/operations/ReadLock/make";
import { concreteReadLock } from "@effect/core/stm/TReentrantLock/operations/_internal/InternalReadLock";
/**
 * Adjusts the number of read locks held by the specified fiber id.
 *
 * @tsplus fluent ets/TReentrantLock/ReadLock adjust
 */

export function adjust_(self, fiberId, adjust) {
  void 0;
  const total = self.readLocksHeld(fiberId);
  const newTotal = total + adjust;

  if (newTotal < 0) {
    throw new Error(`Defect: Fiber ${fiberId} releasing read lock it does not hold: ${self.readers}`);
  }

  return tsplus_module_5.make(newTotal === 0 ? tsplus_module_1.remove_(self.readers, fiberId) : tsplus_module_3.modify_(self.readers, fiberId, _ => tsplus_module_2.some(newTotal)));
}
/**
 * Adjusts the number of read locks held by the specified fiber id.
 *
 * @tsplus static ets/TReentrantLock/ReadLock/Aspects adjust
 */

export const adjust = (fiberId, adjust) => self => adjust_(self, fiberId, adjust);
//# sourceMappingURL=adjust.mjs.map