Skip to content

Commit

Permalink
Compatibility improvements for PHP 8.3
Browse files Browse the repository at this point in the history
  • Loading branch information
zhgzhg committed Jan 1, 2024
1 parent 8378d00 commit 2b1930b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
37 changes: 24 additions & 13 deletions GPhpThread.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* The MIT License (MIT)
*
* Copyright (c) 2023 zhgzhg
* Copyright (c) 2024 zhgzhg
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand All @@ -23,8 +23,8 @@
* SOFTWARE.
*
* @author zhgzhg @ github.com
* @version GIT: $Id$ 1.0.4
* @copyright zhgzhg, 2023
* @version 1.0.5
* @copyright zhgzhg, 2024
*/

// define("DEBUG_MODE", true);
Expand Down Expand Up @@ -418,7 +418,7 @@ public function initialize($afterForkPid, $threadId) { // {{{
* Cleans pipe files garbage left from any ungracefully terminated instances.
* @return int The total number of unused, cleaned pipe garbage files.
*/
public function cleanPipeGarbage() {
public function cleanPipeGarbage() { // {{{
$i = 0;
$dirFp = @opendir($this->pipeDir);
if ($dirFp !== false) {
Expand All @@ -436,7 +436,7 @@ public function cleanPipeGarbage() {
closedir($dirFp);
}
return $i;
}
} // }}}

/**
* Finalization of a thread instance that ended and soon will be destroyed.
Expand Down Expand Up @@ -773,18 +773,29 @@ private function isPidAlive($pid) { // {{{


/**
* Sort by occurred lock and dispatch priority. This is workaround
* Sort by occurred lock and dispatch priority. This is a workaround
* method required for PHP 5.3 and relies on an initialized
* $bindVariable. inside this class.
* $bindVariable inside this class.
* @param mixed $a The first key to be taken into account.
* @param mixed $b The second key to be taken into account.
* @return int -1, 0 or 1 depending on which key is more preferable.
*/
private function sortByLockAndDispatchPriority($a, $b) {
if ($this->bindVariable->mastersThreadSpecificData[$a]['intercomInterlocutorPid'] == $this->bindVariable->ownerPid) return -1;
if ($this->bindVariable->mastersThreadSpecificData[$b]['intercomInterlocutorPid'] == $this->bindVariable->ownerPid) return 1;
private function sortByLockAndDispatchPriority($a, $b) { // {{{
$presentIndexA = false;
if (isset($this->bindVariable->mastersThreadSpecificData[$a])) {
if ($this->bindVariable->mastersThreadSpecificData[$a]['intercomInterlocutorPid'] === $this->bindVariable->ownerPid) return -1;
$presentIndexA = true;
}
$presentIndexB = false;
if (isset($this->bindVariable->mastersThreadSpecificData[$b])) {
if ($this->bindVariable->mastersThreadSpecificData[$b]['intercomInterlocutorPid'] === $this->bindVariable->ownerPid) return 1;
$presentIndexB = true;
}
if (!($presentIndexA && $presentIndexB)) {
return ($presentIndexA ? -1 : (int)$presentIndexB);
}
return (int)($this->bindVariable->mastersThreadSpecificData[$a]['dispatchPriority'] < $this->bindVariable->mastersThreadSpecificData[$b]['dispatchPriority']);
}
} // }}}

/**
* Sort by occurred lock, dispatch priority and most threads using
Expand All @@ -795,7 +806,7 @@ private function sortByLockAndDispatchPriority($a, $b) {
* @param mixed $b The second key to be taken into account.
* @return int -1, 0 or 1 depending on which key is more preferable.
*/
private static function sortByLockDispatchPriorityAndMostThreadsInside($a, $b) {
private static function sortByLockDispatchPriorityAndMostThreadsInside($a, $b) { // {{{
// the locker thread is with highest priority
if (self::$bindStaticVariable[$a]->mastersThreadSpecificData['intercomInterlocutorPid'] == self::$bindStaticVariable[$a]->ownerPid) return -1;
if (self::$bindStaticVariable[$b]->mastersThreadSpecificData['intercomInterlocutorPid'] == self::$bindStaticVariable[$b]->ownerPid) return 1;
Expand Down Expand Up @@ -836,7 +847,7 @@ private static function sortByLockDispatchPriorityAndMostThreadsInside($a, $b) {
}

return 0; // a
}
} // }}}

/**
* Dispatcher responsible for the thread intercommunication and communication with their parent process.
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
GPhpThread - Generic PHP Threads library
========================================

![build status badge](https://travis-ci.com/zhgzhg/GPhpThread.svg?branch=master "Build status")
![build status badge](https://github.com/zhgzhg/GPhpThread/actions/workflows/build.yml/badge.svg?branch=master "Build status")

A heavy threads library implementation written using only pure PHP.
A fully functional component that might come in handy when the host
Expand Down Expand Up @@ -84,7 +84,7 @@ Installation

You can use composer to integrate the library in you project:

php composer.phar require zhgzhg/gphpthread:^1.0.4
php composer.phar require zhgzhg/gphpthread:^1.0.5

Alternatively you can also manually download GPhpThread.php file and
place it in your project's directory.

0 comments on commit 2b1930b

Please sign in to comment.