12
14
$dir = $TMP_PATH . "/locks";
14
16
if (!is_dir($dir)) {
15
if (!@mkdir($dir, 0755, true))
17
if (!@mkdir($dir, 0777 /*0755*/, true))
16
18
throw new ADEIException(translate("It is not possible to create lock directory \"$dir\""));
20
22
else $fname = $dir . "/ADEI__${name}.lock";
22
24
$this->lockf = @fopen($fname, "a+");
24
throw new ADEIException(translate("It is not possible to create lock file \"$fname\""));
26
throw new ADEIException(translate("It is not possible to create lock file \"$fname\""));
29
$fname = $dir . "/${name}.lock";
30
$this->rlock = @fopen($fname, "a+");
33
throw new ADEIException(translate("It is not possible to create lock file \"$fname\""));
27
37
function __destruct() {
28
38
fclose($this->lockf);
31
42
function Lock($flag = 0, $errmsg = false) {
32
43
if ($flag&LOCK::BLOCK) {
46
$res = flock($this->rlock, LOCK_EX);
48
$res = flock($this->rlock, LOCK_SH);
51
if ($errmsg) throw new ADEIException($errmsg);
52
else throw new ADEIException(translate("Locking is failed"));
33
55
$res = flock($this->lockf, LOCK_EX);
57
flock($this->rlock, LOCK_UN);
35
59
if ($errmsg) throw new ADEIException($errmsg);
36
60
else throw new ADEIException(translate("Locking is failed"));
64
$res = flock($this->rlock, LOCK_EX|LOCK_NB);
66
$res = flock($this->rlock, LOCK_SH|LOCK_NB);
68
if ((!$res)&&($errmsg)) throw new ADEIException($errmsg);
39
70
$res = flock($this->lockf, LOCK_EX|LOCK_NB);
40
if ((!$res)&&($errmsg)) throw new ADEIException($errmsg);
72
flock($this->rlock, LOCK_UN);
73
if ($errmsg) throw new ADEIException($errmsg);