| | |
| | | shm "basic.com/valib/goshm.git" |
| | | ) |
| | | |
| | | const sleepPeriod = time.Duration(5) * time.Millisecond |
| | | const ( |
| | | sleepPeriod = time.Duration(5) * time.Millisecond |
| | | attachTimes = 100 |
| | | ) |
| | | |
| | | // NewBlock shm block with size |
| | | func NewBlock(size int, key int) ([]byte, int, error) { |
| | |
| | | return data, id |
| | | } |
| | | |
| | | //AttachRawShmTimeout don't create |
| | | func AttachRawShmTimeout(ctx context.Context, key int) ([]byte, int) { |
| | | tryCount := 0 |
| | | data, id, err := AttachBlock(key) |
| | | if err != nil { |
| | | loopB: |
| | | for { |
| | | select { |
| | | case <-ctx.Done(): |
| | | return nil, -1 |
| | | default: |
| | | if err == nil || tryCount > attachTimes { |
| | | break loopB |
| | | } |
| | | time.Sleep(sleepPeriod) |
| | | data, id, err = AttachBlock(key) |
| | | tryCount++ |
| | | } |
| | | } |
| | | } |
| | | return data, id |
| | | } |
| | | |
| | | // CreateShmOnly create shm block with size, only space, no padding, return id(int) |
| | | // context for quit |
| | | func CreateShmOnly(ctx context.Context, size int, key int) int { |