summaryrefslogtreecommitdiff
path: root/sql/lock.cc
diff options
context:
space:
mode:
authorunknown <monty@mysql.com>2005-11-23 22:58:53 +0200
committerunknown <monty@mysql.com>2005-11-23 22:58:53 +0200
commit039168c2fa724b9ed87ce2f19a7ea20acbd8a1de (patch)
tree8972ae3c8dffff8f3b6f27565d191af346c9ac8d /sql/lock.cc
parentfe245ed8ba1258e1f3920e449338ea92e3a3a96e (diff)
parentf631b361b6119fb73df38602ad58e140848f92d7 (diff)
downloadmariadb-git-039168c2fa724b9ed87ce2f19a7ea20acbd8a1de.tar.gz
Merge mysql.com:/home/my/mysql-5.1
into mysql.com:/home/my/mysql-5.1-TDC mysql-test/r/variables.result: Auto merged mysql-test/t/variables.test: Auto merged sql/ha_berkeley.cc: Auto merged sql/ha_federated.cc: Auto merged sql/ha_federated.h: Auto merged sql/ha_innodb.cc: Auto merged sql/ha_myisammrg.cc: Auto merged sql/ha_ndbcluster.cc: Auto merged sql/handler.cc: Auto merged sql/item.cc: Auto merged sql/item.h: Auto merged sql/item_cmpfunc.cc: Auto merged sql/item_func.cc: Auto merged sql/item_subselect.cc: Auto merged sql/item_sum.cc: Auto merged sql/item_timefunc.cc: Auto merged sql/key.cc: Auto merged sql/mysqld.cc: Auto merged sql/opt_range.cc: Auto merged sql/parse_file.cc: Auto merged sql/set_var.cc: Auto merged sql/slave.cc: Auto merged sql/sp.cc: Auto merged sql/sp_head.cc: Auto merged sql/sp_head.h: Auto merged sql/sql_acl.cc: Auto merged sql/sql_class.cc: Auto merged sql/sql_class.h: Auto merged sql/sql_lex.cc: Auto merged sql/sql_lex.h: Auto merged sql/sql_load.cc: Auto merged sql/sql_parse.cc: Auto merged sql/sql_select.cc: Auto merged sql/sql_show.cc: Auto merged sql/sql_table.cc: Auto merged sql/sql_trigger.cc: Auto merged sql/sql_view.cc: Auto merged sql/structs.h: Auto merged sql/field.cc: Merge with global tree sql/sql_base.cc: Merge with global tree sql/table.cc: Merge with global tree
Diffstat (limited to 'sql/lock.cc')
-rw-r--r--sql/lock.cc54
1 files changed, 34 insertions, 20 deletions
diff --git a/sql/lock.cc b/sql/lock.cc
index dc914d1b5f8..288adc19032 100644
--- a/sql/lock.cc
+++ b/sql/lock.cc
@@ -357,12 +357,15 @@ void mysql_lock_abort(THD *thd, TABLE *table)
{
MYSQL_LOCK *locked;
TABLE *write_lock_used;
+ DBUG_ENTER("mysql_lock_abort");
+
if ((locked = get_lock_data(thd,&table,1,1,&write_lock_used)))
{
for (uint i=0; i < locked->lock_count; i++)
thr_abort_locks(locked->locks[i]->lock);
my_free((gptr) locked,MYF(0));
}
+ DBUG_VOID_RETURN;
}
@@ -482,8 +485,8 @@ static MYSQL_LOCK *get_lock_data(THD *thd, TABLE **table_ptr, uint count,
table_ptr[i]->reginfo.lock_type >= TL_WRITE_ALLOW_WRITE &&
count != 1)
{
- my_error(ER_WRONG_LOCK_OF_SYSTEM_TABLE, MYF(0), table_ptr[i]->s->db,
- table_ptr[i]->s->table_name);
+ my_error(ER_WRONG_LOCK_OF_SYSTEM_TABLE, MYF(0), table_ptr[i]->s->db.str,
+ table_ptr[i]->s->table_name.str);
DBUG_RETURN(0);
}
}
@@ -610,32 +613,35 @@ int lock_table_name(THD *thd, TABLE_LIST *table_list)
DBUG_ENTER("lock_table_name");
DBUG_PRINT("enter",("db: %s name: %s", db, table_list->table_name));
- safe_mutex_assert_owner(&LOCK_open);
-
- key_length=(uint) (strmov(strmov(key,db)+1,table_list->table_name)
- -key)+ 1;
-
+ 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_search(&open_cache,(byte*) key,key_length) ;
table ;
table = (TABLE*) hash_next(&open_cache,(byte*) key,key_length))
+ {
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);
-
+ }
+ }
/*
Create a table entry with the right key and with an old refresh version
Note that we must use my_malloc() here as this is freed by the table
cache
*/
- if (!(table= (TABLE*) my_malloc(sizeof(*table)+key_length,
- MYF(MY_WME | MY_ZEROFILL))))
+ if (!(table= (TABLE*) my_malloc(sizeof(*table)+ sizeof(TABLE_SHARE)+
+ key_length, MYF(MY_WME | MY_ZEROFILL))))
DBUG_RETURN(-1);
- table->s= &table->share_not_to_be_used;
- memcpy((table->s->table_cache_key= (char*) (table+1)), key, key_length);
- table->s->db= table->s->table_cache_key;
- table->s->key_length=key_length;
- table->in_use=thd;
+ table->s= (TABLE_SHARE*) (table+1);
+ memcpy((table->s->table_cache_key.str= (char*) (table->s+1)), key,
+ key_length);
+ table->s->table_cache_key.length= key_length;
+ table->s->tmp_table= INTERNAL_TMP_TABLE; // for intern_close_table
+ table->in_use= thd;
table->locked_by_name=1;
table_list->table=table;
@@ -665,8 +671,17 @@ static bool locked_named_table(THD *thd, TABLE_LIST *table_list)
{
for (; table_list ; table_list=table_list->next_local)
{
- if (table_list->table && table_is_used(table_list->table,0))
- return 1;
+ TABLE *table= table_list->table;
+ if (table)
+ {
+ TABLE *save_next= table->next;
+ bool result;
+ table->next= 0;
+ result= table_is_used(table_list->table, 0);
+ table->next= save_next;
+ if (result)
+ return 1;
+ }
}
return 0; // All tables are locked
}
@@ -676,6 +691,7 @@ bool wait_for_locked_table_names(THD *thd, TABLE_LIST *table_list)
{
bool result=0;
DBUG_ENTER("wait_for_locked_table_names");
+
safe_mutex_assert_owner(&LOCK_open);
while (locked_named_table(thd,table_list))
@@ -685,7 +701,7 @@ bool wait_for_locked_table_names(THD *thd, TABLE_LIST *table_list)
result=1;
break;
}
- wait_for_refresh(thd);
+ wait_for_condition(thd, &LOCK_open, &COND_refresh);
pthread_mutex_lock(&LOCK_open);
}
DBUG_RETURN(result);
@@ -1037,5 +1053,3 @@ bool make_global_read_lock_block_commit(THD *thd)
thd->exit_cond(old_message); // this unlocks LOCK_global_read_lock
DBUG_RETURN(error);
}
-
-