--- modules/system/system.module.orig	2010-02-02 13:49:54.000000000 -0800
+++ modules/system/system.module	2010-02-02 13:51:11.000000000 -0800
@@ -812,6 +812,8 @@
   // Extract current files from database.
   system_get_files_database($themes, 'theme');
 
+  db_lock_table('system');
+
   db_query("DELETE FROM {system} WHERE type = 'theme'");
 
   foreach ($themes as $theme) {
@@ -822,6 +824,8 @@
     db_query("INSERT INTO {system} (name, owner, info, type, filename, status, throttle, bootstrap) VALUES ('%s', '%s', '%s', '%s', '%s', %d, %d, %d)", $theme->name, $theme->owner, serialize($theme->info), 'theme', $theme->filename, isset($theme->status) ? $theme->status : 0, 0, 0);
   }
 
+  db_unlock_tables();
+
   return $themes;
 }
 
