/**
 * The `TxReentrantLock` module provides a transactional read/write lock whose
 * ownership is tracked per fiber. Multiple fibers may hold read locks at the
 * same time, while a write lock gives one fiber exclusive access.
 *
 * **Mental model**
 *
 * The lock stores reader counts and an optional writer count in transactional
 * state. A fiber can reacquire locks it already owns, so nested read or write
 * sections are safe as long as each acquisition is matched by a release. A
 * write acquisition waits when another fiber owns a read or write lock, and a
 * read acquisition waits when another fiber owns the write lock.
 *
 * **Common tasks**
 *
 * - Use `withReadLock` to run an effect that may share access with other
 *   readers.
 * - Use `withWriteLock` or `withLock` to run an effect with exclusive access.
 * - Use `readLock` or `writeLock` when lock ownership should be tied to an
 *   existing scope.
 *
 * **Example** (Protecting a read/write workflow)
 *
 * ```ts
 * import { Effect, Ref, TxReentrantLock } from "effect"
 *
 * const program = Effect.gen(function*() {
 *   const lock = yield* TxReentrantLock.make()
 *   const state = yield* Ref.make(0)
 *
 *   yield* TxReentrantLock.withWriteLock(lock, Ref.update(state, (n) => n + 1))
 *   return yield* TxReentrantLock.withReadLock(lock, Ref.get(state))
 * })
 * ```
 *
 * **Gotchas**
 *
 * - Manual acquisitions are counted; release the same number of times or use
 *   the scoped and `with*` helpers.
 * - Releasing a lock from a fiber that does not own it leaves the lock
 *   unchanged and returns `0`.
 *
 * @since 4.0.0
 */
import * as Effect from "./Effect.ts";
import type { Inspectable } from "./Inspectable.ts";
import type { Pipeable } from "./Pipeable.ts";
import type * as Scope from "./Scope.ts";
declare const TypeId = "~effect/transactions/TxReentrantLock";
/**
 * A TxReentrantLock provides a transactional read/write lock with reentrant semantics.
 * Multiple readers can hold the lock concurrently, or a single writer can hold exclusive
 * access. A fiber holding the write lock may acquire additional read/write locks (reentrancy).
 *
 * **Example** (Using read and write locks)
 *
 * ```ts
 * import { Effect, TxReentrantLock } from "effect"
 *
 * const program = Effect.gen(function*() {
 *   const lock = yield* TxReentrantLock.make()
 *
 *   // Multiple readers can proceed concurrently
 *   yield* TxReentrantLock.withReadLock(lock, Effect.succeed("reading"))
 *
 *   // Writer gets exclusive access
 *   yield* TxReentrantLock.withWriteLock(lock, Effect.succeed("writing"))
 * })
 * ```
 *
 * @category models
 * @since 4.0.0
 */
export interface TxReentrantLock extends Inspectable, Pipeable {
    readonly [TypeId]: typeof TypeId;
}
/**
 * Creates a new TxReentrantLock.
 *
 * **Example** (Creating a reentrant lock)
 *
 * ```ts
 * import { Effect, TxReentrantLock } from "effect"
 *
 * const program = Effect.gen(function*() {
 *   const lock = yield* TxReentrantLock.make()
 *   const isLocked = yield* TxReentrantLock.locked(lock)
 *   console.log(isLocked) // false
 * })
 * ```
 *
 * @category constructors
 * @since 2.0.0
 */
export declare const make: () => Effect.Effect<TxReentrantLock>;
/**
 * Acquires a read lock. Blocks if another fiber holds the write lock.
 * If the current fiber already holds the write lock, the read lock is granted (reentrancy).
 * Returns the current number of read locks held by this fiber.
 *
 * **Example** (Acquiring a read lock)
 *
 * ```ts
 * import { Effect, TxReentrantLock } from "effect"
 *
 * const program = Effect.gen(function*() {
 *   const lock = yield* TxReentrantLock.make()
 *   const count = yield* TxReentrantLock.acquireRead(lock)
 *   console.log(count) // 1
 *   yield* TxReentrantLock.releaseRead(lock)
 * })
 * ```
 *
 * @category mutations
 * @since 2.0.0
 */
export declare const acquireRead: (self: TxReentrantLock) => Effect.Effect<number>;
/**
 * Acquires the write lock for the current fiber.
 *
 * **When to use**
 *
 * Use to enter an exclusive section manually when `withWriteLock` is not the
 * right shape.
 *
 * **Details**
 *
 * Blocks if any other fiber holds a read or write lock. If the current fiber
 * already holds the write lock, the count is incremented. If the current fiber
 * holds a read lock, the write lock is granted as an upgrade.
 *
 * Returns the current number of write locks held by this fiber.
 *
 * **Example** (Acquiring a write lock)
 *
 * ```ts
 * import { Effect, TxReentrantLock } from "effect"
 *
 * const program = Effect.gen(function*() {
 *   const lock = yield* TxReentrantLock.make()
 *   const count = yield* TxReentrantLock.acquireWrite(lock)
 *   console.log(count) // 1
 *   yield* TxReentrantLock.releaseWrite(lock)
 * })
 * ```
 *
 * @category mutations
 * @since 2.0.0
 */
