diff options
Diffstat (limited to 'lib/system/channels.nim')
-rw-r--r-- | lib/system/channels.nim | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/lib/system/channels.nim b/lib/system/channels.nim index e5535dbdc..a5d5c0802 100644 --- a/lib/system/channels.nim +++ b/lib/system/channels.nim @@ -14,7 +14,7 @@ ## **Note:** The current implementation of message passing is slow and does ## not work with cyclic data structures. -when not defined(NimString): +when not declared(NimString): {.error: "You must not import this module explicitly".} type @@ -226,15 +226,16 @@ proc recv*[TMsg](c: var TChannel[TMsg]): TMsg = llRecv(q, addr(result), cast[PNimType](getTypeInfo(result))) releaseSys(q.lock) -proc tryRecv*[TMsg](c: var TChannel[TMsg]): tuple[dataAvaliable: bool, +proc tryRecv*[TMsg](c: var TChannel[TMsg]): tuple[dataAvailable: bool, msg: TMsg] = ## try to receives a message from the channel `c` if available. Otherwise ## it returns ``(false, default(msg))``. var q = cast[PRawChannel](addr(c)) - if q.mask != ChannelDeadMask: - lockChannel(q): + if q.mask != ChannelDeadMask: + if tryAcquireSys(q.lock): llRecv(q, addr(result.msg), cast[PNimType](getTypeInfo(result.msg))) - result.dataAvaliable = true + result.dataAvailable = true + releaseSys(q.lock) proc peek*[TMsg](c: var TChannel[TMsg]): int = ## returns the current number of messages in the channel `c`. Returns -1 |