Skip to content

Commit

Permalink
Update to pthreads 5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dktapps committed Jan 23, 2023
1 parent df1356f commit 6b1d6cc
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 14 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ jobs:
- uses: actions/checkout@v2

- name: Setup PHP
uses: pmmp/setup-php-action@7e0f5f0a95e9d45d1d5fab0e1ee7555fa3b04339
uses: pmmp/setup-php-action@6dd74c145250109942b08fc63cd5118edd2fd256
with:
php-version: ${{ matrix.php }}
install-path: ${{ github.workspace}}/php
pm-version-major: "5"

- name: Cache Composer packages
id: composer-cache
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
"type": "library",
"require": {
"php-64bit": "^8.0",
"ext-pthreads": "^4.0"
"ext-pthreads": "^5.0"
},
"require-dev": {
"phpstan/phpstan": "1.8.11",
"phpstan/phpstan": "1.9.14",
"phpstan/extension-installer": "^1.0",
"phpstan/phpstan-strict-rules": "^1.0"
},
Expand Down
7 changes: 5 additions & 2 deletions src/SleeperHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@
* notifications are received from the notifiers.
*/
class SleeperHandler{
/** @var \Threaded */
/**
* @var \ThreadedArray
* @phpstan-var \ThreadedArray<int, int>
*/
private $sharedObject;

/**
Expand All @@ -44,7 +47,7 @@ class SleeperHandler{
private $nextSleeperId = 0;

public function __construct(){
$this->sharedObject = new \Threaded();
$this->sharedObject = new \ThreadedArray();
}

/**
Expand Down
12 changes: 9 additions & 3 deletions src/SleeperNotifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,20 @@
/**
* Notifiers are Threaded objects which can be attached to threaded sleepers in order to wake them up.
*/
class SleeperNotifier extends \Threaded{
/** @var \Threaded */
class SleeperNotifier extends \ThreadedBase{
/**
* @var \ThreadedArray
* @phpstan-var \ThreadedArray<int, int>
*/
private $sharedObject;

/** @var int */
private $sleeperId;

final public function attachSleeper(\Threaded $sharedObject, int $id) : void{
/**
* @phpstan-param \ThreadedArray<int, int> $sharedObject
*/
final public function attachSleeper(\ThreadedArray $sharedObject, int $id) : void{
$this->sharedObject = $sharedObject;
$this->sleeperId = $id;
}
Expand Down
3 changes: 1 addition & 2 deletions tests/phpstan/configs/phpstan-bugs.neon
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ parameters:
path: ../../../src/SleeperNotifier.php

-
message: "#^Strict comparison using \\!\\=\\= between Threaded and null will always evaluate to true\\.$#"
message: "#^Strict comparison using \\!\\=\\= between ThreadedArray\\<int, int\\> and null will always evaluate to true\\.$#"
count: 1
path: ../../../src/SleeperNotifier.php

26 changes: 22 additions & 4 deletions tests/phpstan/stubs/pthreads.stub
Original file line number Diff line number Diff line change
@@ -1,15 +1,33 @@
<?php

/**
* @implements \Traversable<array-key, mixed>
* @implements \IteratorAggregate<array-key, mixed>
*/
class Threaded implements \Traversable{
abstract class ThreadedBase implements \IteratorAggregate{

/**
* @template TReturn
* @param callable() : TReturn $function
* @param \Closure() : TReturn $function
* @param mixed ...$args
* @return TReturn
*/
public function synchronized(callable $function, ...$args){}
public function synchronized(\Closure $function, mixed ...$args) : mixed{}
}

/**
* @template TKey of array-key
* @template TValue
* @implements ArrayAccess<TKey, TValue>
*/
final class ThreadedArray extends ThreadedBase implements Countable, ArrayAccess{

/**
* @return TValue|null
*/
public function pop() : mixed{}

/**
* @return TValue|null
*/
public function shift() : mixed{}
}

0 comments on commit 6b1d6cc

Please sign in to comment.