Skip to content

Commit

Permalink
update PThread.php
Browse files Browse the repository at this point in the history
  • Loading branch information
TheTechsTech committed Mar 12, 2023
1 parent 6cf5fd2 commit 6cdd3af
Showing 1 changed file with 55 additions and 3 deletions.
58 changes: 55 additions & 3 deletions zend/Types/PThread.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,65 @@

namespace ZE;

use Closure;
use ZE\Thread;
use FFI\CData;
use ZE\Zval;

if (\PHP_ZTS && !\class_exists('PThread')) {
final class PThread
{
/**
*pthread_attr_{get,set}detachstate
*/
const CREATE_JOINABLE = 0; /* Default */
const CREATE_DETACHED = 1;

/**
* pthread_attr_{get,set}inheritsched
*/
const INHERIT_SCHED = 0;
const EXPLICIT_SCHED = 1; /* Default */

/**
* pthread_{get,set}scope
*/
const SCOPE_PROCESS = 0;
const SCOPE_SYSTEM = 1; /* Default */

/**
* pthread_setcancelstate paramters
*/
const CANCEL_ENABLE = 0; /* Default */
const CANCEL_DISABLE = 1;

/**
* pthread_setcanceltype parameters
*/
const CANCEL_ASYNCHRONOUS = 0;
const CANCEL_DEFERRED = 1; /* Default */

/**
* pthread_mutexattr_{get,set}pshared
* pthread_condattr_{get,set}pshared
*/
const PROCESS_PRIVATE = 0;
const PROCESS_SHARED = 1;

/**
* pthread_mutexattr_{get,set}robust
*/
const MUTEX_STALLED = 0; /* Default */
const MUTEX_ROBUST = 1;

/**
* pthread_barrier_wait
*/
const BARRIER_SERIAL_THREAD = -1;

/** @var \php_thread */
private ?\CStruct $php_thread = null;

private ?Closure $func = null;
private ?\Closure $func = null;
private ?\ThreadsModule $module = null;
private array $fcall_info = [];

Expand Down Expand Up @@ -52,6 +99,11 @@ public function get_ptr(): CData
return $this->php_thread->addr('thread');
}

public function get_addr(): CData
{
return $this->php_thread->__invoke()->thread;
}

public function get_args(): CData
{
return $this->php_thread->__invoke()->arg;
Expand Down Expand Up @@ -175,7 +227,7 @@ public function create_ex($params)

public function join()
{
return \ts_ffi()->pthread_join($this->get_ptr()[0], NULL);
return \ts_ffi()->pthread_join($this->get_addr(), NULL);
}
}
}

0 comments on commit 6cdd3af

Please sign in to comment.