"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.adjust = void 0;
exports.adjust_ = adjust_;

var tsplus_module_1 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@tsplus/stdlib/collections/HashMap/remove"));

var tsplus_module_2 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@tsplus/stdlib/data/Maybe/definition"));

var tsplus_module_3 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@tsplus/stdlib/collections/HashMap/modify"));

var tsplus_module_4 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/stm/TReentrantLock/definition"));

var tsplus_module_5 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/stm/TReentrantLock/operations/ReadLock/make"));

var _InternalReadLock = /*#__PURE__*/require("@effect/core/stm/TReentrantLock/operations/_internal/InternalReadLock");

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

/**
 * Adjusts the number of read locks held by the specified fiber id.
 *
 * @tsplus fluent ets/TReentrantLock/ReadLock adjust
 */
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
 */


const adjust = (fiberId, adjust) => self => adjust_(self, fiberId, adjust);

exports.adjust = adjust;
//# sourceMappingURL=adjust.js.map