59
59
fclose($this->rlock);
62
static function timed_flock($handle, $flags = 0, $timeout = LOCK::FLOCK_TIMEOUT) {
62
static function timed_flock($handle, $flags = 0, $timeout = LOCK::FLOCK_TIMEOUT, &$would_block = NULL) {
63
63
if (0) { // we have pcntl
64
64
/* pcntl_signal(SIGALRM, function() {});
65
65
pcntl_alarm($timeout);
88
if ($would_block !== NULL) {
91
function Lock($flag = 0, $errmsg = false) {
95
function TimedLock($flag = 0, $timeout = LOCK::FLOCK_TIMEOUT, $errmsg = false) {
92
96
if ($flag&LOCK::BLOCK) {
94
99
if ($flag&LOCK::ALL)
95
$res = LOCK::timed_flock($this->rlock, LOCK_EX);
100
$res = LOCK::timed_flock($this->rlock, LOCK_EX, $timeout, $wb);
97
$res = LOCK::timed_flock($this->rlock, LOCK_SH);
102
$res = LOCK::timed_flock($this->rlock, LOCK_SH, $timeout, $wb);
100
105
if ($errmsg) throw new ADEIException($errmsg);
106
else if ($wb) throw new ADEIException(translate("Timeout locking file: %s", $this->rlock_file));
101
107
else throw new ADEIException(translate("Locking is failed (file: %s)", $this->rlock_file));
104
$res = LOCK::timed_flock($this->lockf, LOCK_EX);
110
$res = LOCK::timed_flock($this->lockf, LOCK_EX, $timeout, $wb);
106
112
flock($this->rlock, LOCK_UN);
108
114
if ($errmsg) throw new ADEIException($errmsg);
115
else if ($wb) ADEIException(translate("Timeout locking file: %s", $this->lock_file));
109
116
else throw new ADEIException(translate("Locking is failed (file: %s)", $this->lock_file));
136
function Lock($flag = 0, $errmsg = false) {
137
return $this->TimedLock($flag, LOCK::FLOCK_TIMEOUT, $errmsg);
129
140
function UnLock() {
130
141
flock($this->lockf, LOCK_UN);