export declare const acquireWrite: (self: TxReentrantLock) => Effect.Effect<number>;
/**
 * Releases one read lock held by the current fiber.
 *
 * **When to use**
 *
 * Use to leave a manually acquired read lock.
 *
 * **Details**
 *
 * Returns the remaining number of read locks held by this fiber.
 *
 * **Example** (Releasing a read lock)
 *
 * ```ts
 * import { Effect, TxReentrantLock } from "effect"
 *
 * const program = Effect.gen(function*() {
 *   const lock = yield* TxReentrantLock.make()
 *   yield* TxReentrantLock.acquireRead(lock)
 *   const remaining = yield* TxReentrantLock.releaseRead(lock)
 *   console.log(remaining) // 0
 * })
 * ```
 *
 * @category mutations
 * @since 2.0.0
 */
export declare const releaseRead: (self: TxReentrantLock) => Effect.Effect<number>;
/**
 * Releases one write lock held by the current fiber.
 *
 * **When to use**
 *
 * Use to leave a manually acquired write lock.
 *
 * **Details**
 *
 * Returns the remaining number of write locks held by this fiber.
 *
 * **Example** (Releasing a write lock)
 *
 * ```ts
 * import { Effect, TxReentrantLock } from "effect"
 *
 * const program = Effect.gen(function*() {
 *   const lock = yield* TxReentrantLock.make()
 *   yield* TxReentrantLock.acquireWrite(lock)
 *   const remaining = yield* TxReentrantLock.releaseWrite(lock)
 *   console.log(remaining) // 0
 * })
 * ```
 *
 * @category mutations
 * @since 2.0.0
 */
export declare const releaseWrite: (self: TxReentrantLock) => Effect.Effect<number>;
/**
 * Acquires a read lock for the duration of the scope.
 * The lock is automatically released when the scope closes.
 *
 * **Example** (Holding a scoped read lock)
 *
 * ```ts
 * import { Effect, TxReentrantLock } from "effect"
 *
 * const program = Effect.gen(function*() {
 *   const lock = yield* TxReentrantLock.make()
 *
 *   yield* Effect.scoped(
 *     Effect.gen(function*() {
 *       yield* TxReentrantLock.readLock(lock)
 *       // read lock is held for the duration of the scope
 *     })
 *   )
 *   // read lock is released
 * })
 * ```
 *
 * @category mutations
 * @since 2.0.0
 */
export declare const readLock: (self: TxReentrantLock) => Effect.Effect<number, never, Scope.Scope>;
/**
 * Acquires a write lock for the duration of the scope.
 * The lock is automatically released when the scope closes.
 *
 * **Example** (Holding a scoped write lock)
 *
 * ```ts
 * import { Effect, TxReentrantLock } from "effect"
 *
 * const program = Effect.gen(function*() {
 *   const lock = yield* TxReentrantLock.make()
 *
 *   yield* Effect.scoped(
 *     Effect.gen(function*() {
 *       yield* TxReentrantLock.writeLock(lock)
 *       // write lock is held for the duration of the scope
 *     })
 *   )
 *   // write lock is released
 * })
 * ```
 *
 * @category mutations
 * @since 2.0.0
 */
export declare const writeLock: (self: TxReentrantLock) => Effect.Effect<number, never, Scope.Scope>;
/**
 * Runs the provided effect while holding a read lock. The lock is automatically
 * released after the effect completes, fails, or is interrupted.
 *
 * **Example** (Running an effect with a read lock)
 *
 * ```ts
 * import { Effect, TxReentrantLock } from "effect"
 *
 * const program = Effect.gen(function*() {
 *   const lock = yield* TxReentrantLock.make()
 *   const result = yield* TxReentrantLock.withReadLock(
 *     lock,
 *     Effect.succeed("read data")
 *   )
 *   console.log(result) // "read data"
 * })
 * ```
 *
 * @category mutations
 * @since 2.0.0
 */
