summaryrefslogtreecommitdiffhomepage
path: root/pkg/tcpip/link/sharedmem/pipe/pipe_unsafe.go
blob: d536abedf871903c2e858c1f297ecd6b4fc2e40c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// Copyright 2016 The Netstack Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package pipe

import (
	"sync/atomic"
	"unsafe"
)

func (p *pipe) write(idx uint64, v uint64) {
	ptr := (*uint64)(unsafe.Pointer(&p.buffer[idx&offsetMask:][:8][0]))
	*ptr = v
}

func (p *pipe) writeAtomic(idx uint64, v uint64) {
	ptr := (*uint64)(unsafe.Pointer(&p.buffer[idx&offsetMask:][:8][0]))
	atomic.StoreUint64(ptr, v)
}

func (p *pipe) readAtomic(idx uint64) uint64 {
	ptr := (*uint64)(unsafe.Pointer(&p.buffer[idx&offsetMask:][:8][0]))
	return atomic.LoadUint64(ptr)
}