Commit 00b5c301 authored by Etienne CHAMPETIER's avatar Etienne CHAMPETIER

ZP-792 implements SimpleMutex with flock instead of sem_* (InterProcessData).

Released under the Affero GNU General Public License (AGPL) version 3.

flock is portable and it's there since php4
we can now have "smaller" lock
parent c42848ed
......@@ -41,19 +41,13 @@
* Consult LICENSE file for details
************************************************/
class SimpleMutex extends InterProcessData {
/**
* Constructor
*/
public function SimpleMutex() {
// initialize super parameters
$this->allocate = 64;
$this->type = 5173;
parent::__construct();
class SimpleMutex {
private $file;
private $fp;
if (!$this->IsActive()) {
ZLog::Write(LOGLEVEL_ERROR, "SimpleMutex not available as InterProcessData is not available. This is not recommended on duty systems and may result in corrupt user/device linking.");
}
public function __construct($file = __FILE__) {
$this->file = $file;
}
/**
......@@ -65,11 +59,8 @@ class SimpleMutex extends InterProcessData {
* @return boolean
*/
public function Block() {
if ($this->IsActive())
return $this->blockMutex();
ZLog::Write(LOGLEVEL_WARN, "Could not enter mutex as InterProcessData is not available. This is not recommended on duty systems and may result in corrupt user/device linking!");
return true;
$this->fp = fopen($this->file, 'r');
return flock($this->fp, LOCK_EX);
}
/**
......@@ -80,9 +71,6 @@ class SimpleMutex extends InterProcessData {
* @return boolean
*/
public function Release() {
if ($this->IsActive())
return $this->releaseMutex();
return true;
return flock($this->fp, LOCK_UN) && fclose($this->fp) && $this->fp = null;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment