Esempio n. 1
0
File: shm.go Progetto: tcsc/squaddie
// Unmaps the shared memory, closes the region and - if the region owns the
// underlying shm object - signals that the shm object can be unlinked
// when its unmapped by all processes.
func (r *region) Close() error {
	err := syscall.Munmap(r.bytes)
	if err != nil {
		rpcLog.Error("Failed to unmap memory: %s", err.Error())
		return err
	}

	err = r.fd.Close()
	if err != nil {
		rpcLog.Error("Failed to close shared memory handle: %s", err.Error())
		return err
	}

	if r.unlink {
		cname := C.CString(r.name)
		defer C.free(unsafe.Pointer(cname))
		_, err = C.shm_unlink(cname)
		if err != nil {
			rpcLog.Error("Failed to mark shm block for deletion: %s", err.Error())
			return err
		}
	}

	return nil
}
Esempio n. 2
0
func shm_unlink(name string) error {
	cname := C.CString(name)
	defer C.free(unsafe.Pointer(cname))

	_, err := C.shm_unlink(cname)
	return err
}
Esempio n. 3
0
func (o Object) Close() error {
	if err := o.File.Close(); err != nil {
		return err
	}

	cname := C.CString(o.name)
	defer C.free(unsafe.Pointer(cname))

	_, err := C.shm_unlink(cname)
	return err
}