lock_may_be_available

  1. drupal
    1. drupal6
Versionen
drupal6 lock_may_be_available($name)

Check if lock acquired by a different process may be available.

If an existing lock has expired, it is removed.

Übergabeparameter

$name The name of the lock.

Rückgabewert

TRUE if there is no lock or it was removed, FALSE otherwise.

Verwandte Themen

▾ 2 functions call lock_may_be_available()

lock_acquire in includes/lock.inc
Acquire (or renew) a lock, but do not block if it fails.
lock_wait in includes/lock.inc
Wait for a lock to be available.

Code

includes/lock.inc, line 148

<?php
function lock_may_be_available($name) {
  $lock = db_fetch_array(db_query("SELECT expire, value FROM {semaphore} WHERE name = '%s'", $name));
  if (!$lock) {
    return TRUE;
  }
  $expire = (float) $lock['expire'];
  list($usec, $sec) = explode(' ', microtime());
  $now = (float) $usec + (float) $sec;
  if ($now > $lock['expire']) {
    // We check two conditions to prevent a race condition where another
    // request acquired the lock and set a new expire time.  We add a small
    // number to $expire to avoid errors with float to string conversion.
    db_query("DELETE FROM {semaphore} WHERE name = '%s' AND value = '%s' AND expire <= %f", $name, $lock['value'], 0.0001 + $expire);
    return (bool) db_affected_rows();
  }
  return FALSE;
}
?>

Kommentare

Kommentar hinzufügen

Der Inhalt dieses Feldes wird nicht öffentlich zugänglich angezeigt.
  • Internet- und E-Mail-Adressen werden automatisch umgewandelt.
  • Zulässige HTML-Tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Zeilen und Absätze werden automatisch erzeugt.

Weitere Informationen über Formatierungsoptionen

Kommentar hinzufügen

Der Inhalt dieses Feldes wird nicht öffentlich zugänglich angezeigt.
  • Internet- und E-Mail-Adressen werden automatisch umgewandelt.
  • Zulässige HTML-Tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Zeilen und Absätze werden automatisch erzeugt.

Weitere Informationen über Formatierungsoptionen