All Downloads are FREE. Search and download functionalities are using the official Maven repository.

nativeMain.app.cash.sqldelight.driver.native.util.PoolLock.kt Maven / Gradle / Ivy

package app.cash.sqldelight.driver.native.util

internal expect class PoolLock(reentrant: Boolean = false) {
  fun  withLock(
    action: CriticalSection.() -> R,
  ): R

  /**
   * Select one blocked thread in [CriticalSection.loopForConditionalResult] to be woken up for
   * re-evaluation, if any.
   */
  fun notifyConditionChanged()

  fun close(): Boolean

  inner class CriticalSection {
    /**
     * Evaluate the given lambda of a conditional result in an infinite loop, until the result is
     * available.
     *
     * If null is produced, the current thread enters suspension, and are only woken up for
     * re-evaluation by a subsequent [PoolLock.notifyConditionChanged] call. Note that the lock
     * would not be held by the current thread during its suspension. This allows resources
     * protected by the same lock to remain accessible by other threads, provided that they do not
     * depend on the same conditional result.
     */
    fun  loopForConditionalResult(block: () -> R?): R
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy