Fixed race condition in API schedule()

This commit is contained in:
Shoghi Cervantes Pueyo 2013-01-14 16:42:57 +01:00
parent 29cd858622
commit f47fa6d5dc

View File

@ -537,12 +537,13 @@ class PocketMinecraftServer{
return false; return false;
} }
$add = ""; $add = "";
$chcnt = $this->scheduleCnt++;
if($repeat === false){ if($repeat === false){
$add = ' unset($this->schedule['.$this->scheduleCnt.']);'; $add = ' unset($this->schedule['.$chcnt.']);';
} }
$this->schedule[$this->scheduleCnt] = array($callback, $data, $eventName); $this->schedule[$chcnt] = array($callback, $data, $eventName);
$this->action(50000 * $ticks, '$schedule = $this->schedule['.$this->scheduleCnt.'];'.$add.'if(!is_callable($schedule[0])){unset($this->schedule['.$this->scheduleCnt.']);return false;} call_user_func($schedule[0], $schedule[1], $schedule[2]);', (bool) $repeat); $this->action(50000 * $ticks, '$schedule = $this->schedule['.$chcnt.'];'.$add.'if(!is_callable($schedule[0])){unset($this->schedule['.$chcnt.']);return false;} call_user_func($schedule[0], $schedule[1], $schedule[2]);', (bool) $repeat);
return $this->scheduleCnt++; return $chcnt;
} }
public function action($microseconds, $code, $repeat = true){ public function action($microseconds, $code, $repeat = true){