Skip to content

Commit

Permalink
revert to plain acquire
Browse files Browse the repository at this point in the history
  • Loading branch information
planetis-m committed Aug 16, 2024
1 parent 9c8f69c commit c18e393
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions threading/channels.nim
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,8 @@ proc channelSend(chan: ChannelRaw, data: pointer, size: int, blocking: static bo

when not blocking:
if chan.isFull(): return false
if not tryAcquire(chan.lock): return false
else:
acquire(chan.lock)

acquire(chan.lock)

# check for when another thread was faster to fill
when blocking:
Expand Down Expand Up @@ -222,9 +221,8 @@ proc channelReceive(chan: ChannelRaw, data: pointer, size: int, blocking: static

when not blocking:
if chan.isEmpty(): return false
if not tryAcquire(chan.lock): return false
else:
acquire(chan.lock)

acquire(chan.lock)

# check for when another thread was faster to empty
when blocking:
Expand Down Expand Up @@ -295,6 +293,9 @@ proc trySend*[T](c: Chan[T], src: sink Isolated[T]): bool {.inline.} =
## Doesn't block waiting for space in the channel to become available.
## Instead returns after an attempt to send a message was made.
##
## .. warning:: Blocking may occur if another thread holds the internal lock on
## the channel's buffer, causing the thread to wait until the lock is released.
##
## .. warning:: In high-concurrency situations, consider using an exponential
## backoff strategy to reduce contention and improve the success rate of
## operations.
Expand All @@ -320,6 +321,9 @@ proc tryTake*[T](c: Chan[T], src: var Isolated[T]): bool {.inline.} =
## Doesn't block waiting for space in the channel to become available.
## Instead returns after an attempt to send a message was made.
##
## .. warning:: Blocking may occur if another thread holds the internal lock on
## the channel's buffer, causing the thread to wait until the lock is released.
##
## .. warning:: In high-concurrency situations, consider using an exponential
## backoff strategy to reduce contention and improve the success rate of
## operations.
Expand All @@ -335,6 +339,9 @@ proc tryRecv*[T](c: Chan[T], dst: var T): bool {.inline.} =
##
## Doesn't block waiting for messages in the channel to become available.
## Instead returns after an attempt to receive a message was made.
##
## .. warning:: Blocking may occur if another thread holds the internal lock on
## the channel's buffer, causing the thread to wait until the lock is released.
##
## .. warning:: In high-concurrency situations, consider using an exponential
## backoff strategy to reduce contention and improve the success rate of
Expand Down

0 comments on commit c18e393

Please sign in to comment.