namespace Friendica\Core\Lock;
+use Friendica\Core\Cache;
+
class SemaphoreLockDriver extends AbstractLockDriver
{
private static $semaphore = [];
}
/**
- * @brief Creates a semaphore key
- *
- * @param string $key Name of the lock
- *
- * @return integer the semaphore key
+ * (@inheritdoc)
*/
private static function semaphoreKey($key)
{
$temp = get_temppath();
- $file = $temp.'/'.$key.'.sem';
+ $file = $temp . '/' . $key . '.sem';
if (!file_exists($file)) {
file_put_contents($file, $key);
}
/**
- *
- * @brief Sets a lock for a given name
- *
- * @param string $key The Name of the lock
- * @param integer $timeout Seconds until we give up
- *
- * @return boolean Was the lock successful?
+ * (@inheritdoc)
*/
- public function acquireLock($key, $timeout = 120)
+ public function acquireLock($key, $timeout = 120, $ttl = Cache::FIVE_MINUTES)
{
self::$semaphore[$key] = sem_get(self::semaphoreKey($key));
if (self::$semaphore[$key]) {
}
/**
- * @brief Removes a lock if it was set by us
- *
- * @param string $key Name of the lock
- *
- * @return mixed
+ * (@inheritdoc)
*/
- public function releaseLock($key)
+ public function releaseLock($key, $override = false)
{
if (empty(self::$semaphore[$key])) {
return false;
}
/**
- * @brief Checks, if a key is currently locked to a process
- *
- * @param string $key The name of the lock
- * @return bool
+ * (@inheritdoc)
*/
public function isLocked($key)
{
- return @sem_get(self::$semaphore[$key]) !== false;
+ return isset(self::$semaphore[$key]);
}
}