Exemple #1
0
func (c *CGoSystem) WaitMany(handles []uint32, signals []uint32, deadline uint64) (uint32, int, []uint32, []uint32) {
	if len(handles) == 0 {
		r := C.MojoWaitMany(nil, nil, 0, C.MojoDeadline(deadline), nil, nil)
		return uint32(r), -1, nil, nil
	}
	if len(handles) != len(signals) {
		panic("number of handles and signals must match")
	}
	index := ^C.uint32_t(0) // -1
	cHandles := (*C.MojoHandle)(unsafe.Pointer(&handles[0]))
	cSignals := (*C.MojoHandleSignals)(unsafe.Pointer(&signals[0]))
	cStates := make([]C.struct_MojoHandleSignalsState, len(handles))
	r := C.MojoWaitMany(cHandles, cSignals, C.uint32_t(len(handles)), C.MojoDeadline(deadline), &index, &cStates[0])
	var satisfied, satisfiable []uint32
	if r != C.MOJO_RESULT_INVALID_ARGUMENT && r != C.MOJO_RESULT_RESOURCE_EXHAUSTED {
		satisfied = make([]uint32, len(handles))
		satisfiable = make([]uint32, len(handles))
		for i := 0; i < len(handles); i++ {
			satisfied[i] = uint32(cStates[i].satisfied_signals)
			satisfiable[i] = uint32(cStates[i].satisfiable_signals)
		}
	}
	return uint32(r), int(int32(index)), satisfied, satisfiable
}
Exemple #2
0
func (c *CGoSystem) Wait(handle uint32, signals uint32, deadline uint64) (result uint32, satisfiedSignals, satisfiableSignals uint32) {
	var cState C.struct_MojoHandleSignalsState
	r := C.MojoWait(C.MojoHandle(handle), C.MojoHandleSignals(signals), C.MojoDeadline(deadline), &cState)
	return uint32(r), uint32(cState.satisfied_signals), uint32(cState.satisfiable_signals)
}