1
0
mirror of https://github.com/danog/parallel.git synced 2024-12-04 10:38:30 +01:00
parallel/lib/Threading/Mutex.php
2016-08-26 10:10:03 -05:00

45 lines
901 B
PHP

<?php declare(strict_types = 1);
namespace Amp\Parallel\Threading;
use Amp\Parallel\Sync\Mutex as SyncMutex;
use Interop\Async\Awaitable;
/**
* A thread-safe, asynchronous mutex using the pthreads locking mechanism.
*
* Compatible with POSIX systems and Microsoft Windows.
*/
class Mutex implements SyncMutex {
/** @var \Amp\Parallel\Threading\Internal\Mutex */
private $mutex;
/**
* Creates a new threaded mutex.
*/
public function __construct() {
$this->init();
}
/**
* Initializes the mutex.
*/
private function init() {
$this->mutex = new Internal\Mutex;
}
/**
* {@inheritdoc}
*/
public function acquire(): Awaitable {
return $this->mutex->acquire();
}
/**
* Makes a copy of the mutex in the unlocked state.
*/
public function __clone() {
$this->init();
}
}