Avoid locking problems in lock class

This commit is contained in:
Michael 2017-06-12 15:42:54 +00:00
parent 1932a6d634
commit 16df7715b9

View file

@ -61,6 +61,8 @@ class Lock {
$cachekey = get_app()->get_hostname().";lock:".$fn_name; $cachekey = get_app()->get_hostname().";lock:".$fn_name;
do { do {
// We only lock to be sure that nothing happens at exactly the same time
dba::lock('locks');
$lock = $memcache->get($cachekey); $lock = $memcache->get($cachekey);
if (!is_bool($lock)) { if (!is_bool($lock)) {
@ -76,6 +78,9 @@ class Lock {
$memcache->set($cachekey, getmypid(), MEMCACHE_COMPRESSED, 300); $memcache->set($cachekey, getmypid(), MEMCACHE_COMPRESSED, 300);
$got_lock = true; $got_lock = true;
} }
dba::unlock();
if (!$got_lock && ($timeout > 0)) { if (!$got_lock && ($timeout > 0)) {
usleep($wait_sec * 1000000); usleep($wait_sec * 1000000);
} }