mirror of
https://github.com/ii64/gouring.git
synced 2025-04-26 05:42:48 +02:00
* support for sqe128, cqe32 * using unsafe.Add * compile-time size guard/check * added support for uring_cmd
107 lines
2.3 KiB
Go
107 lines
2.3 KiB
Go
package gouring
|
|
|
|
import (
|
|
"unsafe"
|
|
)
|
|
|
|
type uint32Array = unsafe.Pointer // *uint32
|
|
|
|
func uint32Array_Index(u uint32Array, i uintptr) *uint32 {
|
|
|
|
return (*uint32)(unsafe.Add(u, SizeofUint32*i))
|
|
}
|
|
|
|
type ioUringSqeArray = unsafe.Pointer // *IoUringSqe
|
|
|
|
// ioUringSqeArray_Index OR SQE64
|
|
func ioUringSqeArray_Index(u ioUringSqeArray, i uintptr) *IoUringSqe {
|
|
|
|
return (*IoUringSqe)(unsafe.Add(u, SizeofIoUringSqe*i))
|
|
}
|
|
|
|
// ioUringSqe128Array_Index OR SQE128
|
|
func ioUringSqe128Array_Index(u ioUringSqeArray, i uintptr) *IoUringSqe {
|
|
|
|
return (*IoUringSqe)(unsafe.Add(u, (SizeofIoUringSqe+Align128IoUringSqe)*i))
|
|
}
|
|
|
|
//
|
|
|
|
type ioUringCqeArray = unsafe.Pointer // *IoUringCqe
|
|
|
|
// ioUringCqeArray_Index OR CQE16
|
|
func ioUringCqeArray_Index(u ioUringCqeArray, i uintptr) *IoUringCqe {
|
|
|
|
return (*IoUringCqe)(unsafe.Add(u, SizeofIoUringCqe*i))
|
|
}
|
|
|
|
// ioUringCqe32Array_Index OR CQE32
|
|
func ioUringCqe32Array_Index(u ioUringCqeArray, i uintptr) *IoUringCqe {
|
|
return (*IoUringCqe)(unsafe.Add(u, (SizeofIoUringCqe+Align32IoUringCqe)*i))
|
|
}
|
|
|
|
//
|
|
|
|
type UserData uint64
|
|
|
|
func (u *UserData) SetUint64(v uint64) {
|
|
putUintptr(unsafe.Pointer(u), uintptr(v))
|
|
|
|
}
|
|
func (u *UserData) SetUintptr(v uintptr) {
|
|
putUintptr(unsafe.Pointer(u), v)
|
|
}
|
|
func (u *UserData) SetUnsafe(ptr unsafe.Pointer) {
|
|
putUnsafe(unsafe.Pointer(u), ptr)
|
|
}
|
|
|
|
func (u UserData) GetUnsafe() unsafe.Pointer {
|
|
return *(*unsafe.Pointer)(unsafe.Pointer(&u))
|
|
}
|
|
func (u UserData) GetBytes() [8]byte {
|
|
return *(*[8]byte)(u.GetUnsafe())
|
|
}
|
|
func (u UserData) GetUintptr() uintptr {
|
|
return uintptr(u.GetUnsafe())
|
|
}
|
|
func (u UserData) GetUint64() uint64 {
|
|
return uint64(u.GetUintptr())
|
|
}
|
|
func (u UserData) IsZero() bool {
|
|
return u.GetUintptr() == 0
|
|
}
|
|
|
|
// ---
|
|
|
|
func putUnsafe(ptr unsafe.Pointer, v unsafe.Pointer) {
|
|
*(*unsafe.Pointer)(ptr) = v
|
|
}
|
|
|
|
func putUintptr(ptr unsafe.Pointer, v uintptr) {
|
|
*(*uintptr)(ptr) = v
|
|
}
|
|
func putUint64(ptr unsafe.Pointer, v uint64) {
|
|
*(*uint64)(ptr) = v
|
|
}
|
|
func putUint32(ptr unsafe.Pointer, v uint32) {
|
|
*(*uint32)(ptr) = v
|
|
}
|
|
func putUint16(ptr unsafe.Pointer, v uint16) {
|
|
*(*uint16)(ptr) = v
|
|
}
|
|
func putUint8(ptr unsafe.Pointer, v uint8) {
|
|
*(*uint8)(ptr) = v
|
|
}
|
|
|
|
func putInt64(ptr unsafe.Pointer, v int64) {
|
|
*(*int64)(ptr) = v
|
|
}
|
|
func putInt32(ptr unsafe.Pointer, v int32) {
|
|
*(*int32)(ptr) = v
|
|
}
|
|
func putInt16(ptr unsafe.Pointer, v int16) {
|
|
*(*int16)(ptr) = v
|
|
}
|
|
func putInt8(ptr unsafe.Pointer, v int8) {
|
|
*(*int8)(ptr) = v
|
|
}
|