public function schedule()
{
if ($this->msg_count > 0 && !empty($this->processes)) {
$pid = array_shift($this->pids);
$p_meta = $this->processes[$pid];
if (!empty($p_meta['inbox'])) {
$msg = array_shift($p_meta['inbox']);
$restack = true;
foreach ($p_meta['receive'] as $receive) {
if ($receive == $msg->getTag()) {
$m = 'handle_' . $receive;
$args = array($msg->getData(), $p_meta['state']);
$state = call_user_func_array(array($p_meta['p'], $m), $args);
$p_meta['state'] = $state;
$restack = false;
break;
}
}
if ($restack) {
array_push($p_meta['inbox'], $msg);
} else {
$this->msg_count--;
}
$this->processes[$pid] = $p_meta;
}
array_push($this->pids, $pid);
}
}