0ac2a08333b72a93e3b5f0b996d3cf954555a6bd..47099312089389a553e8a49f5e2c0739f061b839
2020-03-30 chenshijun
添加注释
470993 对比 | 目录
2020-03-30 chenshijun
添加注释
d4c6a6 对比 | 目录
1个文件已修改
16 ■■■■■ 已修改文件
shmData.go 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
shmData.go
@@ -5,7 +5,7 @@
    "unsafe"
)
// lock free queue struct
// []byte struct
type ShmDataInfo struct {
    Capacity uint32
    Cache    []byte
@@ -27,16 +27,17 @@
    return *(*[]byte)(unsafe.Pointer(&x))
}
//WriteShmData   data待写入的数据;   shmId:共享内存id,只attach,不create
func WriteShmData(data []byte, shmId int) error {
    shmdata,err := Attach(shmId)
    shmData,err := Attach(shmId)
    if err != nil {
        return err
    }
    sdi := shmData2Info(shmdata)
    if len(data) <= len(shmdata) {
    sdi := shmData2Info(shmData)
    if len(data) <= len(shmData) {
        sdi.Capacity = uint32(len(data))
    } else {
        sdi.Capacity = uint32(len(shmdata))
        sdi.Capacity = uint32(len(shmData))
    }
    tmpData := ptr2Slice(unsafe.Pointer(&sdi.Cache), int(sdi.Capacity))
@@ -45,13 +46,14 @@
    return nil
}
//ReadShmData attach到shmId对应的共享内存,并读出数据[]byte
func ReadShmData(shmId int) ([]byte,error) {
    shmdata,err := Attach(shmId)
    shmData,err := Attach(shmId)
    if err != nil {
        return nil,err
    }
    sdi := shmData2Info(shmdata)
    sdi := shmData2Info(shmData)
    tmpData := ptr2Slice(unsafe.Pointer(&sdi.Cache), int(sdi.Capacity))
    return tmpData, nil