Esempio n. 1
0
// nextTask returns taskInfo.sp for next task or 0.
// TODO: better scheduler
func nextTask(sp uintptr) uintptr {
	n := tasker.forceNext
	if n >= 0 {
		tasker.forceNext = -1
	} else {
	again:
		if ereg := atomic.SwapUintptr((*uintptr)(&eventReg), 0); ereg != 0 {
			tasker.deliverEvent(Event(ereg))
		}
		n = tasker.curTask
		for {
			if n++; n == len(tasker.tasks) {
				n = 0
			}
			if tasker.tasks[n].state() == taskReady {
				break
			}
			if n == tasker.curTask {
				// No task to run.
				sleep.WFE()
				goto again
			}
		}
		if n == tasker.curTask {
			return 0
		}
	}
	tasker.tasks[tasker.curTask].sp = sp
	tasker.curTask = n
	return tasker.tasks[n].sp
}
Esempio n. 2
0
func SwapUintptr(addr *uintptr, new uintptr) uintptr {
	return orig.SwapUintptr(addr, new)
}