From 25fbe7a9a8e3f72259705b691a31071e0adc9734 Mon Sep 17 00:00:00 2001 From: coderstephen Date: Sun, 30 Aug 2015 17:52:00 -0500 Subject: [PATCH] Documentation & unused argument fixes --- src/Sync/FileMutex.php | 6 +++++- src/Sync/Lock.php | 2 +- src/Sync/PosixSemaphore.php | 8 ++++---- src/Sync/Semaphore.php | 8 ++++---- src/Threading/Internal/Semaphore.php | 4 ++-- src/Threading/Mutex.php | 4 +--- src/Threading/Semaphore.php | 10 ++++++---- src/Threading/Thread.php | 24 +++++++++++++++--------- 8 files changed, 38 insertions(+), 28 deletions(-) diff --git a/src/Sync/FileMutex.php b/src/Sync/FileMutex.php index 903a7f7..095ec15 100644 --- a/src/Sync/FileMutex.php +++ b/src/Sync/FileMutex.php @@ -61,7 +61,9 @@ class FileMutex implements MutexInterface } /** - * {@inheritdoc} + * Releases the lock on the mutex. + * + * @throws MutexException If the unlock operation failed. */ protected function release() { @@ -78,6 +80,8 @@ class FileMutex implements MutexInterface * Opens the mutex file and returns a file resource. * * @return resource + * + * @throws MutexException If the mutex file could not be opened. */ private function getFileHandle() { diff --git a/src/Sync/Lock.php b/src/Sync/Lock.php index a76be04..3aa26f0 100644 --- a/src/Sync/Lock.php +++ b/src/Sync/Lock.php @@ -45,7 +45,7 @@ class Lock /** * Releases the lock. * - * @throws LockAlreadyReleasedError Thrown if the lock was already released. + * @throws LockAlreadyReleasedError If the lock was already released. */ public function release() { diff --git a/src/Sync/PosixSemaphore.php b/src/Sync/PosixSemaphore.php index 1460924..3805be9 100644 --- a/src/Sync/PosixSemaphore.php +++ b/src/Sync/PosixSemaphore.php @@ -32,12 +32,12 @@ class PosixSemaphore implements SemaphoreInterface, \Serializable private $data; /** - * Creates a new semaphore. + * Creates a new semaphore with a given number of locks. * - * @param int $maxLocks The maximum number of processes that can lock the - * semaphore. + * @param int $maxLocks The maximum number of locks that can be acquired from the semaphore. + * @param int $permissions Permissions to access the semaphore. */ - public function __construct($maxLocks) + public function __construct($maxLocks, $permissions = 0600) { $this->key = abs(crc32(spl_object_hash($this))); diff --git a/src/Sync/Semaphore.php b/src/Sync/Semaphore.php index f5f972c..1f60afe 100644 --- a/src/Sync/Semaphore.php +++ b/src/Sync/Semaphore.php @@ -24,12 +24,12 @@ class Semaphore implements SemaphoreInterface, \Serializable private $handle; /** - * Creates a new semaphore. + * Creates a new semaphore with a given number of locks. * - * @param int $maxLocks The maximum number of processes that can lock the semaphore. + * @param int $maxLocks The maximum number of locks that can be acquired from the semaphore. * @param int $permissions Permissions to access the semaphore. */ - public function __construct($maxLocks = 1, $permissions = 0666) + public function __construct($maxLocks = 1, $permissions = 0600) { $this->key = abs(crc32(spl_object_hash($this))); $this->maxLocks = $maxLocks; @@ -106,6 +106,6 @@ class Semaphore implements SemaphoreInterface, \Serializable // Get the semaphore key and attempt to re-connect to the semaphore in // memory. list($this->key, $this->maxLocks) = unserialize($serialized); - $this->handle = sem_get($this->key, $maxLocks, 0666, 1); + $this->handle = sem_get($this->key, $maxLocks, 0600, 1); } } diff --git a/src/Threading/Internal/Semaphore.php b/src/Threading/Internal/Semaphore.php index 7000199..84f69a1 100644 --- a/src/Threading/Internal/Semaphore.php +++ b/src/Threading/Internal/Semaphore.php @@ -29,9 +29,9 @@ class Semaphore extends \Threaded private $waitQueue = []; /** - * Creates a new semaphore. + * Creates a new semaphore with a given number of locks. * - * @param int $maxLocks The maximum number of processes that can lock the semaphore. + * @param int $maxLocks The maximum number of locks that can be acquired from the semaphore. */ public function __construct($maxLocks) { diff --git a/src/Threading/Mutex.php b/src/Threading/Mutex.php index 8a27696..115dc28 100644 --- a/src/Threading/Mutex.php +++ b/src/Threading/Mutex.php @@ -17,10 +17,8 @@ class Mutex implements MutexInterface /** * Creates a new threaded mutex. - * - * @param bool $locked Whether the mutex should start out locked. */ - public function __construct($locked = false) + public function __construct() { $this->mutex = new Internal\Mutex(); } diff --git a/src/Threading/Semaphore.php b/src/Threading/Semaphore.php index 04f679a..2fbda78 100644 --- a/src/Threading/Semaphore.php +++ b/src/Threading/Semaphore.php @@ -14,16 +14,18 @@ use Icicle\Concurrent\Sync\SemaphoreInterface; class Semaphore implements SemaphoreInterface { /** - * @var \Icicle\Concurrent\Threading\Internal\Semaphore + * @var Internal\Semaphore */ private $semaphore; /** - * @param int $maxLocks + * Creates a new semaphore with a given number of locks. + * + * @param int $maxLocks The maximum number of locks that can be acquired from the semaphore. */ public function __construct($maxLocks) { - $this->semaphore = new Internal\Semaphore($maxLocks); + $this->semaphore = new Internal\Semaphore($locks); } /** @@ -43,4 +45,4 @@ class Semaphore implements SemaphoreInterface { return $this->semaphore->acquire(); } -} \ No newline at end of file +} diff --git a/src/Threading/Thread.php b/src/Threading/Thread.php index ab947d0..b535f84 100644 --- a/src/Threading/Thread.php +++ b/src/Threading/Thread.php @@ -24,12 +24,12 @@ class Thread implements ContextInterface, SynchronizableInterface const LATENCY_TIMEOUT = 0.01; // 10 ms /** - * @var \Icicle\Concurrent\Threading\Internal\Thread An internal thread instance. + * @var Internal\Thread An internal thread instance. */ private $thread; /** - * @var \Icicle\Concurrent\Sync\Channel A channel for communicating with the thread. + * @var Channel A channel for communicating with the thread. */ private $channel; @@ -46,9 +46,9 @@ class Thread implements ContextInterface, SynchronizableInterface /** * Spawns a new thread and runs it. * - * @param callable $function A callable to invoke in the thread. + * @param callable $function The callable to invoke in the thread. * - * @return \Icicle\Concurrent\Threading\Thread The thread object that was spawned. + * @return Thread The thread object that was spawned. */ public static function spawn(callable $function /* , ...$args */) { @@ -59,9 +59,11 @@ class Thread implements ContextInterface, SynchronizableInterface } /** - * Creates a new thread context from a thread. + * Creates a new thread. * - * @param callable $function + * @param callable $function The callable to invoke in the thread when run. + * + * @throws InvalidArgumentError If the given function cannot be safely invoked in a thread. */ public function __construct(callable $function /* , ...$args */) { @@ -92,7 +94,9 @@ class Thread implements ContextInterface, SynchronizableInterface } /** - * Starts the context execution. + * Spawns the thread and begins the thread's execution. + * + * @throws StatusError If the thread has already been started. */ public function start() { @@ -107,6 +111,8 @@ class Thread implements ContextInterface, SynchronizableInterface /** * Immediately kills the context. + * + * @throws ThreadException If killing the thread was unsuccessful. */ public function kill() { @@ -128,8 +134,8 @@ class Thread implements ContextInterface, SynchronizableInterface * * @resolve mixed Resolved with the return or resolution value of the context once it has completed execution. * - * @throws \Icicle\Concurrent\Exception\StatusError Thrown if the context has not been started. - * @throws \Icicle\Concurrent\Exception\SynchronizationError Thrown if an exit status object is not received. + * @throws StatusError Thrown if the context has not been started. + * @throws SynchronizationError Thrown if an exit status object is not received. */ public function join() {