From b4f186a5d496fd2085a2bf1405a6384cd7802236 Mon Sep 17 00:00:00 2001 From: chenshijun <chenshijun@aiotlink.com> Date: 星期五, 24 四月 2020 16:34:05 +0800 Subject: [PATCH] 把延时单位修正成const=5毫秒,增加CreateShmOnlyTime接口 --- shmqueue.go | 14 +++++++------- 1 files changed, 7 insertions(+), 7 deletions(-) diff --git a/shmqueue.go b/shmqueue.go index 8c5b3a4..227ee4a 100644 --- a/shmqueue.go +++ b/shmqueue.go @@ -12,7 +12,7 @@ ) const ( - TimePeriodPutOrGet = time.Duration(1) * time.Microsecond + TimePeriodPutOrGet = time.Duration(5)*time.Millisecond //ms ) //Element info @@ -146,14 +146,14 @@ func (eqi *EsQueueInfo) QueueSize() int { var putPos, getPos uint32 var quantity uint32 + getPos = atomic.LoadUint32(&eqi.Queue.getPos) putPos = atomic.LoadUint32(&eqi.Queue.putPos) if putPos >= getPos { quantity = putPos - getPos } else { - //quantity = q.capMod + (putPos - getPos) - quantity = (eqi.Queue.capMod + (putPos - getPos)) % eqi.Queue.capMod + quantity = eqi.Queue.capMod + (putPos - getPos) } return int(quantity) @@ -164,7 +164,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) } } @@ -184,8 +185,7 @@ if putPos >= getPos { posCnt = putPos - getPos } else { - //posCnt = capMod + (putPos - getPos) - posCnt = (capMod + (putPos - getPos)) % capMod + posCnt = capMod + (putPos - getPos) } //todo @@ -300,7 +300,7 @@ putNo := atomic.LoadUint32(&cache.putNo) if getPosNew == getNo && getNo == putNo-eqi.Queue.capacity { val := cache.value - cache.value = ElemInfo{PicId: 0} + cache.value = ElemInfo{PicId: 0, InfoId:0} atomic.AddUint32(&cache.getNo, eqi.Queue.capacity) return val, true, int(posCnt - 1) } else { -- Gitblit v1.8.0