From e485095690a71af1a9bc8e811eb4ea64a95508aa Mon Sep 17 00:00:00 2001 From: chenshijun <chenshijun@aiotlink.com> Date: 星期三, 15 四月 2020 15:47:39 +0800 Subject: [PATCH] shmData修改偏移的bug --- shmqueue.go | 29 ++++++++++++++++++----------- 1 files changed, 18 insertions(+), 11 deletions(-) diff --git a/shmqueue.go b/shmqueue.go index 8c5b3a4..2cc6908 100644 --- a/shmqueue.go +++ b/shmqueue.go @@ -139,13 +139,17 @@ // Capacity queue 瀹归噺锛屾�诲ぇ灏� func (eqi *EsQueueInfo) QueueCapacity() int { - return int(eqi.Queue.capMod) + var capMod uint32 + capMod = atomic.LoadUint32(&eqi.Queue.capMod) + return int(capMod) } // Size queue 瀹為檯澶у皬 func (eqi *EsQueueInfo) QueueSize() int { - var putPos, getPos uint32 + var putPos, getPos, capMod uint32 var quantity uint32 + + capMod = atomic.LoadUint32(&eqi.Queue.capMod) getPos = atomic.LoadUint32(&eqi.Queue.getPos) putPos = atomic.LoadUint32(&eqi.Queue.putPos) @@ -153,7 +157,7 @@ quantity = putPos - getPos } else { //quantity = q.capMod + (putPos - getPos) - quantity = (eqi.Queue.capMod + (putPos - getPos)) % eqi.Queue.capMod + quantity = (capMod + (putPos - getPos)) % capMod } return int(quantity) @@ -164,7 +168,8 @@ var elems []ElemInfo for i := 0; i < len(eqi.EsCaches); i++ { - if eqi.EsCaches[i].value.PicId != 0 && eqi.EsCaches[i].value.InfoId != 0 { + if eqi.EsCaches[i].value.PicId != -1 && eqi.EsCaches[i].value.InfoId != -1 && + eqi.EsCaches[i].value.PicId != 0 && eqi.EsCaches[i].value.InfoId != 0 { elems = append(elems, eqi.EsCaches[i].value) } } @@ -174,10 +179,11 @@ // Put 鍗曟鍐欏叆锛屽彲鑳藉け璐� func (eqi *EsQueueInfo) Put(val ElemInfo) (bool, int) { - var putPos, putPosNew, getPos, posCnt uint32 + var putPos, putPosNew, getPos, posCnt, capMod ,capacity uint32 var cache *esCache - capMod := eqi.Queue.capMod + capacity = atomic.LoadUint32(&eqi.Queue.capacity) + capMod = atomic.LoadUint32(&eqi.Queue.capMod) getPos = atomic.LoadUint32(&eqi.Queue.getPos) putPos = atomic.LoadUint32(&eqi.Queue.putPos) @@ -209,7 +215,7 @@ putNo := atomic.LoadUint32(&cache.putNo) if putPosNew == putNo && getNo == putNo { cache.value = val - atomic.AddUint32(&cache.putNo, eqi.Queue.capacity) + atomic.AddUint32(&cache.putNo, capacity) return true, int(posCnt + 1) } else { runtime.Gosched() @@ -269,10 +275,11 @@ // Get 鍗曟鑾峰彇锛屽彲鑳藉け璐� func (eqi *EsQueueInfo) Get() (ElemInfo, bool, int) { - var putPos, getPos, getPosNew, posCnt uint32 + var putPos, getPos, getPosNew, posCnt, capMod, capacity uint32 var cache *esCache - capMod := eqi.Queue.capMod + capacity = atomic.LoadUint32(&eqi.Queue.capacity) + capMod = atomic.LoadUint32(&eqi.Queue.capMod) putPos = atomic.LoadUint32(&eqi.Queue.putPos) getPos = atomic.LoadUint32(&eqi.Queue.getPos) @@ -298,10 +305,10 @@ for { getNo := atomic.LoadUint32(&cache.getNo) putNo := atomic.LoadUint32(&cache.putNo) - if getPosNew == getNo && getNo == putNo-eqi.Queue.capacity { + if getPosNew == getNo && getNo == putNo-capacity { val := cache.value cache.value = ElemInfo{PicId: 0} - atomic.AddUint32(&cache.getNo, eqi.Queue.capacity) + atomic.AddUint32(&cache.getNo, capacity) return val, true, int(posCnt - 1) } else { runtime.Gosched() -- Gitblit v1.8.0