From 38c5da85d4bee87c89774acc161e88b40adc9f57 Mon Sep 17 00:00:00 2001 From: araq Date: Sun, 8 Feb 2026 01:28:00 +0100 Subject: [PATCH] prevent contention between producer/consumer threads --- lib/system/yrc.nim | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/lib/system/yrc.nim b/lib/system/yrc.nim index 9f82c68252..58e26afef2 100644 --- a/lib/system/yrc.nim +++ b/lib/system/yrc.nim @@ -56,11 +56,12 @@ include threadids type Stripe = object - lock: Lock - toInc: array[QueueSize, Cell] + lockInc: Lock toIncLen: int - toDec: array[QueueSize, (Cell, PNimTypeV2)] + toInc: array[QueueSize, Cell] + lockDec: Lock toDecLen: int + toDec: array[QueueSize, (Cell, PNimTypeV2)] var gYrcGlobalLock: Lock @@ -79,7 +80,7 @@ proc nimIncRefCyclic(p: pointer; cyclic: bool) {.compilerRtl, inl.} = let idx = getStripeIdx() while true: var overflow = false - withLock stripes[idx].lock: + withLock stripes[idx].lockInc: if stripes[idx].toIncLen < QueueSize: stripes[idx].toInc[stripes[idx].toIncLen] = h stripes[idx].toIncLen += 1 @@ -88,19 +89,22 @@ proc nimIncRefCyclic(p: pointer; cyclic: bool) {.compilerRtl, inl.} = if overflow: withLock gYrcGlobalLock: for i in 0..