Skip to content

Commit f2f320c

Browse files
committed
Negative count is non-blocking, can be investigated later (#49)
1 parent 9a343b8 commit f2f320c

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

weave/channels/channels_mpsc_unbounded_batch.nim

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ proc tryRecvBatch*[T](chan: var ChannelMpscUnboundedBatch[T], bFirst, bLast: var
147147
## Returns the number of items received
148148
##
149149
## If no items are returned bFirst and bLast are undefined
150+
## and should not be used.
150151
##
151152
## ⚠️ This leaks the next item
152153
## nil or overwrite it for further use in linked lists
@@ -172,9 +173,10 @@ proc tryRecvBatch*[T](chan: var ChannelMpscUnboundedBatch[T], bFirst, bLast: var
172173
# We lose the competition, bail out
173174
chan.front.next.store(front, moRelaxed)
174175
discard chan.count.fetchSub(result, moRelaxed)
175-
postCondition: chan.count.load(moRelaxed) >= 0
176+
postCondition: chan.count.load(moRelaxed) >= 0 # TODO: somehow it can be negative
176177
return
177178

179+
# front == last
178180
chan.front.next.store(nil, moRelaxed)
179181
if compareExchange(chan.back, last, chan.front.addr, moAcquireRelease):
180182
# We won and replaced the last node with the channel front

0 commit comments

Comments
 (0)