1
0
mirror of https://github.com/danog/amp.git synced 2024-11-30 04:29:08 +01:00

Fixed bug causing NativeReactor to run at 100% CPU

See also https://github.com/amphp/aerys/issues/68
This commit is contained in:
Bob Weinand 2016-02-22 23:17:50 +01:00
parent 5341a4cb92
commit 4b667478f4
3 changed files with 12 additions and 5 deletions

View File

@ -1,3 +1,8 @@
### 1.0.8
- Fix NativeReactor running a busy loop if no timers are active.
Properly block now in NativeReactor inside stream_select().
### 1.0.7
- Several combinator functions could result in a Promise already

View File

@ -195,14 +195,13 @@ class NativeReactor implements Reactor {
// @TODO Instead of iterating all timers hunting for a keep-alive
// we should just use a specific counter to cache the number
// of keep-alive timers in use at any given time
$timeToNextAlarm = 0;
$timeToNextAlarm = null;
foreach ($this->timerOrder as $watcherId => $time) {
if ($this->watchers[$watcherId]->keepAlive) {
// The reset() is important because the foreach modifies
// the internal array pointer.
// the internal array pointer with PHP 5.
$nextTimerAt = \reset($this->timerOrder);
$timeToNextAlarm = \round($nextTimerAt - \microtime(true), 4);
$timeToNextAlarm = ($timeToNextAlarm > 0) ? $timeToNextAlarm : 0;
break;
}
}
@ -228,7 +227,10 @@ class NativeReactor implements Reactor {
$w = $this->writeStreams;
$e = null;
if ($timeout <= 0) {
if ($timeout === null) {
$sec = null;
$usec = null;
} elseif ($timeout <= 0) {
$sec = 0;
$usec = 0;
} else {

View File

@ -6,7 +6,7 @@ use Amp\UvReactor;
class UvReactorTest extends ReactorTest {
public static function setUpBeforeClass() {
if (!defined('SIGUSR1')) {
if (!defined('SIGUSR1') && extension_loaded("uv")) {
define('SIGUSR1', \Uv::SIGUSR1);
}
}