export declare const withReadLock: {
    /**
     * Runs the provided effect while holding a read lock. The lock is automatically
     * released after the effect completes, fails, or is interrupted.
     *
     * **Example** (Running an effect with a read lock)
     *
     * ```ts
     * import { Effect, TxReentrantLock } from "effect"
     *
     * const program = Effect.gen(function*() {
     *   const lock = yield* TxReentrantLock.make()
     *   const result = yield* TxReentrantLock.withReadLock(
     *     lock,
     *     Effect.succeed("read data")
     *   )
     *   console.log(result) // "read data"
     * })
     * ```
     *
     * @category mutations
     * @since 2.0.0
     */
    <A, E, R>(effect: Effect.Effect<A, E, R>): (self: TxReentrantLock) => Effect.Effect<A, E, R>;
    /**
     * Runs the provided effect while holding a read lock. The lock is automatically
     * released after the effect completes, fails, or is interrupted.
     *
     * **Example** (Running an effect with a read lock)
     *
     * ```ts
     * import { Effect, TxReentrantLock } from "effect"
     *
     * const program = Effect.gen(function*() {
     *   const lock = yield* TxReentrantLock.make()
     *   const result = yield* TxReentrantLock.withReadLock(
     *     lock,
     *     Effect.succeed("read data")
     *   )
     *   console.log(result) // "read data"
     * })
     * ```
     *
     * @category mutations
     * @since 2.0.0
     */
    <A, E, R>(self: TxReentrantLock, effect: Effect.Effect<A, E, R>): Effect.Effect<A, E, R>;
};
/**
 * Runs the provided effect while holding a write lock. The lock is automatically
 * released after the effect completes, fails, or is interrupted.
 *
 * **Example** (Running an effect with a write lock)
 *
 * ```ts
 * import { Effect, TxReentrantLock } from "effect"
 *
 * const program = Effect.gen(function*() {
 *   const lock = yield* TxReentrantLock.make()
 *   const result = yield* TxReentrantLock.withWriteLock(
 *     lock,
 *     Effect.succeed("wrote data")
 *   )
 *   console.log(result) // "wrote data"
 * })
 * ```
 *
 * @category mutations
 * @since 2.0.0
 */
export declare const withWriteLock: {
    /**
     * Runs the provided effect while holding a write lock. The lock is automatically
     * released after the effect completes, fails, or is interrupted.
     *
     * **Example** (Running an effect with a write lock)
     *
     * ```ts
     * import { Effect, TxReentrantLock } from "effect"
     *
     * const program = Effect.gen(function*() {
     *   const lock = yield* TxReentrantLock.make()
     *   const result = yield* TxReentrantLock.withWriteLock(
     *     lock,
     *     Effect.succeed("wrote data")
     *   )
     *   console.log(result) // "wrote data"
     * })
     * ```
     *
     * @category mutations
     * @since 2.0.0
     */
    <A, E, R>(effect: Effect.Effect<A, E, R>): (self: TxReentrantLock) => Effect.Effect<A, E, R>;
    /**
     * Runs the provided effect while holding a write lock. The lock is automatically
     * released after the effect completes, fails, or is interrupted.
     *
     * **Example** (Running an effect with a write lock)
     *
     * ```ts
     * import { Effect, TxReentrantLock } from "effect"
     *
     * const program = Effect.gen(function*() {
     *   const lock = yield* TxReentrantLock.make()
     *   const result = yield* TxReentrantLock.withWriteLock(
     *     lock,
     *     Effect.succeed("wrote data")
     *   )
     *   console.log(result) // "wrote data"
     * })
     * ```
     *
     * @category mutations
     * @since 2.0.0
     */
    <A, E, R>(self: TxReentrantLock, effect: Effect.Effect<A, E, R>): Effect.Effect<A, E, R>;
};
/**
 * Runs an effect while holding a write lock.
 *
 * **When to use**
 *
 * Use as the short alias for {@link withWriteLock}.
 *
 * **Example** (Running an effect with exclusive access)
 *
 * ```ts
 * import { Effect, TxReentrantLock } from "effect"
 *
 * const program = Effect.gen(function*() {
 *   const lock = yield* TxReentrantLock.make()
 *   const result = yield* TxReentrantLock.withLock(
 *     lock,
 *     Effect.succeed("exclusive operation")
 *   )
 *   console.log(result) // "exclusive operation"
 * })
 * ```
 *
 * @category mutations
 * @since 2.0.0
 */
