Added test-ffi target, use it in CI (#9)

* Added test-ffi target, use it in CI

* Added clang-format config, fixed RETURN_STRING API mismatch

* Skip installing php and packages on the PHP docker images

* Removed al2 job that was never going to work, and compiler tests

* Fixed basic test for extension loading

* Cleaned up lib structure, fixed tests

* use test-ci target to conditionally test in GitHub

* Use v0.8.1 of builder
This commit is contained in:
Justin Boswell
2021-02-15 09:47:32 -08:00
committed by GitHub
parent 7b5ccfd55a
commit aee57a929d
18 changed files with 354 additions and 232 deletions
+31
View File
@@ -0,0 +1,31 @@
<?php
/**
* Represents 1 or more event loops (1 per thread) for doing I/O and background tasks.
* Typically, every application has one EventLoopGroup.
*
* @param array options:
* - int num_threads - Number of worker threads in the EventLoopGroup. Defaults to 0/1 per logical core.
*/
final class EventLoopGroup extends NativeResource {
static function defaults() {
return array(
'num_threads' => 0,
);
}
function __construct(array $options = array()) {
parent::__construct();
if (count($options) == 0) {
$options = self::defaults();
}
$this->acquire(self::$crt->event_loop_group_new($options['num_threads']));
}
function __destruct() {
self::$crt->event_loop_group_release($this->native);
$this->release();
parent::__destruct();
}
}
+37
View File
@@ -0,0 +1,37 @@
<?php
/**
* Base class for all native resources, tracks all outstanding resources
* and provides basic leak checking
*/
abstract class NativeResource {
protected static $crt = null;
protected static $resources = [];
protected $native = null;
function __construct() {
if (is_null(self::$crt)) {
try {
self::$crt = new CRT();
} catch (Exception $e) {
echo 'Exception while loading CRT: ', $e->getMessage(), "\n";
}
}
self::$resources[spl_object_hash($this)] = 1;
}
protected function acquire($handle) {
$this->native = $handle;
}
protected function release() {
$this->native = null;
}
function __destruct() {
// Should have been destroyed and released by derived resource
assert($this->native == null);
unset(self::$resources[spl_object_hash($this)]);
}
}