Skip to content

Commit

Permalink
Rename
Browse files Browse the repository at this point in the history
  • Loading branch information
yschimke committed Apr 27, 2024
1 parent 9a48692 commit 8a23546
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions okhttp/src/main/kotlin/okhttp3/internal/connection/Locks.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,51 +36,61 @@ import okhttp3.internal.http2.Http2Writer
internal object Locks {
inline fun <T> Dispatcher.withLock(action: () -> T): T {
contract { callsInPlace(action, InvocationKind.EXACTLY_ONCE) }
return lock.withMonitoredLock(action)
return lock.runWithLock(action)
}

inline fun <T> RealConnection.withLock(action: () -> T): T {
contract { callsInPlace(action, InvocationKind.EXACTLY_ONCE) }
return lock.withMonitoredLock(action)
return lock.runWithLock(action)
}

inline fun <T> RealCall.withLock(action: () -> T): T {
contract { callsInPlace(action, InvocationKind.EXACTLY_ONCE) }
return lock.withMonitoredLock(action)
return lock.runWithLock(action)
}

inline fun <T> Http2Connection.withLock(action: () -> T): T {
contract { callsInPlace(action, InvocationKind.EXACTLY_ONCE) }
return lock.withMonitoredLock(action)
return lock.runWithLock(action)
}

inline fun <T> Http2Stream.withLock(action: () -> T): T {
contract { callsInPlace(action, InvocationKind.EXACTLY_ONCE) }
return lock.withMonitoredLock(action)
return lock.runWithLock(action)
}

inline fun <T> TaskRunner.withLock(action: () -> T): T {
contract { callsInPlace(action, InvocationKind.EXACTLY_ONCE) }
return lock.withMonitoredLock(action)
return lock.runWithLock(action)
}

inline fun <T> TaskQueue.withLock(action: () -> T): T {
contract { callsInPlace(action, InvocationKind.EXACTLY_ONCE) }
return lock.withMonitoredLock(action)
return lock.runWithLock(action)
}

inline fun <T> Http2Writer.withLock(action: () -> T): T {
// TODO can we assert we don't have the connection lock?

contract { callsInPlace(action, InvocationKind.EXACTLY_ONCE) }
return lock.withMonitoredLock(action)
return lock.runWithLock(action)
}

/**
* A no cost (inlined) alias to [ReentrantLock#newCondition] for an OkHttp Lock.
* No function on its own but places a central place that all conditions go through to allow
* temporary debugging.
*/
internal fun ReentrantLock.newLockCondition(): Condition {
return this.newCondition()
}

inline fun <T> ReentrantLock.withMonitoredLock(action: () -> T): T {
/**
* A no cost (inlined) alias to [ReentrantLock#withLock] for an OkHttp Lock.
* No function on its own but places a central place that all locks go through to allow
* temporary debugging.
*/
inline fun <T> ReentrantLock.runWithLock(action: () -> T): T {
contract { callsInPlace(action, InvocationKind.EXACTLY_ONCE) }
return withLock(action)
}
Expand Down

0 comments on commit 8a23546

Please sign in to comment.