export declare const withLock: {
    /**
     * Runs an effect while holding a write lock.
     *
     * **When to use**
     *
     * Use as the short alias for {@link withWriteLock}.
     *
     * **Example** (Running an effect with exclusive access)
     *
     * ```ts
     * import { Effect, TxReentrantLock } from "effect"
     *
     * const program = Effect.gen(function*() {
     *   const lock = yield* TxReentrantLock.make()
     *   const result = yield* TxReentrantLock.withLock(
     *     lock,
     *     Effect.succeed("exclusive operation")
     *   )
     *   console.log(result) // "exclusive operation"
     * })
     * ```
     *
     * @category mutations
     * @since 2.0.0
     */
    <A, E, R>(effect: Effect.Effect<A, E, R>): (self: TxReentrantLock) => Effect.Effect<A, E, R>;
    /**
     * Runs an effect while holding a write lock.
     *
     * **When to use**
     *
     * Use as the short alias for {@link withWriteLock}.
     *
     * **Example** (Running an effect with exclusive access)
     *
     * ```ts
     * import { Effect, TxReentrantLock } from "effect"
     *
     * const program = Effect.gen(function*() {
     *   const lock = yield* TxReentrantLock.make()
     *   const result = yield* TxReentrantLock.withLock(
     *     lock,
     *     Effect.succeed("exclusive operation")
     *   )
     *   console.log(result) // "exclusive operation"
     * })
     * ```
     *
     * @category mutations
     * @since 2.0.0
     */
    <A, E, R>(self: TxReentrantLock, effect: Effect.Effect<A, E, R>): Effect.Effect<A, E, R>;
};
/**
 * Returns the total number of read locks held across all fibers.
 *
 * **Example** (Counting read locks)
 *
 * ```ts
 * import { Effect, TxReentrantLock } from "effect"
 *
 * const program = Effect.gen(function*() {
 *   const lock = yield* TxReentrantLock.make()
 *   yield* TxReentrantLock.acquireRead(lock)
 *   const count = yield* TxReentrantLock.readLocks(lock)
 *   console.log(count) // 1
 *   yield* TxReentrantLock.releaseRead(lock)
 * })
 * ```
 *
 * @category getters
 * @since 2.0.0
 */
export declare const readLocks: (self: TxReentrantLock) => Effect.Effect<number>;
/**
 * Returns the number of write locks held (0 or the reentrant count).
 *
 * **Example** (Counting write locks)
 *
 * ```ts
 * import { Effect, TxReentrantLock } from "effect"
 *
 * const program = Effect.gen(function*() {
 *   const lock = yield* TxReentrantLock.make()
 *   const count = yield* TxReentrantLock.writeLocks(lock)
 *   console.log(count) // 0
 * })
 * ```
 *
 * @category getters
 * @since 2.0.0
 */
export declare const writeLocks: (self: TxReentrantLock) => Effect.Effect<number>;
/**
 * Checks whether the lock is held by any fiber (read or write).
 *
 * **Example** (Checking whether a lock is held)
 *
 * ```ts
 * import { Effect, TxReentrantLock } from "effect"
 *
 * const program = Effect.gen(function*() {
 *   const lock = yield* TxReentrantLock.make()
 *   const isLocked = yield* TxReentrantLock.locked(lock)
 *   console.log(isLocked) // false
 * })
 * ```
 *
 * @category getters
 * @since 2.0.0
 */
export declare const locked: (self: TxReentrantLock) => Effect.Effect<boolean>;
/**
 * Checks whether any fiber holds a read lock.
 *
 * **Example** (Checking whether a read lock is held)
 *
 * ```ts
 * import { Effect, TxReentrantLock } from "effect"
 *
 * const program = Effect.gen(function*() {
 *   const lock = yield* TxReentrantLock.make()
 *   const isReadLocked = yield* TxReentrantLock.readLocked(lock)
 *   console.log(isReadLocked) // false
 * })
 * ```
 *
 * @category getters
 * @since 2.0.0
 */
export declare const readLocked: (self: TxReentrantLock) => Effect.Effect<boolean>;
/**
 * Checks whether any fiber holds a write lock.
 *
 * **Example** (Checking whether a write lock is held)
 *
 * ```ts
 * import { Effect, TxReentrantLock } from "effect"
 *
 * const program = Effect.gen(function*() {
 *   const lock = yield* TxReentrantLock.make()
 *   const isWriteLocked = yield* TxReentrantLock.writeLocked(lock)
 *   console.log(isWriteLocked) // false
 * })
 * ```
 *
 * @category getters
 * @since 2.0.0
 */
export declare const writeLocked: (self: TxReentrantLock) => Effect.Effect<boolean>;
/**
 * Checks whether the given value is a TxReentrantLock.
 *
 * **Example** (Checking for TxReentrantLock values)
 *
 * ```ts
 * import { TxReentrantLock } from "effect"
 *
 * declare const someValue: unknown
 *
 * if (TxReentrantLock.isTxReentrantLock(someValue)) {
 *   console.log("This is a TxReentrantLock")
 * }
 * ```
 *
 * @category guards
 * @since 4.0.0
 */
export declare const isTxReentrantLock: (u: unknown) => u is TxReentrantLock;
export {};
//# sourceMappingURL=TxReentrantLock.d.ts.map