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 @@ ...@@ -41,19 +41,13 @@
* Consult LICENSE file for details * Consult LICENSE file for details
************************************************/ ************************************************/
class SimpleMutex extends InterProcessData { class SimpleMutex {
/**
* Constructor private $file;
*/ private $fp;
public function SimpleMutex() {
// initialize super parameters
$this->allocate = 64;
$this->type = 5173;
parent::__construct();
if (!$this->IsActive()) { public function __construct($file = __FILE__) {
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."); $this->file = $file;
}
} }
/** /**
...@@ -65,11 +59,8 @@ class SimpleMutex extends InterProcessData { ...@@ -65,11 +59,8 @@ class SimpleMutex extends InterProcessData {
* @return boolean * @return boolean
*/ */
public function Block() { public function Block() {
if ($this->IsActive()) $this->fp = fopen($this->file, 'r');
return $this->blockMutex(); return flock($this->fp, LOCK_EX);
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;
} }
/** /**
...@@ -80,9 +71,6 @@ class SimpleMutex extends InterProcessData { ...@@ -80,9 +71,6 @@ class SimpleMutex extends InterProcessData {
* @return boolean * @return boolean
*/ */
public function Release() { public function Release() {
if ($this->IsActive()) return flock($this->fp, LOCK_UN) && fclose($this->fp) && $this->fp = null;
return $this->releaseMutex();
return true;
} }
} }
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