Skip to content

Commit a080691

Browse files
committed
Fix conditional signal bug, fix overriding = hook
1. Conditionally sending the signal doesn't take into consideration the situation where only one side of a sender/receiver uses the blocking call. In a mixed situation a blocking end can never get a signal from a non-blocking end. So we need to send signals regardless of how the proc was invoked. 2. Fixes "Overriding `=` hook is deprecated; Override `=copy` hook instead".
1 parent 2544b57 commit a080691

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

threading/channels.nim

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,7 @@ proc recvUnbufferedMpmc(chan: ChannelRaw, data: pointer, size: int, blocking: st
280280
assert chan.isEmptyUnbuf()
281281

282282
release(chan.lock)
283-
when blocking:
284-
signal(chan.spaceAvailableCV)
283+
signal(chan.spaceAvailableCV)
285284
result = true
286285

287286
proc recvMpmc(chan: ChannelRaw, data: pointer, size: int, blocking: static bool): bool =
@@ -320,8 +319,7 @@ proc recvMpmc(chan: ChannelRaw, data: pointer, size: int, blocking: static bool)
320319
chan.tail = 0
321320

322321
release(chan.lock)
323-
when blocking:
324-
signal(chan.spaceAvailableCV)
322+
signal(chan.spaceAvailableCV)
325323
result = true
326324

327325

@@ -340,7 +338,7 @@ proc `=destroy`*[T](c: var Chan[T]) =
340338
else:
341339
atomicDec(c.d.atomicCounter)
342340

343-
proc `=`*[T](dest: var Chan[T], src: Chan[T]) =
341+
proc `=copy`*[T](dest: var Chan[T], src: Chan[T]) =
344342
## Shares `Channel` by reference counting.
345343
if src.d != nil:
346344
atomicInc(src.d.atomicCounter)

0 commit comments

Comments
 (0)