MadelineProto/src/Thread.php

66 lines
1.3 KiB
PHP
Raw Normal View History

2017-05-16 22:19:42 +02:00
<?php
2017-05-16 22:19:54 +02:00
if (!extension_loaded('pthreads')) {
class Thread extends Threaded
{
public function isStarted()
{
return (bool) ($this->state & self::STARTED);
}
public function isJoined()
{
return (bool) ($this->state & self::JOINED);
}
public function kill()
{
$this->state |= self::ERROR;
return true;
}
public static function getCurrentThreadId()
{
return 1;
}
public function getThreadId()
{
return 1;
}
public function start()
{
2017-05-28 01:50:22 +02:00
if (!isset($this->state)) $this->state = 0;
2017-05-16 22:19:54 +02:00
if ($this->state & self::STARTED) {
throw new \RuntimeException();
}
$this->state |= self::STARTED;
$this->state |= self::RUNNING;
try {
$this->run();
} catch (Exception $t) {
$this->state |= self::ERROR;
}
$this->state &= ~self::RUNNING;
return true;
}
public function join()
{
if ($this->state & self::JOINED) {
throw new \RuntimeException();
}
$this->state |= self::JOINED;
return true;
}
}
2017-05-16 22:19:42 +02:00
}