From fbb82a5c9c3ea9aef26041f47da27bf362b132e6 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Sun, 4 Apr 2021 18:38:30 -0700 Subject: [PATCH] skip limiting if limit is zero --- weed/util/limiter.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/weed/util/limiter.go b/weed/util/limiter.go index ccdaa701e..2debaaa85 100644 --- a/weed/util/limiter.go +++ b/weed/util/limiter.go @@ -85,16 +85,20 @@ func NewLimitedOutOfOrderProcessor(limit int32) (c *LimitedOutOfOrderProcessor) request := value.Interface().(OperationRequest) - c.processorLimitCond.L.Lock() - for atomic.LoadInt32(&c.currentProcessor) > c.processorLimit { - c.processorLimitCond.Wait() + if c.processorLimit > 0 { + c.processorLimitCond.L.Lock() + for atomic.LoadInt32(&c.currentProcessor) > c.processorLimit { + c.processorLimitCond.Wait() + } + atomic.AddInt32(&c.currentProcessor, 1) + c.processorLimitCond.L.Unlock() } - atomic.AddInt32(&c.currentProcessor, 1) - c.processorLimitCond.L.Unlock() go func() { - defer atomic.AddInt32(&c.currentProcessor, -1) - defer c.processorLimitCond.Signal() + if c.processorLimit > 0 { + defer atomic.AddInt32(&c.currentProcessor, -1) + defer c.processorLimitCond.Signal() + } request() }()