<?php
namespace App\Cron\Mutex;

/**
 * Base interface for Mutex and Lock/Unlock pattern
 *
 * Methods for locking (not implemented now):
 * 	@see http://php.net/manual/en/function.getmypid.php#109333
 * 	@see http://php.net/manual/en/function.getmypid.php#107022
 * 	@see http://stackoverflow.com/questions/9874331/check-if-specified-pid-is-currently-running-using-php-possible-without-using-p
 * 	daca foloseste intens DB, ar putea sa noteze in status id-ul conexiunii la DB, si master-ul sa verifice daca conexiunea aia este inca deschisa
 *
 * @author Lucian Sirbu
 *
 */
interface AbstractLock
{
	/**
	 * Block the call until the lock is acuired
	 */
	public function lock();

	/**
	 * Unlock a locked lock
	 */
	public function unlock();

	/**
	 * Check if a lock is in effect
	 */
	public function isLocked();

	/**
	 * Get some kind of feedback on why the file is locked/unlocked
	 */
	public function rawGetIsLockedReasons();

	/**
	 * Check if the lock was actually aquired
	 */
	public function wasAquired();

	/**
	 * Aquire a lock, wait for maximum $timeout
	 */
	public function lockWithTimeout($timeout);
}
