diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d93f9e..3f061f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,9 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [2.0.2] - 2020-02-02 + +### Changed + +- #10: Improved shared memory cleanup code. + ## [2.0.1] - 2020-02-02 -# Fixed +### Fixed - #10: Properly detach from and cleanup shared memory. @@ -59,7 +65,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added progress callbacks to Deferred. - Added serializable objects for exit and error messages. -[Unreleased]: https://github.com/TheLevti/spork/compare/2.0.1...HEAD +[Unreleased]: https://github.com/TheLevti/spork/compare/2.0.2...HEAD +[2.0.2]: https://github.com/TheLevti/spork/releases/2.0.2 [2.0.1]: https://github.com/TheLevti/spork/releases/2.0.1 [2.0.0]: https://github.com/TheLevti/spork/releases/2.0.0 [1.0.0]: https://github.com/TheLevti/spork/releases/1.0.0 diff --git a/src/Spork/Fork.php b/src/Spork/Fork.php index d132af4..df589a0 100644 --- a/src/Spork/Fork.php +++ b/src/Spork/Fork.php @@ -36,16 +36,6 @@ public function __construct($pid, SharedMemory $shm, $debug = false) $this->name = ''; } - /** - * Clean up shared memory when not needed any longer. - * - * @return void - */ - public function cleanupSharedMemory(): void - { - $this->shm->cleanup(); - } - /** * Assign a name to the current fork (useful for debugging). */ @@ -92,6 +82,8 @@ public function processWaitStatus($status) if ($this->isExited()) { $this->receive(); + $this->shm->cleanup(); + $this->isSuccessful() ? $this->resolve() : $this->reject(); if ($this->debug && (!$this->isSuccessful() || $this->getError())) { diff --git a/src/Spork/ProcessManager.php b/src/Spork/ProcessManager.php index 117237f..176dde6 100644 --- a/src/Spork/ProcessManager.php +++ b/src/Spork/ProcessManager.php @@ -48,15 +48,16 @@ public function __construct( $this->forks = []; } + /** + * Does cleanup when the process manager is destroyed. + * + * @return void + */ public function __destruct() { if (!$this->zombieOkay) { $this->wait(); } - - foreach ($this->forks as $fork) { - $fork->cleanupSharedMemory(); - } } public function getEventDispatcher()