2022-04-26 22:22:02 +00:00
|
|
|
//go:build !no_ptrguard
|
|
|
|
// +build !no_ptrguard
|
2021-01-16 20:07:12 +00:00
|
|
|
|
|
|
|
package cutil
|
|
|
|
|
|
|
|
import (
|
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
|
|
|
// SyncBuffer is a C buffer connected to a data slice
|
|
|
|
type SyncBuffer struct {
|
|
|
|
pg *PtrGuard
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewSyncBuffer creates a C buffer from a data slice and stores it at CPtr
|
|
|
|
func NewSyncBuffer(cPtr CPtr, data []byte) *SyncBuffer {
|
|
|
|
var v SyncBuffer
|
|
|
|
v.pg = NewPtrGuard(cPtr, unsafe.Pointer(&data[0]))
|
|
|
|
return &v
|
|
|
|
}
|
|
|
|
|
|
|
|
// Release releases the C buffer and nulls its stored pointer
|
|
|
|
func (v *SyncBuffer) Release() {
|
|
|
|
v.pg.Release()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sync asserts that changes in the C buffer are available in the data
|
|
|
|
// slice
|
2022-02-07 23:01:43 +00:00
|
|
|
func (*SyncBuffer) Sync() {}
|