? includes/handlers.inc ? modules/system/system.path_lazy.inc ? modules/system/system.path_precache.inc Index: includes/bootstrap.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/bootstrap.inc,v retrieving revision 1.278 diff -u -p -r1.278 bootstrap.inc --- includes/bootstrap.inc 30 Apr 2009 16:15:44 -0000 1.278 +++ includes/bootstrap.inc 4 May 2009 02:07:59 -0000 @@ -1407,6 +1407,8 @@ function _drupal_bootstrap($phase) { } // Prepare for non-cached page workflow. + require_once DRUPAL_ROOT . '/' . variable_get('lock_inc', 'includes/lock.inc'); + lock_init(); // If the session has not already been started and output buffering is // not enabled, the HTTP headers must be sent now, including the session 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 4 May 2009 02:08:00 -0000 @@ -0,0 +1,201 @@ + $name, ':value' => _lock_id()))->fetchField()) { + // The lock was broken. + unset($locks[$name]); + } + } + elseif (lock_may_be_available($name)) { + // Try to acquire the lock. + $expire = microtime(TRUE) + $timeout; + try { + db_insert('semaphore') + ->fields(array( + 'name' => $name, + 'value' => _lock_id(), + 'expire' => $expire, + )) + ->execute(); + $locks[$name] = TRUE; + } + catch (PDOException $e) { + // Suppress the error. + } + } + return isset($locks[$name]); +} + +/** + * Try to renew (extend) a lock previously acquired. + * + * @param $name + * The name of the lock. + * @param $timeout + * A number of seconds (float) before the lock expires. + * @return TRUE if the lock was renewed, FALSE if it failed. + */ +function lock_renew($name, $timeout = 20.0) { + global $locks; + + if (isset($locks[$name])) { + $expire = microtime(TRUE) + $timeout; + return (bool)db_update('semaphore') + ->fields(array('expire' => $expire)) + ->condition('name', $name) + ->condition('value', _lock_id()) + ->execute(); + } + return FALSE; +} + +/** + * Check if lock acquired by a different process may be available. + * + * If an existing lock has expired, it is removed. + * + * @param $name + * The name of the lock. + * + * @return TRUE if there is no lock or it was removed, FALSE otherwise. + */ +function lock_may_be_available($name) { + $lock = db_query("SELECT expire, value FROM {semaphore} WHERE name = :name", array(':name' => $name))->fetchAssoc(); + if (!$lock) { + return TRUE; + } + $now = microtime(TRUE); + if ($now > $lock['expire']) { + return (bool)db_delete('semaphore') + ->condition('name', $name) + ->condition('value', $lock['value']) + ->condition('expire', $lock['expire']) + ->execute(); + } + return FALSE; +} + +/** + * Wait for a lock to be released. + * + * @param $name + * The name of the lock. + * @param $delay + * The maximum number of seconds to wait. + * @return TRUE if the lock holds, FALSE if it is available. + */ +function lock_wait($name, $delay = 30) { + while ($delay--) { + sleep(1); + if (lock_may_be_available($name)) { + return FALSE; + } + } + return TRUE; +} + +/** + * 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_delete('semaphore') + ->condition('name', $name) + ->condition('value', _lock_id()) + ->execute(); +} + +/** + * Release all previously acquired locks. + */ +function lock_release_all($lock_id = NULL) { + global $locks; + + $locks = array(); + if (empty($lock_id)) { + $lock_id = _lock_id(); + } + db_delete('semaphore') + ->condition('value', $lock_id) + ->execute(); +} + +/** + * @} End of "defgroup locks". + */ Index: includes/menu.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/menu.inc,v retrieving revision 1.322 diff -u -p -r1.322 menu.inc --- includes/menu.inc 25 Apr 2009 15:19:12 -0000 1.322 +++ includes/menu.inc 4 May 2009 02:08:00 -0000 @@ -1818,16 +1818,28 @@ function menu_cache_clear_all() { * is different and leaves stale data in the menu tables. */ function menu_rebuild() { - variable_del('menu_rebuild_needed'); + if (!lock_acquire('menu_rebuild')) { + // Wait for another request that is already doing this work. + lock_wait('menu_rebuild'); + return FALSE; + } + list($menu, $masks) = menu_router_build(); _menu_router_save($menu, $masks); - _menu_navigation_links_rebuild($menu); - menu_cache_clear_all(); - // Clear the page and block caches. - _menu_clear_page_cache(); + if (lock_renew('menu_rebuild')) { + _menu_navigation_links_rebuild($menu); + // Clear the menu, page and block caches. + menu_cache_clear_all(); + _menu_clear_page_cache(); + } if (defined('MAINTENANCE_MODE')) { variable_set('menu_rebuild_needed', TRUE); } + else { + variable_del('menu_rebuild_needed'); + } + lock_release('menu_rebuild'); + return TRUE; } /** Index: modules/locale/locale.module =================================================================== RCS file: /cvs/drupal/drupal/modules/locale/locale.module,v retrieving revision 1.238 diff -u -p -r1.238 locale.module --- modules/locale/locale.module 31 Mar 2009 02:02:21 -0000 1.238 +++ modules/locale/locale.module 4 May 2009 02:08:00 -0000 @@ -372,7 +372,7 @@ function locale($string = NULL, $langcod if ($cache = cache_get('locale:' . $langcode, 'cache')) { $locale_t[$langcode] = $cache->data; } - else { + elseif (lock_acquire('locale_cache_' . $langcode)) { // Refresh database stored cache of translations for given language. // We only store short strings used in current version, to improve // performance and consume less memory. @@ -381,6 +381,7 @@ function locale($string = NULL, $langcod $locale_t[$langcode][$data->source] = (empty($data->translation) ? TRUE : $data->translation); } cache_set('locale:' . $langcode, $locale_t[$langcode]); + lock_release('locale_cache_' . $langcode); } } }