summaryrefslogtreecommitdiff
path: root/sql/lock.cc
diff options
context:
space:
mode:
Diffstat (limited to 'sql/lock.cc')
-rw-r--r--sql/lock.cc74
1 files changed, 57 insertions, 17 deletions
diff --git a/sql/lock.cc b/sql/lock.cc
index dd2b61b65d2..fa199ce7454 100644
--- a/sql/lock.cc
+++ b/sql/lock.cc
@@ -68,9 +68,12 @@ TODO:
#include "mysql_priv.h"
#include <hash.h>
-#include <assert.h>
-
-extern HASH open_cache;
+#include "ha_myisammrg.h"
+#ifndef MASTER
+#include "../srclib/myisammrg/myrg_def.h"
+#else
+#include "../myisammrg/myrg_def.h"
+#endif
static MYSQL_LOCK *get_lock_data(THD *thd, TABLE **table,uint count,
bool unlock, TABLE **write_locked);
@@ -156,6 +159,7 @@ retry:
sql_lock=0;
}
}
+
thd->lock_time();
DBUG_RETURN (sql_lock);
}
@@ -236,7 +240,7 @@ void mysql_unlock_read_tables(THD *thd, MYSQL_LOCK *sql_lock)
{
if (sql_lock->locks[i]->type >= TL_WRITE_ALLOW_READ)
{
- swap(THR_LOCK_DATA *,*lock,sql_lock->locks[i]);
+ swap_variables(THR_LOCK_DATA *, *lock, sql_lock->locks[i]);
lock++;
found++;
}
@@ -255,7 +259,7 @@ void mysql_unlock_read_tables(THD *thd, MYSQL_LOCK *sql_lock)
{
if ((uint) sql_lock->table[i]->reginfo.lock_type >= TL_WRITE_ALLOW_READ)
{
- swap(TABLE *,*table,sql_lock->table[i]);
+ swap_variables(TABLE *, *table, sql_lock->table[i]);
table++;
found++;
}
@@ -431,20 +435,37 @@ static MYSQL_LOCK *get_lock_data(THD *thd, TABLE **table_ptr, uint count,
return 0;
}
}
+ THR_LOCK_DATA **org_locks = locks;
locks=table->file->store_lock(thd, locks, get_old_locks ? TL_IGNORE :
lock_type);
+ if (locks)
+ for ( ; org_locks != locks ; org_locks++)
+ (*org_locks)->debug_print_param= (void *) table;
}
return sql_lock;
}
+
/*****************************************************************************
-** Lock table based on the name.
-** This is used when we need total access to a closed, not open table
+ Lock table based on the name.
+ This is used when we need total access to a closed, not open table
*****************************************************************************/
/*
Lock and wait for the named lock.
- Returns 0 on ok
+
+ SYNOPSIS
+ lock_and_wait_for_table_name()
+ thd Thread handler
+ table_list Lock first table in this list
+
+
+ NOTES
+ Works together with global read lock.
+
+ RETURN
+ 0 ok
+ 1 error
*/
int lock_and_wait_for_table_name(THD *thd, TABLE_LIST *table_list)
@@ -474,20 +495,35 @@ end:
/*
Put a not open table with an old refresh version in the table cache.
- This will force any other threads that uses the table to release it
- as soon as possible.
- One must have a lock on LOCK_open !
- Return values:
- < 0 error
- == 0 table locked
- > 0 table locked, but someone is using it
+
+ SYNPOSIS
+ lock_table_name()
+ thd Thread handler
+ table_list Lock first table in this list
+
+ WARNING
+ If you are going to update the table, you should use
+ lock_and_wait_for_table_name instead of this function as this works
+ together with 'FLUSH TABLES WITH READ LOCK'
+
+ NOTES
+ This will force any other threads that uses the table to release it
+ as soon as possible.
+
+ REQUIREMENTS
+ One must have a lock on LOCK_open !
+
+ RETURN:
+ < 0 error
+ == 0 table locked
+ > 0 table locked, but someone is using it
*/
int lock_table_name(THD *thd, TABLE_LIST *table_list)
{
TABLE *table;
char key[MAX_DBKEY_LENGTH];
- char *db= table_list->db ? table_list->db : (thd->db ? thd->db : (char*) "");
+ char *db= table_list->db;
uint key_length;
DBUG_ENTER("lock_table_name");
DBUG_PRINT("enter",("db: %s name: %s", db, table_list->real_name));
@@ -519,7 +555,7 @@ int lock_table_name(THD *thd, TABLE_LIST *table_list)
table->locked_by_name=1;
table_list->table=table;
- if (hash_insert(&open_cache, (byte*) table))
+ if (my_hash_insert(&open_cache, (byte*) table))
{
my_free((gptr) table,MYF(0));
DBUG_RETURN(-1);
@@ -580,6 +616,10 @@ bool wait_for_locked_table_names(THD *thd, TABLE_LIST *table_list)
table_list Names of tables to lock
NOTES
+ If you are just locking one table, you should use
+ lock_and_wait_for_table_name().
+
+ REQUIREMENTS
One must have a lock on LOCK_open when calling this
RETURN