mem-ring 0.2.0

Across-thread queue based on shared memory
Documentation
package mem_ring

import (
	"net"
	"os"
	"syscall"
	"unsafe"

	"golang.org/x/sys/unix"
)

type Notifier struct {
	fd int32
}

func NewNotifier(fd int32) Notifier {
	return Notifier{fd: fd}
}

func (n Notifier) Notify() {
	val := uint8(0)
	for {
		_, e := syscall.Write(int(n.fd), (*(*[1]byte)(unsafe.Pointer(&val)))[:])
		if e == unix.EINTR {
			continue
		}
		return
	}
}

type Awaiter struct {
	fd int32
}

func NewAwaiter(fd int32) Awaiter {
	return Awaiter{fd: fd}
}

func (n Awaiter) Wait() {
	f := os.NewFile(uintptr(n.fd), "fd")
	c, e := net.FileConn(f)
	if e != nil {
		panic(e)
	}
	var buf [64]byte
	c.Read(buf[:])
}