summaryrefslogtreecommitdiff
path: root/sql/lock.cc
diff options
context:
space:
mode:
authorunknown <monty@hundin.mysql.fi>2001-08-14 20:33:49 +0300
committerunknown <monty@hundin.mysql.fi>2001-08-14 20:33:49 +0300
commit410dd0779c32b1975eceeab92a1e62ff099f37db (patch)
tree63b1bcf87d376e768395f4a058416187ee0aad95 /sql/lock.cc
parent97250b9c40a378659c6c4423461021231a3b551d (diff)
downloadmariadb-git-410dd0779c32b1975eceeab92a1e62ff099f37db.tar.gz
Remove warnings and portability fixes
New global read lock code Fixed bug in DATETIME with WHERE optimization Made UNION code more general. include/global.h: Remove warning on Linux Alpha include/mysql_com.h: Move some C variables inside extern "C" block. include/mysqld_error.h: New error mesages myisam/mi_write.c: cleanup mysql-test/r/select.result: Fix because of table lists now always has a database argument. mysql-test/r/type_datetime.result: Test for bug with datetime and where optimization mysql-test/r/union.result: Updated result mysql-test/t/type_datetime.test: New test for datetime mysql-test/t/union.test: More testing of error conditions sql/item_sum.cc: Remove warnings on Linux Alpha sql/item_sum.h: Cleanup sql/lock.cc: Cleaned up global lock handling sql/log_event.cc: Removed default arguments from declarations (not allowed in cxx) sql/mysql_priv.h: New prototypes sql/mysqld.cc: Fix for global locks sql/opt_range.cc: Cleanup sql/share/czech/errmsg.txt: New errors sql/share/danish/errmsg.txt: New errors sql/share/dutch/errmsg.txt: New errors sql/share/english/errmsg.txt: New errors sql/share/estonian/errmsg.txt: New errors sql/share/french/errmsg.txt: New errors sql/share/german/errmsg.txt: New errors sql/share/greek/errmsg.txt: New errors sql/share/hungarian/errmsg.txt: New errors sql/share/italian/errmsg.txt: New errors sql/share/japanese/errmsg.txt: New errors sql/share/korean/errmsg.txt: New errors sql/share/norwegian-ny/errmsg.txt: New errors sql/share/norwegian/errmsg.txt: New errors sql/share/polish/errmsg.txt: New errors sql/share/portuguese/errmsg.txt: New errors sql/share/romanian/errmsg.txt: New errors sql/share/russian/errmsg.txt: New errors sql/share/slovak/errmsg.txt: New errors sql/share/spanish/errmsg.txt: New errors sql/share/swedish/errmsg.OLD: New errors sql/share/swedish/errmsg.txt: New errors sql/sql_acl.cc: Use thd->host_or_ip sql/sql_class.cc: Use new global lock code sql/sql_class.h: host_or_ip sql/sql_db.cc: host_or_ip sql/sql_delete.cc: Use now global lock code sql/sql_lex.h: Cleanup of not used states and variables sql/sql_parse.cc: Use now global locks. Made UNION code more general. Change to use thd->hosts_or_ip. TABLE_LIST now always has 'db' set. sql/sql_repl.cc: Portability fixes. Changed wrong usage of my_vsnprintf -> my_snprintf sql/sql_select.cc: Changes for UNION sql/sql_show.cc: Cleanup sql/sql_union.cc: Handle 'select_result' outside of mysql_union(). sql/sql_yacc.yy: Fixes for union
Diffstat (limited to 'sql/lock.cc')
-rw-r--r--sql/lock.cc117
1 files changed, 93 insertions, 24 deletions
diff --git a/sql/lock.cc b/sql/lock.cc
index 1d9aca66e74..561ce94f88b 100644
--- a/sql/lock.cc
+++ b/sql/lock.cc
@@ -55,35 +55,13 @@ MYSQL_LOCK *mysql_lock_tables(THD *thd,TABLE **tables,uint count)
Someone has issued LOCK ALL TABLES FOR READ and we want a write lock
Wait until the lock is gone
*/
- if (thd->global_read_lock) // This thread had the read locks
+ if (wait_if_global_read_lock(thd, 1))
{
- my_error(ER_TABLE_NOT_LOCKED_FOR_WRITE,MYF(0),
- write_lock_used->table_name);
my_free((gptr) sql_lock,MYF(0));
sql_lock=0;
break;
}
-
- pthread_mutex_lock(&LOCK_open);
- pthread_mutex_lock(&thd->mysys_var->mutex);
- thd->mysys_var->current_mutex= &LOCK_open;
- thd->mysys_var->current_cond= &COND_refresh;
- thd->proc_info="Waiting for table";
- pthread_mutex_unlock(&thd->mysys_var->mutex);
-
- while (global_read_lock && ! thd->killed &&
- thd->version == refresh_version)
- {
- (void) pthread_cond_wait(&COND_refresh,&LOCK_open);
- }
- pthread_mutex_unlock(&LOCK_open);
- pthread_mutex_lock(&thd->mysys_var->mutex);
- thd->mysys_var->current_mutex= 0;
- thd->mysys_var->current_cond= 0;
- thd->proc_info= 0;
- pthread_mutex_unlock(&thd->mysys_var->mutex);
-
- if (thd->version != refresh_version || thd->killed)
+ if (thd->version != refresh_version)
{
my_free((gptr) sql_lock,MYF(0));
goto retry;
@@ -502,3 +480,94 @@ static void print_lock_error(int error)
DBUG_VOID_RETURN;
}
+
+/****************************************************************************
+ Handling of global read locks
+
+ The global locks are handled through the global variables:
+ global_read_lock
+ waiting_for_read_lock
+ protect_against_global_read_lock
+****************************************************************************/
+
+volatile uint global_read_lock=0;
+static volatile uint protect_against_global_read_lock=0;
+static volatile uint waiting_for_read_lock=0;
+
+bool lock_global_read_lock(THD *thd)
+{
+ DBUG_ENTER("lock_global_read_lock");
+
+ if (!thd->global_read_lock)
+ {
+ (void) pthread_mutex_lock(&LOCK_open);
+ const char *old_message=thd->enter_cond(&COND_refresh, &LOCK_open,
+ "Waiting to get readlock");
+ waiting_for_read_lock++;
+ while (protect_against_global_read_lock && !thd->killed)
+ pthread_cond_wait(&COND_refresh, &LOCK_open);
+ waiting_for_read_lock--;
+ if (thd->killed)
+ {
+ (void) pthread_mutex_unlock(&LOCK_open);
+ DBUG_RETURN(1);
+ }
+ thd->global_read_lock=1;
+ global_read_lock++;
+ (void) pthread_mutex_unlock(&LOCK_open);
+ }
+ DBUG_RETURN(0);
+}
+
+void unlock_global_read_lock(THD *thd)
+{
+ uint tmp;
+ thd->global_read_lock=0;
+ pthread_mutex_lock(&LOCK_open);
+ tmp= --global_read_lock;
+ pthread_mutex_unlock(&LOCK_open);
+ /* Send the signal outside the mutex to avoid a context switch */
+ if (!tmp)
+ pthread_cond_broadcast(&COND_refresh);
+}
+
+
+bool wait_if_global_read_lock(THD *thd, bool abort_on_refresh)
+{
+ const char *old_message;
+ bool result=0;
+ DBUG_ENTER("wait_if_global_read_lock");
+
+ (void) pthread_mutex_lock(&LOCK_open);
+ if (global_read_lock)
+ {
+ if (thd->global_read_lock) // This thread had the read locks
+ {
+ my_error(ER_CANT_UPDATE_WITH_READLOCK,MYF(0));
+ DBUG_RETURN(1);
+ }
+ old_message=thd->enter_cond(&COND_refresh, &LOCK_open,
+ "Waiting for release of readlock");
+ while (global_read_lock && ! thd->killed &&
+ (!abort_on_refresh || thd->version == refresh_version))
+ (void) pthread_cond_wait(&COND_refresh,&LOCK_open);
+ if (thd->killed)
+ result=1;
+ thd->exit_cond(old_message);
+ }
+ if (!abort_on_refresh && !result)
+ protect_against_global_read_lock++;
+ pthread_mutex_unlock(&LOCK_open);
+ DBUG_RETURN(result);
+}
+
+
+void start_waiting_global_read_lock(THD *thd)
+{
+ bool tmp;
+ (void) pthread_mutex_lock(&LOCK_open);
+ tmp= (!--protect_against_global_read_lock && waiting_for_read_lock);
+ (void) pthread_mutex_unlock(&LOCK_open);
+ if (tmp)
+ pthread_cond_broadcast(&COND_refresh);
+}