chenshijun
2020-05-22 309302ff1743e28052a40a640b05b15ec3f58ebd
shmqueue.go
@@ -12,7 +12,7 @@
)
const (
   TimePeriodPutOrGet = time.Duration(5) * time.Microsecond
   TimePeriodPutOrGet = time.Duration(5)*time.Millisecond //ms
)
//Element info
@@ -72,6 +72,9 @@
   shmLen = shmblocks*uint32(unsafe.Sizeof(datainfo)) + uint32(unsafe.Sizeof(shmstruct))
   data, shmid := CreateRawShm(ctx, int(shmLen), key)
   if shmid == -1 {
      return nil
   }
   q := bytes2shmEsQueue(data)
   //init parameters
   q.capacity = shmblocks
@@ -104,6 +107,9 @@
   var eqi EsQueueInfo
   data, shmid := AttachRawShm(ctx, key)
   if shmid == -1 {
      return nil
   }
   shmdata := bytes2shmEsQueue(data)
   eqi.EsCaches = ptr2esCache(unsafe.Pointer(&shmdata.cache), int(shmdata.capacity))
   //fmt.Println("AttachQueue EsCaches:", eqi.EsCaches)
@@ -189,8 +195,8 @@
   }
   //todo
   if posCnt >= capMod-1 {
   //if posCnt >= capMod {
   //if posCnt >= capMod-1 {
   if posCnt >= capMod {
      runtime.Gosched()
      return false, int(posCnt)
   }
@@ -204,8 +210,6 @@
   cache = &(eqi.EsCaches[putPosNew&capMod])
   //tryMax := 100
   //tryCount := 0
   for {
      getNo := atomic.LoadUint32(&cache.getNo)
      putNo := atomic.LoadUint32(&cache.putNo)
@@ -216,10 +220,6 @@
      } else {
         runtime.Gosched()
      }
      //tryCount++
      //if tryCount >= tryMax {
      //   return false, int(posCnt)
      //}
   }
}
@@ -301,8 +301,6 @@
   cache = &(eqi.EsCaches[getPosNew&capMod])
   //tryMax := 100
   //tryCount := 0
   for {
      getNo := atomic.LoadUint32(&cache.getNo)
      putNo := atomic.LoadUint32(&cache.putNo)
@@ -314,10 +312,6 @@
      } else {
         runtime.Gosched()
      }
      //tryCount++
      //if tryCount >= tryMax {
      //   return ElemInfo{}, false, int(posCnt)
      //}
   }
}