Index: includes/bootstrap.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/bootstrap.inc,v retrieving revision 1.206.2.11 diff -u -p -r1.206.2.11 bootstrap.inc --- includes/bootstrap.inc 25 Feb 2009 13:49:54 -0000 1.206.2.11 +++ includes/bootstrap.inc 18 Apr 2009 13:42:12 -0000 @@ -1052,6 +1052,8 @@ function _drupal_bootstrap($phase) { exit; } // Prepare for non-cached page workflow. + require_once variable_get('lock_inc', './includes/lock.inc'); + lock_init(); drupal_page_header(); break; Index: includes/lock.inc =================================================================== RCS file: includes/lock.inc diff -N includes/lock.inc --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ includes/lock.inc 18 Apr 2009 13:42:12 -0000 @@ -0,0 +1,174 @@ + $expire) { + lock_break($name, $now); + return FALSE; + } + sleep(1); + } + return TRUE; +} + +/** + * Break a lock acquired by a different process. + * + * @param $name + * The name of the lock. + * @param $now + * A unix timestamp with microseconds (float). + */ +function lock_break($name, $now) { + db_query("DELETE FROM {semaphore} WHERE name = '%s' AND expire < %f", $name, $now); +} + +/** + * Release a lock previously acquired by lock_acquire(). + * + * @param $name + * The name of the lock. + */ +function lock_release($name) { + global $locks; + + unset($locks[$name]); + db_query("DELETE FROM {semaphore} WHERE name = '%s' AND value = '%s'", $name, _lock_id()); +} + +/** + * Release all previously acquired locks. + */ +function lock_release_all() { + global $locks; + + $locks = array(); + db_query("DELETE FROM {semaphore} WHERE value = '%s'", _lock_id()); +} + +/** + * @} End of "defgroup locks". + */ Index: modules/system/system.install =================================================================== RCS file: /cvs/drupal/drupal/modules/system/system.install,v retrieving revision 1.238.2.12 diff -u -p -r1.238.2.12 system.install --- modules/system/system.install 25 Feb 2009 14:02:46 -0000 1.238.2.12 +++ modules/system/system.install 18 Apr 2009 13:42:12 -0000 @@ -956,6 +956,31 @@ function system_schema() { 'primary key' => array('mlid'), ); + $schema['semaphore'] = array( + 'description' => 'Table for storing locks and other flags that should not be cached by the variable system.', + 'fields' => array( + 'name' => array( + 'description' => 'Primary Key: Unique name.', + 'type' => 'varchar', + 'length' => 255, + 'not null' => TRUE, + 'default' => ''), + 'value' => array( + 'description' => 'A value.', + 'type' => 'varchar', + 'length' => 255, + 'not null' => TRUE, + 'default' => ''), + 'expire' => array( + 'description' => 'A Unix timestamp with microseconds indicating when the semaphore should expire.', + 'type' => 'float', + 'size' => 'big', + 'not null' => TRUE), + ), + 'indexes' => array('expire' => array('expire')), + 'primary key' => array('name'), + ); + $schema['sessions'] = array( 'description' => "Drupal's session handlers read and write into the sessions table. Each record represents a user session, either anonymous or authenticated.", 'fields' => array( @@ -2548,6 +2573,37 @@ function system_update_6049() { } /** + * Add semaphore table. + */ +function system_update_6050() { + $ret = array(); + + $schema['semaphore'] = array( + 'fields' => array( + 'name' => array( + 'type' => 'varchar', + 'length' => 255, + 'not null' => TRUE, + 'default' => ''), + 'value' => array( + 'type' => 'varchar', + 'length' => 255, + 'not null' => TRUE, + 'default' => ''), + 'expire' => array( + 'type' => 'float', + 'size' => 'big', + 'not null' => TRUE), + ), + 'indexes' => array('expire' => array('expire')), + 'primary key' => array('name'), + ); + db_create_table($ret, 'semaphore', $schema['semaphore']); + + return $ret; +} + +/** * @} End of "defgroup updates-5.x-to-6.x" * The next series of updates should start at 7000. */