MadelineProto/src/Thread.php
Daniil Gentili ab1bd5330d Add polyfill
2017-05-16 21:19:42 +01:00

43 lines
945 B
PHP

<?php
if (!extension_loaded("pthreads")) {
class Thread extends Threaded {
public function isStarted() { return (bool) ($this->state & THREAD::STARTED); }
public function isJoined() { return (bool) ($this->state & THREAD::JOINED); }
public function kill() {
$this->state |= THREAD::ERROR;
return true;
}
public static function getCurrentThreadId() { return 1; }
public function getThreadId() { return 1; }
public function start() {
if ($this->state & THREAD::STARTED) {
throw new \RuntimeException();
}
$this->state |= THREAD::STARTED;
$this->state |= THREAD::RUNNING;
try {
$this->run();
} catch(Exception $t) {
$this->state |= THREAD::ERROR;
}
$this->state &= ~THREAD::RUNNING;
return true;
}
public function join() {
if ($this->state & THREAD::JOINED) {
throw new \RuntimeException();
}
$this->state |= THREAD::JOINED;
return true;
}
}
}