summaryrefslogtreecommitdiff
path: root/sql/lock.cc
diff options
context:
space:
mode:
authorunknown <mikael@c-0409e253.1238-1-64736c10.cust.bredbandsbolaget.se>2006-06-12 17:41:05 -0400
committerunknown <mikael@c-0409e253.1238-1-64736c10.cust.bredbandsbolaget.se>2006-06-12 17:41:05 -0400
commitbe2c2ad2f2bdac641a5f5e60f212ebb04a0b6c45 (patch)
treea0b9a43a413eac584552b1ca4165f411c350eb3f /sql/lock.cc
parentbeaea997e49a6e07b829e29599de5685267b5b37 (diff)
parent7f1a78fc62e98f6a5b15213ab14d674e9eb76d35 (diff)
downloadmariadb-git-be2c2ad2f2bdac641a5f5e60f212ebb04a0b6c45.tar.gz
Merge c-0409e253.1238-1-64736c10.cust.bredbandsbolaget.se:/home/pappa/clean-mysql-5.1
into c-0409e253.1238-1-64736c10.cust.bredbandsbolaget.se:/home/pappa/bug19122 mysql-test/r/partition.result: Auto merged mysql-test/t/partition.test: Auto merged sql/lock.cc: Auto merged sql/mysql_priv.h: Auto merged sql/sql_base.cc: Auto merged sql/sql_partition.cc: Auto merged
Diffstat (limited to 'sql/lock.cc')
-rw-r--r--sql/lock.cc34
1 files changed, 20 insertions, 14 deletions
diff --git a/sql/lock.cc b/sql/lock.cc
index 80861e3beb5..e5003325df6 100644
--- a/sql/lock.cc
+++ b/sql/lock.cc
@@ -828,7 +828,7 @@ int lock_and_wait_for_table_name(THD *thd, TABLE_LIST *table_list)
if (wait_if_global_read_lock(thd, 0, 1))
DBUG_RETURN(1);
VOID(pthread_mutex_lock(&LOCK_open));
- if ((lock_retcode = lock_table_name(thd, table_list)) < 0)
+ if ((lock_retcode = lock_table_name(thd, table_list, TRUE)) < 0)
goto end;
if (lock_retcode && wait_for_locked_table_names(thd, table_list))
{
@@ -851,6 +851,7 @@ end:
lock_table_name()
thd Thread handler
table_list Lock first table in this list
+ check_in_use Do we need to check if table already in use by us
WARNING
If you are going to update the table, you should use
@@ -870,7 +871,7 @@ end:
> 0 table locked, but someone is using it
*/
-int lock_table_name(THD *thd, TABLE_LIST *table_list)
+int lock_table_name(THD *thd, TABLE_LIST *table_list, bool check_in_use)
{
TABLE *table;
char key[MAX_DBKEY_LENGTH];
@@ -882,17 +883,22 @@ int lock_table_name(THD *thd, TABLE_LIST *table_list)
key_length= create_table_def_key(thd, key, table_list, 0);
- /* Only insert the table if we haven't insert it already */
- for (table=(TABLE*) hash_first(&open_cache, (byte*)key, key_length, &state);
- table ;
- table = (TABLE*) hash_next(&open_cache,(byte*) key,key_length, &state))
+ if (check_in_use)
{
- if (table->in_use == thd)
+ /* Only insert the table if we haven't insert it already */
+ for (table=(TABLE*) hash_first(&open_cache, (byte*)key,
+ key_length, &state);
+ table ;
+ table = (TABLE*) hash_next(&open_cache,(byte*) key,
+ key_length, &state))
{
- DBUG_PRINT("info", ("Table is in use"));
- table->s->version= 0; // Ensure no one can use this
- table->locked_by_name= 1;
- DBUG_RETURN(0);
+ if (table->in_use == thd)
+ {
+ DBUG_PRINT("info", ("Table is in use"));
+ table->s->version= 0; // Ensure no one can use this
+ table->locked_by_name= 1;
+ DBUG_RETURN(0);
+ }
}
}
/*
@@ -917,10 +923,10 @@ int lock_table_name(THD *thd, TABLE_LIST *table_list)
my_free((gptr) table,MYF(0));
DBUG_RETURN(-1);
}
-
+
/* Return 1 if table is in use */
DBUG_RETURN(test(remove_table_from_cache(thd, db, table_list->table_name,
- RTFC_NO_FLAG)));
+ check_in_use ? RTFC_NO_FLAG : RTFC_WAIT_OTHER_THREAD_FLAG)));
}
@@ -1003,7 +1009,7 @@ bool lock_table_names(THD *thd, TABLE_LIST *table_list)
for (lock_table= table_list; lock_table; lock_table= lock_table->next_local)
{
int got_lock;
- if ((got_lock=lock_table_name(thd,lock_table)) < 0)
+ if ((got_lock=lock_table_name(thd,lock_table, TRUE)) < 0)
goto end; // Fatal error
if (got_lock)
got_all_locks=0; // Someone is using table