MDL-65072 core_lock: Locks with a zero timeout return asap

This commit is contained in:
Brendan Heywood
2019-03-14 16:55:31 +11:00
parent 3271c39c74
commit ecbe920656
3 changed files with 3 additions and 3 deletions
+1 -1
View File
@@ -146,7 +146,7 @@ class db_record_lock_factory implements lock_factory {
$countparams = array('owner' => $token, 'resourcekey' => $resource);
$result = $this->db->count_records('lock_db', $countparams);
$locked = $result === 1;
if (!$locked) {
if (!$locked && $timeout > 0) {
usleep(rand(10000, 250000)); // Sleep between 10 and 250 milliseconds.
}
// Try until the giveup time.
+1 -1
View File
@@ -152,7 +152,7 @@ class file_lock_factory implements lock_factory {
// Will block on windows. So sad.
$wouldblock = false;
$locked = flock($filehandle, LOCK_EX | LOCK_NB, $wouldblock);
if (!$locked && $wouldblock) {
if (!$locked && $wouldblock && $timeout > 0) {
usleep(rand(10000, 250000)); // Sleep between 10 and 250 milliseconds.
}
// Try until the giveup time.
+1 -1
View File
@@ -188,7 +188,7 @@ class postgres_lock_factory implements lock_factory {
do {
$result = $this->db->get_record_sql('SELECT pg_try_advisory_lock(:locktype, :token) AS locked', $params);
$locked = $result->locked === 't';
if (!$locked) {
if (!$locked && $timeout > 0) {
usleep(rand(10000, 250000)); // Sleep between 10 and 250 milliseconds.
}
// Try until the giveup time.