chenshijun
2020-03-12 637b5145c12ac150a00026e4929cace1ec3e593d
闭包初步测试通过
1个文件已修改
24 ■■■■ 已修改文件
shmqueue.go 24 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
shmqueue.go
@@ -17,7 +17,8 @@
//Element info
type ElemInfo struct {
    ShmId int
    PicId  int
    InfoId int
}
//queue info
@@ -143,7 +144,7 @@
    shmdata := bytes2shmEsQueue(data)
    fmt.Println("shmdata:", shmdata)
    eqi.EsCaches = ptr2esCache(unsafe.Pointer(&shmdata.cache), int(shmdata.capacity))
    //fmt.Println("EsCaches:", eqi.EsCaches)
    fmt.Println("EsCaches:", eqi.EsCaches)
    eqi.Queue = shmdata
    eqi.ShmKey = key
@@ -155,12 +156,13 @@
// ReleaseQueue detach an exist shm queue
func (eqi *EsQueueInfo) ReleaseQueue() {
    fmt.Println("ReleaseQueue: key", eqi.ShmKey)
    fmt.Printf("ReleaseQueue: key=%x\n", eqi.ShmKey)
    DestroyShm(eqi.ShmData)
}
// RemoveShmId remove an exist shm queue (ipcrm -m shmid)
func (eqi *EsQueueInfo) RemoveShmId() error {
    fmt.Printf("RemoveShmId: key=%x\n", eqi.ShmKey)
    return shm.Rm(eqi.ShmID)
}
@@ -193,6 +195,19 @@
    }
    return int(quantity)
}
// Status status of shm queue
func (eqi *EsQueueInfo) QueueElements() []ElemInfo {
    var elems []ElemInfo
    for i := 0; i < len(eqi.EsCaches); i++ {
        if eqi.EsCaches[i].value.PicId != 0 && eqi.EsCaches[i].value.InfoId != 0 {
            elems = append(elems, eqi.EsCaches[i].value)
        }
    }
    return elems
}
// Put 单次写入,可能失败
@@ -309,7 +324,7 @@
        putNo := atomic.LoadUint32(&cache.putNo)
        if getPosNew == getNo && getNo == putNo-eqi.Queue.capacity {
            val := cache.value
            cache.value = ElemInfo{ShmId:0}
            cache.value = ElemInfo{PicId: 0}
            atomic.AddUint32(&cache.getNo, eqi.Queue.capacity)
            return val, true, int(posCnt - 1)
        } else {
@@ -365,4 +380,3 @@
    v++
    return v
}