summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorAlexander Nozdrin <alik@sun.com>2009-12-17 23:02:52 +0300
committerAlexander Nozdrin <alik@sun.com>2009-12-17 23:02:52 +0300
commit5244303ac900d589706f75b12e59063cdbb3bd2e (patch)
tree4a2290cb7f9ba65d264395cea1348ad6251496fb /sql
parent2ba49bee0e97ab9571a8bf965b18a7946822b7fb (diff)
parent92630be0ee81604ec47cb8c7e9ab016e5449dc4d (diff)
downloadmariadb-git-5244303ac900d589706f75b12e59063cdbb3bd2e.tar.gz
Manual merge from mysql-next-mr.
Conflicts: - mysys/charset.c - mysys/my_thr_init.c
Diffstat (limited to 'sql')
-rw-r--r--sql/debug_sync.cc96
-rw-r--r--sql/ha_ndbcluster.cc26
-rw-r--r--sql/ha_ndbcluster_binlog.cc40
-rw-r--r--sql/item_func.cc104
-rw-r--r--sql/lock.cc14
-rw-r--r--sql/mysql_priv.h17
-rw-r--r--sql/mysqld.cc63
-rw-r--r--sql/replication.h6
-rw-r--r--sql/sp_cache.cc30
-rw-r--r--sql/sql_base.cc156
-rw-r--r--sql/sql_class.cc18
-rw-r--r--sql/sql_class.h16
-rw-r--r--sql/sql_db.cc116
-rw-r--r--sql/sql_delete.cc14
-rw-r--r--sql/sql_handler.cc9
-rw-r--r--sql/sql_insert.cc177
-rw-r--r--sql/sql_parse.cc6
-rw-r--r--sql/sql_partition.cc8
-rw-r--r--sql/sql_plugin.cc4
-rw-r--r--sql/sql_rename.cc12
-rw-r--r--sql/sql_show.cc30
-rw-r--r--sql/sql_table.cc136
-rw-r--r--sql/sql_test.cc18
-rw-r--r--sql/sql_trigger.cc8
-rw-r--r--sql/sql_view.cc10
25 files changed, 629 insertions, 505 deletions
diff --git a/sql/debug_sync.cc b/sql/debug_sync.cc
index 81870e6b7a3..3c8e24f6901 100644
--- a/sql/debug_sync.cc
+++ b/sql/debug_sync.cc
@@ -221,14 +221,14 @@
There are quite a few places in MySQL, where we use a synchronization
pattern like this:
- pthread_mutex_lock(&mutex);
+ mysql_mutex_lock(&mutex);
thd->enter_cond(&condition_variable, &mutex, new_message);
#if defined(ENABLE_DEBUG_SYNC)
if (!thd->killed && !end_of_wait_condition)
DEBUG_SYNC(thd, "sync_point_name");
#endif
while (!thd->killed && !end_of_wait_condition)
- pthread_cond_wait(&condition_variable, &mutex);
+ mysql_cond_wait(&condition_variable, &mutex);
thd->exit_cond(old_message);
Here some explanations:
@@ -264,12 +264,12 @@
while (!thd->killed && !end_of_wait_condition)
{
- pthread_mutex_lock(&mutex);
+ mysql_mutex_lock(&mutex);
thd->enter_cond(&condition_variable, &mutex, new_message);
if (!thd->killed [&& !end_of_wait_condition])
{
[DEBUG_SYNC(thd, "sync_point_name");]
- pthread_cond_wait(&condition_variable, &mutex);
+ mysql_cond_wait(&condition_variable, &mutex);
}
thd->exit_cond(old_message);
}
@@ -285,7 +285,7 @@
before sleeping, we hold the mutex, which is registered in mysys_var.
The killing thread would try to acquire the mutex before signaling
the condition variable. Since the mutex is only released implicitly in
- pthread_cond_wait(), the signaling happens at the right place. We
+ mysql_cond_wait(), the signaling happens at the right place. We
have a safe synchronization.
=== Co-work with the DBUG facility ===
@@ -373,8 +373,8 @@ struct st_debug_sync_control
struct st_debug_sync_globals
{
String ds_signal; /* signal variable */
- pthread_cond_t ds_cond; /* condition variable */
- pthread_mutex_t ds_mutex; /* mutex variable */
+ mysql_cond_t ds_cond; /* condition variable */
+ mysql_mutex_t ds_mutex; /* mutex variable */
ulonglong dsp_hits; /* statistics */
ulonglong dsp_executed; /* statistics */
ulonglong dsp_max_active; /* statistics */
@@ -425,6 +425,37 @@ static void debug_sync_C_callback(const char *sync_point_name,
debug_sync(current_thd, sync_point_name, name_len);
}
+#ifdef HAVE_PSI_INTERFACE
+static PSI_mutex_key key_debug_sync_globals_ds_mutex;
+
+static PSI_mutex_info all_debug_sync_mutexes[]=
+{
+ { &key_debug_sync_globals_ds_mutex, "DEBUG_SYNC::mutex", PSI_FLAG_GLOBAL}
+};
+
+static PSI_cond_key key_debug_sync_globals_ds_cond;
+
+static PSI_cond_info all_debug_sync_conds[]=
+{
+ { &key_debug_sync_globals_ds_cond, "DEBUG_SYNC::cond", PSI_FLAG_GLOBAL}
+};
+
+static void init_debug_sync_psi_keys(void)
+{
+ const char* category= "sql";
+ int count;
+
+ if (PSI_server == NULL)
+ return;
+
+ count= array_elements(all_debug_sync_mutexes);
+ PSI_server->register_mutex(category, all_debug_sync_mutexes, count);
+
+ count= array_elements(all_debug_sync_conds);
+ PSI_server->register_cond(category, all_debug_sync_conds, count);
+}
+#endif /* HAVE_PSI_INTERFACE */
+
/**
Initialize the debug sync facility at server start.
@@ -438,15 +469,21 @@ int debug_sync_init(void)
{
DBUG_ENTER("debug_sync_init");
+#ifdef HAVE_PSI_INTERFACE
+ init_debug_sync_psi_keys();
+#endif
+
if (opt_debug_sync_timeout)
{
int rc;
/* Initialize the global variables. */
debug_sync_global.ds_signal.length(0);
- if ((rc= pthread_cond_init(&debug_sync_global.ds_cond, NULL)) ||
- (rc= pthread_mutex_init(&debug_sync_global.ds_mutex,
- MY_MUTEX_INIT_FAST)))
+ if ((rc= mysql_cond_init(key_debug_sync_globals_ds_cond,
+ &debug_sync_global.ds_cond, NULL)) ||
+ (rc= mysql_mutex_init(key_debug_sync_globals_ds_mutex,
+ &debug_sync_global.ds_mutex,
+ MY_MUTEX_INIT_FAST)))
DBUG_RETURN(rc); /* purecov: inspected */
/* Set the call back pointer in C files. */
@@ -476,8 +513,8 @@ void debug_sync_end(void)
/* Destroy the global variables. */
debug_sync_global.ds_signal.free();
- (void) pthread_cond_destroy(&debug_sync_global.ds_cond);
- (void) pthread_mutex_destroy(&debug_sync_global.ds_mutex);
+ mysql_cond_destroy(&debug_sync_global.ds_cond);
+ mysql_mutex_destroy(&debug_sync_global.ds_mutex);
/* Print statistics. */
{
@@ -585,12 +622,12 @@ void debug_sync_end_thread(THD *thd)
}
/* Statistics. */
- pthread_mutex_lock(&debug_sync_global.ds_mutex);
+ mysql_mutex_lock(&debug_sync_global.ds_mutex);
debug_sync_global.dsp_hits+= ds_control->dsp_hits;
debug_sync_global.dsp_executed+= ds_control->dsp_executed;
if (debug_sync_global.dsp_max_active < ds_control->dsp_max_active)
debug_sync_global.dsp_max_active= ds_control->dsp_max_active;
- pthread_mutex_unlock(&debug_sync_global.ds_mutex);
+ mysql_mutex_unlock(&debug_sync_global.ds_mutex);
my_free(ds_control, MYF(0));
thd->debug_sync_control= NULL;
@@ -824,9 +861,9 @@ static void debug_sync_reset(THD *thd)
ds_control->ds_active= 0;
/* Clear the global signal. */
- pthread_mutex_lock(&debug_sync_global.ds_mutex);
+ mysql_mutex_lock(&debug_sync_global.ds_mutex);
debug_sync_global.ds_signal.length(0);
- pthread_mutex_unlock(&debug_sync_global.ds_mutex);
+ mysql_mutex_unlock(&debug_sync_global.ds_mutex);
DBUG_VOID_RETURN;
}
@@ -1659,7 +1696,7 @@ uchar *sys_var_debug_sync::value_ptr(THD *thd,
static char on[]= "ON - current signal: '";
// Ensure exclusive access to debug_sync_global.ds_signal
- pthread_mutex_lock(&debug_sync_global.ds_mutex);
+ mysql_mutex_lock(&debug_sync_global.ds_mutex);
size_t lgt= (sizeof(on) /* includes '\0' */ +
debug_sync_global.ds_signal.length() + 1 /* for '\'' */);
@@ -1676,7 +1713,7 @@ uchar *sys_var_debug_sync::value_ptr(THD *thd,
*(vptr++)= '\'';
*vptr= '\0'; /* We have one byte reserved for the worst case. */
}
- pthread_mutex_unlock(&debug_sync_global.ds_mutex);
+ mysql_mutex_unlock(&debug_sync_global.ds_mutex);
}
else
{
@@ -1744,7 +1781,7 @@ static void debug_sync_execute(THD *thd, st_debug_sync_action *action)
read access too, to create a memory barrier in order to avoid that
threads just reads an old cached version of the signal.
*/
- pthread_mutex_lock(&debug_sync_global.ds_mutex);
+ mysql_mutex_lock(&debug_sync_global.ds_mutex);
if (action->signal.length())
{
@@ -1758,15 +1795,15 @@ static void debug_sync_execute(THD *thd, st_debug_sync_action *action)
debug_sync_emergency_disable(); /* purecov: tested */
}
/* Wake threads waiting in a sync point. */
- pthread_cond_broadcast(&debug_sync_global.ds_cond);
+ mysql_cond_broadcast(&debug_sync_global.ds_cond);
DBUG_PRINT("debug_sync_exec", ("signal '%s' at: '%s'",
sig_emit, dsp_name));
} /* end if (action->signal.length()) */
if (action->wait_for.length())
{
- pthread_mutex_t *old_mutex;
- pthread_cond_t *old_cond;
+ mysql_mutex_t *old_mutex;
+ mysql_cond_t *old_cond;
int error= 0;
struct timespec abstime;
@@ -1797,9 +1834,9 @@ static void debug_sync_execute(THD *thd, st_debug_sync_action *action)
while (stringcmp(&debug_sync_global.ds_signal, &action->wait_for) &&
!thd->killed && opt_debug_sync_timeout)
{
- error= pthread_cond_timedwait(&debug_sync_global.ds_cond,
- &debug_sync_global.ds_mutex,
- &abstime);
+ error= mysql_cond_timedwait(&debug_sync_global.ds_cond,
+ &debug_sync_global.ds_mutex,
+ &abstime);
DBUG_EXECUTE("debug_sync", {
/* Functions as DBUG_PRINT args can change keyword and line nr. */
const char *sig_glob= debug_sync_global.ds_signal.c_ptr();
@@ -1832,18 +1869,17 @@ static void debug_sync_execute(THD *thd, st_debug_sync_action *action)
protected mutex must always unlocked _before_ mysys_var->mutex
is locked. (See comment in THD::exit_cond().)
*/
- pthread_mutex_unlock(&debug_sync_global.ds_mutex);
- pthread_mutex_lock(&thd->mysys_var->mutex);
+ mysql_mutex_unlock(&debug_sync_global.ds_mutex);
+ mysql_mutex_lock(&thd->mysys_var->mutex);
thd->mysys_var->current_mutex= old_mutex;
thd->mysys_var->current_cond= old_cond;
thd_proc_info(thd, old_proc_info);
- pthread_mutex_unlock(&thd->mysys_var->mutex);
-
+ mysql_mutex_unlock(&thd->mysys_var->mutex);
}
else
{
/* In case we don't wait, we just release the mutex. */
- pthread_mutex_unlock(&debug_sync_global.ds_mutex);
+ mysql_mutex_unlock(&debug_sync_global.ds_mutex);
} /* end if (action->wait_for.length()) */
} /* end if (action->execute) */
diff --git a/sql/ha_ndbcluster.cc b/sql/ha_ndbcluster.cc
index a9cc37f3162..1103683b56c 100644
--- a/sql/ha_ndbcluster.cc
+++ b/sql/ha_ndbcluster.cc
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2003 MySQL AB
+/* Copyright (C) 2000-2003 MySQL AB, 2008-2009 Sun Microsystems, Inc
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -6909,7 +6909,7 @@ int ndbcluster_drop_database_impl(const char *path)
while ((tabname=it++))
{
tablename_to_filename(tabname, tmp, FN_REFLEN - (tmp - full_path)-1);
- pthread_mutex_lock(&LOCK_open);
+ mysql_mutex_lock(&LOCK_open);
if (ha_ndbcluster::delete_table(0, ndb, full_path, dbname, tabname))
{
const NdbError err= dict->getNdbError();
@@ -6919,7 +6919,7 @@ int ndbcluster_drop_database_impl(const char *path)
ret= ndb_to_mysql_error(&err);
}
}
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
}
DBUG_RETURN(ret);
}
@@ -7071,7 +7071,7 @@ int ndbcluster_find_all_files(THD *thd)
my_free((char*) data, MYF(MY_ALLOW_ZERO_PTR));
my_free((char*) pack_data, MYF(MY_ALLOW_ZERO_PTR));
- pthread_mutex_lock(&LOCK_open);
+ mysql_mutex_lock(&LOCK_open);
if (discover)
{
/* ToDo 4.1 database needs to be created if missing */
@@ -7089,7 +7089,7 @@ int ndbcluster_find_all_files(THD *thd)
TRUE);
}
#endif
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
}
}
while (unhandled && retries);
@@ -7182,19 +7182,19 @@ int ndbcluster_find_files(handlerton *hton, THD *thd,
file_name->str, reg_ext, 0);
if (my_access(name, F_OK))
{
- pthread_mutex_lock(&LOCK_open);
+ mysql_mutex_lock(&LOCK_open);
DBUG_PRINT("info", ("Table %s listed and need discovery",
file_name->str));
if (ndb_create_table_from_engine(thd, db, file_name->str))
{
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
ER_TABLE_EXISTS_ERROR,
"Discover of table %s.%s failed",
db, file_name->str);
continue;
}
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
}
DBUG_PRINT("info", ("%s existed in NDB _and_ on disk ", file_name->str));
file_on_disk= TRUE;
@@ -7251,10 +7251,10 @@ int ndbcluster_find_files(handlerton *hton, THD *thd,
file_name_str= (char*)my_hash_element(&ok_tables, i);
end= end1 +
tablename_to_filename(file_name_str, end1, sizeof(name) - (end1 - name));
- pthread_mutex_lock(&LOCK_open);
+ mysql_mutex_lock(&LOCK_open);
ndbcluster_create_binlog_setup(ndb, name, end-name,
db, file_name_str, TRUE);
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
}
}
#endif
@@ -7303,7 +7303,7 @@ int ndbcluster_find_files(handlerton *hton, THD *thd,
}
}
- pthread_mutex_lock(&LOCK_open);
+ mysql_mutex_lock(&LOCK_open);
// Create new files
List_iterator_fast<char> it2(create_list);
while ((file_name_str=it2++))
@@ -7318,7 +7318,7 @@ int ndbcluster_find_files(handlerton *hton, THD *thd,
}
}
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
my_hash_free(&ok_tables);
my_hash_free(&ndb_tables);
@@ -8246,7 +8246,7 @@ int handle_trailing_share(NDB_SHARE *share)
bzero((char*) &table_list,sizeof(table_list));
table_list.db= share->db;
table_list.alias= table_list.table_name= share->table_name;
- safe_mutex_assert_owner(&LOCK_open);
+ mysql_mutex_assert_owner(&LOCK_open);
close_cached_tables(thd, &table_list, TRUE, FALSE, FALSE);
pthread_mutex_lock(&ndbcluster_mutex);
diff --git a/sql/ha_ndbcluster_binlog.cc b/sql/ha_ndbcluster_binlog.cc
index a22ce976351..bdbb57224b0 100644
--- a/sql/ha_ndbcluster_binlog.cc
+++ b/sql/ha_ndbcluster_binlog.cc
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2003 MySQL AB
+/* Copyright (C) 2000-2003 MySQL AB, 2008-2009 Sun Microsystems, Inc
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -343,7 +343,7 @@ ndbcluster_binlog_open_table(THD *thd, NDB_SHARE *share,
int error;
DBUG_ENTER("ndbcluster_binlog_open_table");
- safe_mutex_assert_owner(&LOCK_open);
+ mysql_mutex_assert_owner(&LOCK_open);
init_tmp_table_share(thd, table_share, share->db, 0, share->table_name,
share->key);
if ((error= open_table_def(thd, table_share, 0)))
@@ -891,9 +891,9 @@ int ndbcluster_setup_binlog_table_shares(THD *thd)
if (!ndb_schema_share &&
ndbcluster_check_ndb_schema_share() == 0)
{
- pthread_mutex_lock(&LOCK_open);
+ mysql_mutex_lock(&LOCK_open);
ndb_create_table_from_engine(thd, NDB_REP_DB, NDB_SCHEMA_TABLE);
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
if (!ndb_schema_share)
{
ndbcluster_create_schema_table(thd);
@@ -905,9 +905,9 @@ int ndbcluster_setup_binlog_table_shares(THD *thd)
if (!ndb_apply_status_share &&
ndbcluster_check_ndb_apply_status_share() == 0)
{
- pthread_mutex_lock(&LOCK_open);
+ mysql_mutex_lock(&LOCK_open);
ndb_create_table_from_engine(thd, NDB_REP_DB, NDB_APPLY_TABLE);
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
if (!ndb_apply_status_share)
{
ndbcluster_create_ndb_apply_status_table(thd);
@@ -917,12 +917,12 @@ int ndbcluster_setup_binlog_table_shares(THD *thd)
}
if (!ndbcluster_find_all_files(thd))
{
- pthread_mutex_lock(&LOCK_open);
+ mysql_mutex_lock(&LOCK_open);
ndb_binlog_tables_inited= TRUE;
if (ndb_extra_logging)
sql_print_information("NDB Binlog: ndb tables writable");
close_cached_tables(NULL, NULL, TRUE, FALSE, FALSE);
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
/* Signal injector thread that all is setup */
pthread_cond_signal(&injector_cond);
}
@@ -1565,8 +1565,8 @@ end:
(void) pthread_mutex_lock(&ndb_schema_object->mutex);
if (have_lock_open)
{
- safe_mutex_assert_owner(&LOCK_open);
- (void) pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_assert_owner(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
}
while (1)
{
@@ -1625,7 +1625,7 @@ end:
}
if (have_lock_open)
{
- (void) pthread_mutex_lock(&LOCK_open);
+ mysql_mutex_lock(&LOCK_open);
}
(void) pthread_mutex_unlock(&ndb_schema_object->mutex);
}
@@ -1709,7 +1709,7 @@ ndb_handle_schema_change(THD *thd, Ndb *ndb, NdbEventOperation *pOp,
{
DBUG_DUMP("frm", (uchar*) altered_table->getFrmData(),
altered_table->getFrmLength());
- pthread_mutex_lock(&LOCK_open);
+ mysql_mutex_lock(&LOCK_open);
Ndb_table_guard ndbtab_g(dict, tabname);
const NDBTAB *old= ndbtab_g.get_table();
if (!old &&
@@ -1747,7 +1747,7 @@ ndb_handle_schema_change(THD *thd, Ndb *ndb, NdbEventOperation *pOp,
dbname= table_share->db.str;
tabname= table_share->table_name.str;
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
}
my_free((char*)data, MYF(MY_ALLOW_ZERO_PTR));
my_free((char*)pack_data, MYF(MY_ALLOW_ZERO_PTR));
@@ -1974,7 +1974,7 @@ ndb_binlog_thread_handle_schema_event(THD *thd, Ndb *ndb,
}
// fall through
case SOT_CREATE_TABLE:
- pthread_mutex_lock(&LOCK_open);
+ mysql_mutex_lock(&LOCK_open);
if (ndbcluster_check_if_local_table(schema->db, schema->name))
{
DBUG_PRINT("info", ("NDB Binlog: Skipping locally defined table '%s.%s'",
@@ -1988,7 +1988,7 @@ ndb_binlog_thread_handle_schema_event(THD *thd, Ndb *ndb,
{
print_could_not_discover_error(thd, schema);
}
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
log_query= 1;
break;
case SOT_DROP_DB:
@@ -2257,7 +2257,7 @@ ndb_binlog_thread_handle_schema_event_post_epoch(THD *thd,
free_share(&share);
share= 0;
}
- pthread_mutex_lock(&LOCK_open);
+ mysql_mutex_lock(&LOCK_open);
if (ndbcluster_check_if_local_table(schema->db, schema->name))
{
DBUG_PRINT("info", ("NDB Binlog: Skipping locally defined table '%s.%s'",
@@ -2271,7 +2271,7 @@ ndb_binlog_thread_handle_schema_event_post_epoch(THD *thd,
{
print_could_not_discover_error(thd, schema);
}
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
}
break;
default:
@@ -3155,8 +3155,8 @@ ndbcluster_handle_drop_table(Ndb *ndb, const char *event_name,
#ifdef SYNC_DROP_
thd->proc_info= "Syncing ndb table schema operation and binlog";
(void) pthread_mutex_lock(&share->mutex);
- safe_mutex_assert_owner(&LOCK_open);
- (void) pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_assert_owner(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
int max_timeout= opt_ndb_sync_timeout;
while (share->op)
{
@@ -3182,7 +3182,7 @@ ndbcluster_handle_drop_table(Ndb *ndb, const char *event_name,
type_str, share->key);
}
}
- (void) pthread_mutex_lock(&LOCK_open);
+ mysql_mutex_lock(&LOCK_open);
(void) pthread_mutex_unlock(&share->mutex);
#else
(void) pthread_mutex_lock(&share->mutex);
diff --git a/sql/item_func.cc b/sql/item_func.cc
index 691af708d51..6f14e69e101 100644
--- a/sql/item_func.cc
+++ b/sql/item_func.cc
@@ -1,4 +1,4 @@
-/* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
+/* Copyright 2000-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -3282,7 +3282,7 @@ bool udf_handler::get_arguments() { return 0; }
** User level locks
*/
-pthread_mutex_t LOCK_user_locks;
+mysql_mutex_t LOCK_user_locks;
static HASH hash_user_locks;
class User_level_lock
@@ -3293,7 +3293,7 @@ class User_level_lock
public:
int count;
bool locked;
- pthread_cond_t cond;
+ mysql_cond_t cond;
my_thread_id thread_id;
void set_thread(THD *thd) { thread_id= thd->thread_id; }
@@ -3301,7 +3301,7 @@ public:
:key_length(length),count(1),locked(1), thread_id(id)
{
key= (uchar*) my_memdup(key_arg,length,MYF(0));
- pthread_cond_init(&cond,NULL);
+ mysql_cond_init(key_user_level_lock_cond, &cond, NULL);
if (key)
{
if (my_hash_insert(&hash_user_locks,(uchar*) this))
@@ -3318,7 +3318,7 @@ public:
my_hash_delete(&hash_user_locks,(uchar*) this);
my_free(key, MYF(0));
}
- pthread_cond_destroy(&cond);
+ mysql_cond_destroy(&cond);
}
inline bool initialized() { return key != 0; }
friend void item_user_lock_release(User_level_lock *ull);
@@ -3333,12 +3333,36 @@ uchar *ull_get_key(const User_level_lock *ull, size_t *length,
return ull->key;
}
+#ifdef HAVE_PSI_INTERFACE
+static PSI_mutex_key key_LOCK_user_locks;
+
+static PSI_mutex_info all_user_mutexes[]=
+{
+ { &key_LOCK_user_locks, "LOCK_user_locks", PSI_FLAG_GLOBAL}
+};
+
+static void init_user_lock_psi_keys(void)
+{
+ const char* category= "sql";
+ int count;
+
+ if (PSI_server == NULL)
+ return;
+
+ count= array_elements(all_user_mutexes);
+ PSI_server->register_mutex(category, all_user_mutexes, count);
+}
+#endif
static bool item_user_lock_inited= 0;
void item_user_lock_init(void)
{
- pthread_mutex_init(&LOCK_user_locks,MY_MUTEX_INIT_SLOW);
+#ifdef HAVE_PSI_INTERFACE
+ init_user_lock_psi_keys();
+#endif
+
+ mysql_mutex_init(key_LOCK_user_locks, &LOCK_user_locks, MY_MUTEX_INIT_SLOW);
my_hash_init(&hash_user_locks,system_charset_info,
16,0,0,(my_hash_get_key) ull_get_key,NULL,0);
item_user_lock_inited= 1;
@@ -3350,7 +3374,7 @@ void item_user_lock_free(void)
{
item_user_lock_inited= 0;
my_hash_free(&hash_user_locks);
- pthread_mutex_destroy(&LOCK_user_locks);
+ mysql_mutex_destroy(&LOCK_user_locks);
}
}
@@ -3359,7 +3383,7 @@ void item_user_lock_release(User_level_lock *ull)
ull->locked=0;
ull->thread_id= 0;
if (--ull->count)
- pthread_cond_signal(&ull->cond);
+ mysql_cond_signal(&ull->cond);
else
delete ull;
}
@@ -3402,7 +3426,7 @@ void debug_sync_point(const char* lock_name, uint lock_timeout)
struct timespec abstime;
size_t lock_name_len;
lock_name_len= strlen(lock_name);
- pthread_mutex_lock(&LOCK_user_locks);
+ mysql_mutex_lock(&LOCK_user_locks);
if (thd->ull)
{
@@ -3420,7 +3444,7 @@ void debug_sync_point(const char* lock_name, uint lock_timeout)
(uchar*) lock_name,
lock_name_len))))
{
- pthread_mutex_unlock(&LOCK_user_locks);
+ mysql_mutex_unlock(&LOCK_user_locks);
return;
}
ull->count++;
@@ -3436,7 +3460,7 @@ void debug_sync_point(const char* lock_name, uint lock_timeout)
set_timespec(abstime,lock_timeout);
while (ull->locked && !thd->killed)
{
- int error= pthread_cond_timedwait(&ull->cond, &LOCK_user_locks, &abstime);
+ int error= mysql_cond_timedwait(&ull->cond, &LOCK_user_locks, &abstime);
if (error == ETIMEDOUT || error == ETIME)
break;
}
@@ -3452,19 +3476,19 @@ void debug_sync_point(const char* lock_name, uint lock_timeout)
ull->set_thread(thd);
thd->ull=ull;
}
- pthread_mutex_unlock(&LOCK_user_locks);
- pthread_mutex_lock(&thd->mysys_var->mutex);
+ mysql_mutex_unlock(&LOCK_user_locks);
+ mysql_mutex_lock(&thd->mysys_var->mutex);
thd_proc_info(thd, 0);
thd->mysys_var->current_mutex= 0;
thd->mysys_var->current_cond= 0;
- pthread_mutex_unlock(&thd->mysys_var->mutex);
- pthread_mutex_lock(&LOCK_user_locks);
+ mysql_mutex_unlock(&thd->mysys_var->mutex);
+ mysql_mutex_lock(&LOCK_user_locks);
if (thd->ull)
{
item_user_lock_release(thd->ull);
thd->ull=0;
}
- pthread_mutex_unlock(&LOCK_user_locks);
+ mysql_mutex_unlock(&LOCK_user_locks);
}
#endif
@@ -3482,8 +3506,8 @@ void debug_sync_point(const char* lock_name, uint lock_timeout)
#define INTERRUPT_INTERVAL (5 * ULL(1000000000))
-static int interruptible_wait(THD *thd, pthread_cond_t *cond,
- pthread_mutex_t *lock, double time)
+static int interruptible_wait(THD *thd, mysql_cond_t *cond,
+ mysql_mutex_t *lock, double time)
{
int error;
struct timespec abstime;
@@ -3499,7 +3523,7 @@ static int interruptible_wait(THD *thd, pthread_cond_t *cond,
timeout-= slice;
set_timespec_nsec(abstime, slice);
- error= pthread_cond_timedwait(cond, lock, &abstime);
+ error= mysql_cond_timedwait(cond, lock, &abstime);
if (error == ETIMEDOUT || error == ETIME)
{
/* Return error if timed out or connection is broken. */
@@ -3542,11 +3566,11 @@ longlong Item_func_get_lock::val_int()
if (thd->slave_thread)
DBUG_RETURN(1);
- pthread_mutex_lock(&LOCK_user_locks);
+ mysql_mutex_lock(&LOCK_user_locks);
if (!res || !res->length())
{
- pthread_mutex_unlock(&LOCK_user_locks);
+ mysql_mutex_unlock(&LOCK_user_locks);
null_value=1;
DBUG_RETURN(0);
}
@@ -3569,13 +3593,13 @@ longlong Item_func_get_lock::val_int()
if (!ull || !ull->initialized())
{
delete ull;
- pthread_mutex_unlock(&LOCK_user_locks);
+ mysql_mutex_unlock(&LOCK_user_locks);
null_value=1; // Probably out of memory
DBUG_RETURN(0);
}
ull->set_thread(thd);
thd->ull=ull;
- pthread_mutex_unlock(&LOCK_user_locks);
+ mysql_mutex_unlock(&LOCK_user_locks);
DBUG_PRINT("info", ("made new lock"));
DBUG_RETURN(1); // Got new lock
}
@@ -3625,13 +3649,13 @@ longlong Item_func_get_lock::val_int()
error=0;
DBUG_PRINT("info", ("got the lock"));
}
- pthread_mutex_unlock(&LOCK_user_locks);
+ mysql_mutex_unlock(&LOCK_user_locks);
- pthread_mutex_lock(&thd->mysys_var->mutex);
+ mysql_mutex_lock(&thd->mysys_var->mutex);
thd_proc_info(thd, 0);
thd->mysys_var->current_mutex= 0;
thd->mysys_var->current_cond= 0;
- pthread_mutex_unlock(&thd->mysys_var->mutex);
+ mysql_mutex_unlock(&thd->mysys_var->mutex);
DBUG_RETURN(!error ? 1 : 0);
}
@@ -3662,7 +3686,7 @@ longlong Item_func_release_lock::val_int()
null_value=0;
result=0;
- pthread_mutex_lock(&LOCK_user_locks);
+ mysql_mutex_lock(&LOCK_user_locks);
if (!(ull= ((User_level_lock*) my_hash_search(&hash_user_locks,
(const uchar*) res->ptr(),
(size_t) res->length()))))
@@ -3683,7 +3707,7 @@ longlong Item_func_release_lock::val_int()
thd->ull=0;
}
}
- pthread_mutex_unlock(&LOCK_user_locks);
+ mysql_mutex_unlock(&LOCK_user_locks);
DBUG_RETURN(result);
}
@@ -3789,7 +3813,7 @@ void Item_func_benchmark::print(String *str, enum_query_type query_type)
longlong Item_func_sleep::val_int()
{
THD *thd= current_thd;
- pthread_cond_t cond;
+ mysql_cond_t cond;
double timeout;
int error;
@@ -3803,13 +3827,13 @@ longlong Item_func_sleep::val_int()
When given a very short timeout (< 10 mcs) just return
immediately.
We assume that the lines between this test and the call
- to pthread_cond_timedwait() will be executed in less than 0.00001 sec.
+ to mysql_cond_timedwait() will be executed in less than 0.00001 sec.
*/
if (timeout < 0.00001)
return 0;
- pthread_cond_init(&cond, NULL);
- pthread_mutex_lock(&LOCK_user_locks);
+ mysql_cond_init(key_item_func_sleep_cond, &cond, NULL);
+ mysql_mutex_lock(&LOCK_user_locks);
thd_proc_info(thd, "User sleep");
thd->mysys_var->current_mutex= &LOCK_user_locks;
@@ -3824,13 +3848,13 @@ longlong Item_func_sleep::val_int()
error= 0;
}
thd_proc_info(thd, 0);
- pthread_mutex_unlock(&LOCK_user_locks);
- pthread_mutex_lock(&thd->mysys_var->mutex);
+ mysql_mutex_unlock(&LOCK_user_locks);
+ mysql_mutex_lock(&thd->mysys_var->mutex);
thd->mysys_var->current_mutex= 0;
thd->mysys_var->current_cond= 0;
- pthread_mutex_unlock(&thd->mysys_var->mutex);
+ mysql_mutex_unlock(&thd->mysys_var->mutex);
- pthread_cond_destroy(&cond);
+ mysql_cond_destroy(&cond);
return test(!error); // Return 1 killed
}
@@ -5758,10 +5782,10 @@ longlong Item_func_is_free_lock::val_int()
return 0;
}
- pthread_mutex_lock(&LOCK_user_locks);
+ mysql_mutex_lock(&LOCK_user_locks);
ull= (User_level_lock *) my_hash_search(&hash_user_locks, (uchar*) res->ptr(),
(size_t) res->length());
- pthread_mutex_unlock(&LOCK_user_locks);
+ mysql_mutex_unlock(&LOCK_user_locks);
if (!ull || !ull->locked)
return 1;
return 0;
@@ -5777,10 +5801,10 @@ longlong Item_func_is_used_lock::val_int()
if (!res || !res->length())
return 0;
- pthread_mutex_lock(&LOCK_user_locks);
+ mysql_mutex_lock(&LOCK_user_locks);
ull= (User_level_lock *) my_hash_search(&hash_user_locks, (uchar*) res->ptr(),
(size_t) res->length());
- pthread_mutex_unlock(&LOCK_user_locks);
+ mysql_mutex_unlock(&LOCK_user_locks);
if (!ull || !ull->locked)
return 0;
diff --git a/sql/lock.cc b/sql/lock.cc
index 56ae94ddc39..e60259f6acc 100644
--- a/sql/lock.cc
+++ b/sql/lock.cc
@@ -1,4 +1,4 @@
-/* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
+/* Copyright 2000-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -978,7 +978,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);
- pthread_mutex_lock(&LOCK_open);
+ mysql_mutex_lock(&LOCK_open);
if ((lock_retcode = lock_table_name(thd, table_list, TRUE)) < 0)
goto end;
if (lock_retcode && wait_for_locked_table_names(thd, table_list))
@@ -989,7 +989,7 @@ int lock_and_wait_for_table_name(THD *thd, TABLE_LIST *table_list)
error=0;
end:
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
start_waiting_global_read_lock(thd);
DBUG_RETURN(error);
}
@@ -1118,7 +1118,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);
+ mysql_mutex_assert_owner(&LOCK_open);
while (locked_named_table(thd,table_list))
{
@@ -1128,7 +1128,7 @@ bool wait_for_locked_table_names(THD *thd, TABLE_LIST *table_list)
break;
}
wait_for_condition(thd, &LOCK_open, &COND_refresh);
- pthread_mutex_lock(&LOCK_open);
+ mysql_mutex_lock(&LOCK_open);
}
DBUG_RETURN(result);
}
@@ -1508,7 +1508,7 @@ bool wait_if_global_read_lock(THD *thd, bool abort_on_refresh,
threads could not close their tables. This would make a pretty
deadlock.
*/
- safe_mutex_assert_not_owner(&LOCK_open);
+ mysql_mutex_assert_not_owner(&LOCK_open);
(void) pthread_mutex_lock(&LOCK_global_read_lock);
if ((need_exit_cond= must_wait))
@@ -1622,7 +1622,7 @@ bool make_global_read_lock_block_commit(THD *thd)
void broadcast_refresh(void)
{
- pthread_cond_broadcast(&COND_refresh);
+ mysql_cond_broadcast(&COND_refresh);
pthread_cond_broadcast(&COND_global_read_lock);
}
diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h
index 4bce96b4be6..3ddaf114673 100644
--- a/sql/mysql_priv.h
+++ b/sql/mysql_priv.h
@@ -1548,8 +1548,8 @@ int setup_conds(THD *thd, TABLE_LIST *tables, TABLE_LIST *leaves,
COND **conds);
int setup_ftfuncs(SELECT_LEX* select);
int init_ftfuncs(THD *thd, SELECT_LEX* select, bool no_order);
-void wait_for_condition(THD *thd, pthread_mutex_t *mutex,
- pthread_cond_t *cond);
+void wait_for_condition(THD *thd, mysql_mutex_t *mutex,
+ mysql_cond_t *cond);
int open_tables(THD *thd, TABLE_LIST **tables, uint *counter, uint flags);
/* open_and_lock_tables with optional derived handling */
int open_and_lock_tables_derived(THD *thd, TABLE_LIST *tables, bool derived);
@@ -2038,13 +2038,15 @@ extern FILE *bootstrap_file;
extern int bootstrap_error;
extern FILE *stderror_file;
extern pthread_key(MEM_ROOT**,THR_MALLOC);
-extern pthread_mutex_t LOCK_mysql_create_db, LOCK_open, LOCK_lock_db,
- LOCK_mapped_file,LOCK_user_locks, LOCK_status,
- LOCK_error_log, LOCK_delayed_insert, LOCK_uuid_generator,
- LOCK_delayed_status, LOCK_delayed_create, LOCK_crypt, LOCK_timezone,
+extern pthread_mutex_t LOCK_mapped_file,
+ LOCK_error_log, LOCK_uuid_generator,
+ LOCK_crypt, LOCK_timezone,
LOCK_slave_list, LOCK_active_mi, LOCK_manager, LOCK_global_read_lock,
LOCK_global_system_variables, LOCK_user_conn,
LOCK_prepared_stmt_count, LOCK_error_messages, LOCK_connection_count;
+extern mysql_mutex_t LOCK_mysql_create_db, LOCK_lock_db, LOCK_open,
+ LOCK_user_locks, LOCK_status, LOCK_delayed_status, LOCK_delayed_insert,
+ LOCK_delayed_create;
extern MYSQL_PLUGIN_IMPORT pthread_mutex_t LOCK_thread_count;
#ifdef HAVE_OPENSSL
extern pthread_mutex_t LOCK_des_key_file;
@@ -2054,7 +2056,8 @@ extern pthread_cond_t COND_server_started;
extern int mysqld_server_started;
extern rw_lock_t LOCK_grant, LOCK_sys_init_connect, LOCK_sys_init_slave;
extern rw_lock_t LOCK_system_variables_hash;
-extern pthread_cond_t COND_refresh, COND_thread_count, COND_manager;
+extern mysql_cond_t COND_refresh;
+extern pthread_cond_t COND_thread_count, COND_manager;
extern pthread_cond_t COND_global_read_lock;
extern pthread_attr_t connection_attrib;
extern I_List<THD> threads;
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index a9eb78b3722..826e8a6c980 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -1,4 +1,4 @@
-/* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
+/* Copyright 2000-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -650,14 +650,16 @@ SHOW_COMP_OPTION have_profiling;
pthread_key(MEM_ROOT**,THR_MALLOC);
pthread_key(THD*, THR_THD);
-pthread_mutex_t LOCK_mysql_create_db, LOCK_open, LOCK_thread_count,
- LOCK_mapped_file, LOCK_status, LOCK_global_read_lock,
+pthread_mutex_t LOCK_thread_count,
+ LOCK_mapped_file, LOCK_global_read_lock,
LOCK_error_log, LOCK_uuid_generator,
- LOCK_delayed_insert, LOCK_delayed_status, LOCK_delayed_create,
LOCK_crypt,
LOCK_global_system_variables,
LOCK_user_conn, LOCK_slave_list, LOCK_active_mi,
LOCK_connection_count, LOCK_error_messages;
+mysql_mutex_t LOCK_open, LOCK_mysql_create_db, LOCK_status, LOCK_delayed_status,
+ LOCK_delayed_insert, LOCK_delayed_create;
+
/**
The below lock protects access to two global server variables:
max_prepared_stmt_count and prepared_stmt_count. These variables
@@ -671,7 +673,8 @@ pthread_mutex_t LOCK_des_key_file;
#endif
rw_lock_t LOCK_grant, LOCK_sys_init_connect, LOCK_sys_init_slave;
rw_lock_t LOCK_system_variables_hash;
-pthread_cond_t COND_refresh, COND_thread_count, COND_global_read_lock;
+mysql_cond_t COND_refresh;
+pthread_cond_t COND_thread_count, COND_global_read_lock;
pthread_t signal_thread;
pthread_attr_t connection_attrib;
pthread_mutex_t LOCK_server_started;
@@ -961,14 +964,14 @@ static void close_connections(void)
if (tmp->mysys_var)
{
tmp->mysys_var->abort=1;
- pthread_mutex_lock(&tmp->mysys_var->mutex);
+ mysql_mutex_lock(&tmp->mysys_var->mutex);
if (tmp->mysys_var->current_cond)
{
- pthread_mutex_lock(tmp->mysys_var->current_mutex);
- pthread_cond_broadcast(tmp->mysys_var->current_cond);
- pthread_mutex_unlock(tmp->mysys_var->current_mutex);
+ mysql_mutex_lock(tmp->mysys_var->current_mutex);
+ mysql_cond_broadcast(tmp->mysys_var->current_cond);
+ mysql_mutex_unlock(tmp->mysys_var->current_mutex);
}
- pthread_mutex_unlock(&tmp->mysys_var->mutex);
+ mysql_mutex_unlock(&tmp->mysys_var->mutex);
}
}
(void) pthread_mutex_unlock(&LOCK_thread_count); // For unlink from list
@@ -1414,17 +1417,17 @@ static void wait_for_signal_thread_to_end()
static void clean_up_mutexes()
{
- (void) pthread_mutex_destroy(&LOCK_mysql_create_db);
- (void) pthread_mutex_destroy(&LOCK_lock_db);
+ mysql_mutex_destroy(&LOCK_mysql_create_db);
+ mysql_mutex_destroy(&LOCK_lock_db);
(void) rwlock_destroy(&LOCK_grant);
- (void) pthread_mutex_destroy(&LOCK_open);
+ mysql_mutex_destroy(&LOCK_open);
(void) pthread_mutex_destroy(&LOCK_thread_count);
(void) pthread_mutex_destroy(&LOCK_mapped_file);
- (void) pthread_mutex_destroy(&LOCK_status);
+ mysql_mutex_destroy(&LOCK_status);
(void) pthread_mutex_destroy(&LOCK_error_log);
- (void) pthread_mutex_destroy(&LOCK_delayed_insert);
- (void) pthread_mutex_destroy(&LOCK_delayed_status);
- (void) pthread_mutex_destroy(&LOCK_delayed_create);
+ mysql_mutex_destroy(&LOCK_delayed_insert);
+ mysql_mutex_destroy(&LOCK_delayed_status);
+ mysql_mutex_destroy(&LOCK_delayed_create);
(void) pthread_mutex_destroy(&LOCK_manager);
(void) pthread_mutex_destroy(&LOCK_crypt);
(void) pthread_mutex_destroy(&LOCK_user_conn);
@@ -1452,7 +1455,7 @@ static void clean_up_mutexes()
(void) pthread_mutex_destroy(&LOCK_prepared_stmt_count);
(void) pthread_mutex_destroy(&LOCK_error_messages);
(void) pthread_cond_destroy(&COND_thread_count);
- (void) pthread_cond_destroy(&COND_refresh);
+ mysql_cond_destroy(&COND_refresh);
(void) pthread_cond_destroy(&COND_global_read_lock);
(void) pthread_cond_destroy(&COND_thread_cache);
(void) pthread_cond_destroy(&COND_flush_thread_cache);
@@ -3596,16 +3599,20 @@ You should consider changing lower_case_table_names to 1 or 2",
static int init_thread_environment()
{
- (void) pthread_mutex_init(&LOCK_mysql_create_db,MY_MUTEX_INIT_SLOW);
- (void) pthread_mutex_init(&LOCK_lock_db,MY_MUTEX_INIT_SLOW);
- (void) pthread_mutex_init(&LOCK_open, MY_MUTEX_INIT_FAST);
+ mysql_mutex_init(key_LOCK_mysql_create_db,
+ &LOCK_mysql_create_db, MY_MUTEX_INIT_SLOW);
+ mysql_mutex_init(key_LOCK_lock_db, &LOCK_lock_db, MY_MUTEX_INIT_SLOW);
+ mysql_mutex_init(key_LOCK_open, &LOCK_open, MY_MUTEX_INIT_FAST);
(void) pthread_mutex_init(&LOCK_thread_count,MY_MUTEX_INIT_FAST);
(void) pthread_mutex_init(&LOCK_mapped_file,MY_MUTEX_INIT_SLOW);
- (void) pthread_mutex_init(&LOCK_status,MY_MUTEX_INIT_FAST);
+ mysql_mutex_init(key_LOCK_status, &LOCK_status, MY_MUTEX_INIT_FAST);
(void) pthread_mutex_init(&LOCK_error_log,MY_MUTEX_INIT_FAST);
- (void) pthread_mutex_init(&LOCK_delayed_insert,MY_MUTEX_INIT_FAST);
- (void) pthread_mutex_init(&LOCK_delayed_status,MY_MUTEX_INIT_FAST);
- (void) pthread_mutex_init(&LOCK_delayed_create,MY_MUTEX_INIT_SLOW);
+ mysql_mutex_init(key_LOCK_deleyed_insert,
+ &LOCK_delayed_insert, MY_MUTEX_INIT_FAST);
+ mysql_mutex_init(key_LOCK_delayed_status,
+ &LOCK_delayed_status, MY_MUTEX_INIT_FAST);
+ mysql_mutex_init(key_LOCK_delayed_create,
+ &LOCK_delayed_create, MY_MUTEX_INIT_SLOW);
(void) pthread_mutex_init(&LOCK_manager,MY_MUTEX_INIT_FAST);
(void) pthread_mutex_init(&LOCK_crypt,MY_MUTEX_INIT_FAST);
(void) pthread_mutex_init(&LOCK_user_conn, MY_MUTEX_INIT_FAST);
@@ -3635,7 +3642,7 @@ static int init_thread_environment()
(void) my_rwlock_init(&LOCK_sys_init_slave, NULL);
(void) my_rwlock_init(&LOCK_grant, NULL);
(void) pthread_cond_init(&COND_thread_count,NULL);
- (void) pthread_cond_init(&COND_refresh,NULL);
+ mysql_cond_init(key_COND_refresh, &COND_refresh, NULL);
(void) pthread_cond_init(&COND_global_read_lock,NULL);
(void) pthread_cond_init(&COND_thread_cache,NULL);
(void) pthread_cond_init(&COND_flush_thread_cache,NULL);
@@ -8936,7 +8943,7 @@ static void create_pid_file()
/** Clear most status variables. */
void refresh_status(THD *thd)
{
- pthread_mutex_lock(&LOCK_status);
+ mysql_mutex_lock(&LOCK_status);
/* Add thread's status variabes to global status */
add_to_status(&global_status_var, &thd->status_var);
@@ -8950,7 +8957,7 @@ void refresh_status(THD *thd)
/* Reset the counters of all key caches (default and named). */
process_key_caches(reset_key_cache_counters);
flush_status_time= time((time_t*) 0);
- pthread_mutex_unlock(&LOCK_status);
+ mysql_mutex_unlock(&LOCK_status);
/*
Set max_used_connections to the number of currently open
diff --git a/sql/replication.h b/sql/replication.h
index eea77ef9f8e..5e9c09adf31 100644
--- a/sql/replication.h
+++ b/sql/replication.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 2008 MySQL AB
+/* Copyright (C) 2008 MySQL AB, 2008-2009 Sun Microsystems, Inc
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -470,8 +470,8 @@ MYSQL *rpl_connect_master(MYSQL *mysql);
held before call this function
@param msg The new process message for the thread
*/
-const char* thd_enter_cond(MYSQL_THD thd, pthread_cond_t *cond,
- pthread_mutex_t *mutex, const char *msg);
+const char* thd_enter_cond(MYSQL_THD thd, mysql_cond_t *cond,
+ mysql_mutex_t *mutex, const char *msg);
/**
Set thread leaving a condition
diff --git a/sql/sp_cache.cc b/sql/sp_cache.cc
index 0da5e44b846..e8604baf466 100644
--- a/sql/sp_cache.cc
+++ b/sql/sp_cache.cc
@@ -1,4 +1,4 @@
-/* Copyright (C) 2002 MySQL AB
+/* Copyright (C) 2002 MySQL AB, 2008-2009 Sun Microsystems, Inc
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -20,7 +20,7 @@
#include "sp_cache.h"
#include "sp_head.h"
-static pthread_mutex_t Cversion_lock;
+static mysql_mutex_t Cversion_lock;
static ulong volatile Cversion= 0;
@@ -81,12 +81,36 @@ private:
HASH m_hashtable;
}; // class sp_cache
+#ifdef HAVE_PSI_INTERFACE
+static PSI_mutex_key key_Cversion_lock;
+
+static PSI_mutex_info all_sp_cache_mutexes[]=
+{
+ { &key_Cversion_lock, "Cversion_lock", PSI_FLAG_GLOBAL}
+};
+
+static void init_sp_cache_psi_keys(void)
+{
+ const char* category= "sql";
+ int count;
+
+ if (PSI_server == NULL)
+ return;
+
+ count= array_elements(all_sp_cache_mutexes);
+ PSI_server->register_mutex(category, all_sp_cache_mutexes, count);
+}
+#endif
/* Initialize the SP caching once at startup */
void sp_cache_init()
{
- pthread_mutex_init(&Cversion_lock, MY_MUTEX_INIT_FAST);
+#ifdef HAVE_PSI_INTERFACE
+ init_sp_cache_psi_keys();
+#endif
+
+ mysql_mutex_init(key_Cversion_lock, &Cversion_lock, MY_MUTEX_INIT_FAST);
}
diff --git a/sql/sql_base.cc b/sql/sql_base.cc
index 2460e018880..9a778e75a11 100644
--- a/sql/sql_base.cc
+++ b/sql/sql_base.cc
@@ -1,4 +1,4 @@
-/* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
+/* Copyright 2000-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -566,7 +566,7 @@ void release_table_share(TABLE_SHARE *share, enum release_type type)
(ulong) share, share->db.str, share->table_name.str,
share->ref_count, share->version));
- safe_mutex_assert_owner(&LOCK_open);
+ mysql_mutex_assert_owner(&LOCK_open);
pthread_mutex_lock(&share->mutex);
if (!--share->ref_count)
@@ -619,7 +619,7 @@ TABLE_SHARE *get_cached_table_share(const char *db, const char *table_name)
char key[NAME_LEN*2+2];
TABLE_LIST table_list;
uint key_length;
- safe_mutex_assert_owner(&LOCK_open);
+ mysql_mutex_assert_owner(&LOCK_open);
table_list.db= (char*) db;
table_list.table_name= (char*) table_name;
@@ -714,7 +714,7 @@ OPEN_TABLE_LIST *list_open_tables(THD *thd, const char *db, const char *wild)
TABLE_LIST table_list;
DBUG_ENTER("list_open_tables");
- pthread_mutex_lock(&LOCK_open);
+ mysql_mutex_lock(&LOCK_open);
bzero((char*) &table_list,sizeof(table_list));
start_list= &open_list;
open_list=0;
@@ -767,7 +767,7 @@ OPEN_TABLE_LIST *list_open_tables(THD *thd, const char *db, const char *wild)
start_list= &(*start_list)->next;
*start_list=0;
}
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
DBUG_RETURN(open_list);
}
@@ -864,7 +864,7 @@ bool close_cached_tables(THD *thd, TABLE_LIST *tables, bool have_lock,
DBUG_ASSERT(thd || (!wait_for_refresh && !tables));
if (!have_lock)
- pthread_mutex_lock(&LOCK_open);
+ mysql_mutex_lock(&LOCK_open);
if (!tables)
{
refresh_version++; // Force close of open tables
@@ -994,7 +994,7 @@ bool close_cached_tables(THD *thd, TABLE_LIST *tables, bool have_lock,
{
found=1;
DBUG_PRINT("signal", ("Waiting for COND_refresh"));
- pthread_cond_wait(&COND_refresh,&LOCK_open);
+ mysql_cond_wait(&COND_refresh, &LOCK_open);
break;
}
}
@@ -1019,14 +1019,14 @@ bool close_cached_tables(THD *thd, TABLE_LIST *tables, bool have_lock,
}
}
if (!have_lock)
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
if (wait_for_refresh)
{
- pthread_mutex_lock(&thd->mysys_var->mutex);
+ mysql_mutex_lock(&thd->mysys_var->mutex);
thd->mysys_var->current_mutex= 0;
thd->mysys_var->current_cond= 0;
thd_proc_info(thd, 0);
- pthread_mutex_unlock(&thd->mysys_var->mutex);
+ mysql_mutex_unlock(&thd->mysys_var->mutex);
}
DBUG_RETURN(result);
}
@@ -1049,7 +1049,7 @@ bool close_cached_connection_tables(THD *thd, bool if_wait_for_refresh,
bzero(&tmp, sizeof(TABLE_LIST));
if (!have_lock)
- pthread_mutex_lock(&LOCK_open);
+ mysql_mutex_lock(&LOCK_open);
for (idx= 0; idx < table_def_cache.records; idx++)
{
@@ -1082,15 +1082,15 @@ bool close_cached_connection_tables(THD *thd, bool if_wait_for_refresh,
result= close_cached_tables(thd, tables, TRUE, FALSE, FALSE);
if (!have_lock)
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
if (if_wait_for_refresh)
{
- pthread_mutex_lock(&thd->mysys_var->mutex);
+ mysql_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);
+ mysql_mutex_unlock(&thd->mysys_var->mutex);
}
DBUG_RETURN(result);
@@ -1197,9 +1197,9 @@ static void close_open_tables(THD *thd)
{
bool found_old_table= 0;
- safe_mutex_assert_not_owner(&LOCK_open);
+ mysql_mutex_assert_not_owner(&LOCK_open);
- pthread_mutex_lock(&LOCK_open);
+ mysql_mutex_lock(&LOCK_open);
DBUG_PRINT("info", ("thd->open_tables: 0x%lx", (long) thd->open_tables));
@@ -1217,7 +1217,7 @@ static void close_open_tables(THD *thd)
broadcast_refresh();
}
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
}
@@ -2098,7 +2098,7 @@ void unlink_open_table(THD *thd, TABLE *find, bool unlock)
TABLE *list, **prev;
DBUG_ENTER("unlink_open_table");
- safe_mutex_assert_owner(&LOCK_open);
+ mysql_mutex_assert_owner(&LOCK_open);
memcpy(key, find->s->table_cache_key.str, key_length);
/*
@@ -2167,14 +2167,14 @@ void drop_open_table(THD *thd, TABLE *table, const char *db_name,
else
{
handlerton *table_type= table->s->db_type();
- pthread_mutex_lock(&LOCK_open);
+ mysql_mutex_lock(&LOCK_open);
/*
unlink_open_table() also tells threads waiting for refresh or close
that something has happened.
*/
unlink_open_table(thd, table, FALSE);
quick_rm_table(table_type, db_name, table_name, 0);
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
}
}
@@ -2190,7 +2190,7 @@ void drop_open_table(THD *thd, TABLE *table, const char *db_name,
cond Condition to wait for
*/
-void wait_for_condition(THD *thd, pthread_mutex_t *mutex, pthread_cond_t *cond)
+void wait_for_condition(THD *thd, mysql_mutex_t *mutex, mysql_cond_t *cond)
{
/* Wait until the current table is up to date */
const char *proc_info;
@@ -2200,7 +2200,7 @@ void wait_for_condition(THD *thd, pthread_mutex_t *mutex, pthread_cond_t *cond)
thd_proc_info(thd, "Waiting for table");
DBUG_ENTER("wait_for_condition");
if (!thd->killed)
- (void) pthread_cond_wait(cond, mutex);
+ mysql_cond_wait(cond, mutex);
/*
We must unlock mutex first to avoid deadlock becasue conditions are
@@ -2213,12 +2213,12 @@ void wait_for_condition(THD *thd, pthread_mutex_t *mutex, pthread_cond_t *cond)
mutex is unlocked
*/
- pthread_mutex_unlock(mutex);
- pthread_mutex_lock(&thd->mysys_var->mutex);
+ mysql_mutex_unlock(mutex);
+ mysql_mutex_lock(&thd->mysys_var->mutex);
thd->mysys_var->current_mutex= 0;
thd->mysys_var->current_cond= 0;
thd_proc_info(thd, proc_info);
- pthread_mutex_unlock(&thd->mysys_var->mutex);
+ mysql_mutex_unlock(&thd->mysys_var->mutex);
DBUG_VOID_RETURN;
}
@@ -2289,7 +2289,7 @@ bool reopen_name_locked_table(THD* thd, TABLE_LIST* table_list, bool link_in)
TABLE orig_table;
DBUG_ENTER("reopen_name_locked_table");
- safe_mutex_assert_owner(&LOCK_open);
+ mysql_mutex_assert_owner(&LOCK_open);
if (thd->killed || !table)
DBUG_RETURN(TRUE);
@@ -2369,7 +2369,7 @@ TABLE *table_cache_insert_placeholder(THD *thd, const char *key,
char *key_buff;
DBUG_ENTER("table_cache_insert_placeholder");
- safe_mutex_assert_owner(&LOCK_open);
+ mysql_mutex_assert_owner(&LOCK_open);
/*
Create a table entry with the right key and with an old refresh version
@@ -2429,24 +2429,24 @@ bool lock_table_name_if_not_cached(THD *thd, const char *db,
DBUG_ENTER("lock_table_name_if_not_cached");
key_length= (uint)(strmov(strmov(key, db) + 1, table_name) - key) + 1;
- pthread_mutex_lock(&LOCK_open);
+ mysql_mutex_lock(&LOCK_open);
if (my_hash_search(&open_cache, (uchar *)key, key_length))
{
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
DBUG_PRINT("info", ("Table is cached, name-lock is not obtained"));
*table= 0;
DBUG_RETURN(FALSE);
}
if (!(*table= table_cache_insert_placeholder(thd, key, key_length)))
{
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
DBUG_RETURN(TRUE);
}
(*table)->open_placeholder= 1;
(*table)->next= thd->open_tables;
thd->open_tables= *table;
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
DBUG_RETURN(FALSE);
}
@@ -2478,7 +2478,7 @@ bool check_if_table_exists(THD *thd, TABLE_LIST *table, bool *exists)
int rc;
DBUG_ENTER("check_if_table_exists");
- safe_mutex_assert_owner(&LOCK_open);
+ mysql_mutex_assert_owner(&LOCK_open);
*exists= TRUE;
@@ -2701,15 +2701,15 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root,
*/
TABLE tab;
table= &tab;
- pthread_mutex_lock(&LOCK_open);
+ mysql_mutex_lock(&LOCK_open);
if (!open_unireg_entry(thd, table, table_list, alias,
key, key_length, mem_root, 0))
{
DBUG_ASSERT(table_list->view != 0);
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
DBUG_RETURN(0); // VIEW
}
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
}
}
/*
@@ -2743,7 +2743,7 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root,
*/
hash_value= my_calc_hash(&open_cache, (uchar*) key, key_length);
- pthread_mutex_lock(&LOCK_open);
+ mysql_mutex_lock(&LOCK_open);
/*
If it's the first table from a list of tables used in a query,
@@ -2761,7 +2761,7 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root,
/* Someone did a refresh while thread was opening tables */
if (refresh)
*refresh=1;
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
DBUG_RETURN(0);
}
@@ -2830,7 +2830,7 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root,
/* Avoid self-deadlocks by detecting self-dependencies. */
if (table->open_placeholder && table->in_use == thd)
{
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
my_error(ER_UPDATE_TABLE_USED, MYF(0), table->s->table_name.str);
DBUG_RETURN(0);
}
@@ -2871,7 +2871,7 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root,
}
else
{
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
}
/*
There is a refresh in progress for this table.
@@ -2912,7 +2912,7 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root,
if (check_if_table_exists(thd, table_list, &exists))
{
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
DBUG_RETURN(NULL);
}
@@ -2923,7 +2923,7 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root,
*/
if (!(table= table_cache_insert_placeholder(thd, key, key_length)))
{
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
DBUG_RETURN(NULL);
}
/*
@@ -2934,7 +2934,7 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root,
table->open_placeholder= 1;
table->next= thd->open_tables;
thd->open_tables= table;
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
DBUG_RETURN(table);
}
/* Table exists. Let us try to open it. */
@@ -2943,7 +2943,7 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root,
/* make a new table */
if (!(table=(TABLE*) my_malloc(sizeof(*table),MYF(MY_WME))))
{
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
DBUG_RETURN(NULL);
}
@@ -2952,7 +2952,7 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root,
if (error > 0)
{
my_free((uchar*)table, MYF(0));
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
DBUG_RETURN(NULL);
}
if (table_list->view || error < 0)
@@ -2965,7 +2965,7 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root,
table_list->view= (LEX*)1;
my_free((uchar*)table, MYF(0));
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
DBUG_RETURN(0); // VIEW
}
DBUG_PRINT("info", ("inserting table '%s'.'%s' 0x%lx into the cache",
@@ -2974,14 +2974,14 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root,
if (my_hash_insert(&open_cache,(uchar*) table))
{
my_free(table, MYF(0));
- (void) pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
DBUG_RETURN(NULL);
}
}
check_unused(); // Debugging call
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
if (refresh)
{
table->next=thd->open_tables; /* Link into simple list */
@@ -3185,7 +3185,7 @@ void close_data_files_and_morph_locks(THD *thd, const char *db,
TABLE *table;
DBUG_ENTER("close_data_files_and_morph_locks");
- safe_mutex_assert_owner(&LOCK_open);
+ mysql_mutex_assert_owner(&LOCK_open);
if (thd->lock)
{
@@ -3324,7 +3324,7 @@ bool reopen_tables(THD *thd, bool get_locks, bool mark_share_as_old)
if (!thd->open_tables)
DBUG_RETURN(0);
- safe_mutex_assert_owner(&LOCK_open);
+ mysql_mutex_assert_owner(&LOCK_open);
if (get_locks)
{
/*
@@ -3587,7 +3587,7 @@ bool wait_for_tables(THD *thd)
DBUG_ENTER("wait_for_tables");
thd_proc_info(thd, "Waiting for tables");
- pthread_mutex_lock(&LOCK_open);
+ mysql_mutex_lock(&LOCK_open);
while (!thd->killed)
{
thd->some_tables_deleted=0;
@@ -3595,7 +3595,7 @@ bool wait_for_tables(THD *thd)
mysql_ha_flush(thd);
if (!table_is_used(thd->open_tables,1))
break;
- (void) pthread_cond_wait(&COND_refresh,&LOCK_open);
+ mysql_cond_wait(&COND_refresh, &LOCK_open);
}
if (thd->killed)
result= 1; // aborted
@@ -3606,7 +3606,7 @@ bool wait_for_tables(THD *thd)
thd->version= refresh_version;
result=reopen_tables(thd,0,0);
}
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
thd_proc_info(thd, 0);
DBUG_RETURN(result);
}
@@ -3759,7 +3759,7 @@ void assign_new_table_id(TABLE_SHARE *share)
/* Preconditions */
DBUG_ASSERT(share != NULL);
- safe_mutex_assert_owner(&LOCK_open);
+ mysql_mutex_assert_owner(&LOCK_open);
ulong tid= ++last_table_id; /* get next id */
/*
@@ -3883,7 +3883,7 @@ static int open_unireg_entry(THD *thd, TABLE *entry, TABLE_LIST *table_list,
uint discover_retry_count= 0;
DBUG_ENTER("open_unireg_entry");
- safe_mutex_assert_owner(&LOCK_open);
+ mysql_mutex_assert_owner(&LOCK_open);
retry:
if (!(share= get_table_share_with_create(thd, table_list, cache_key,
cache_key_length,
@@ -4012,7 +4012,7 @@ retry:
goto err;
}
}
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
thd->clear_error(); // Clear error message
error= 0;
if (open_table_from_share(thd, share, alias,
@@ -4035,7 +4035,7 @@ retry:
}
else
thd->clear_error(); // Clear error message
- pthread_mutex_lock(&LOCK_open);
+ mysql_mutex_lock(&LOCK_open);
unlock_table_name(thd, table_list);
if (error)
@@ -8440,10 +8440,10 @@ void remove_db_from_cache(const char *db)
void flush_tables()
{
- (void) pthread_mutex_lock(&LOCK_open);
+ mysql_mutex_lock(&LOCK_open);
while (unused_tables)
my_hash_delete(&open_cache,(uchar*) unused_tables);
- (void) pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
}
@@ -8514,15 +8514,15 @@ bool remove_table_from_cache(THD *thd, const char *db, const char *table_name,
! in_use->killed)
{
in_use->killed= THD::KILL_CONNECTION;
- pthread_mutex_lock(&in_use->mysys_var->mutex);
+ mysql_mutex_lock(&in_use->mysys_var->mutex);
if (in_use->mysys_var->current_cond)
{
- pthread_mutex_lock(in_use->mysys_var->current_mutex);
+ mysql_mutex_lock(in_use->mysys_var->current_mutex);
signalled= 1;
- pthread_cond_broadcast(in_use->mysys_var->current_cond);
- pthread_mutex_unlock(in_use->mysys_var->current_mutex);
+ mysql_cond_broadcast(in_use->mysys_var->current_cond);
+ mysql_mutex_unlock(in_use->mysys_var->current_mutex);
}
- pthread_mutex_unlock(&in_use->mysys_var->mutex);
+ mysql_mutex_unlock(&in_use->mysys_var->mutex);
}
/*
Now we must abort all tables locks used by this thread
@@ -8579,7 +8579,7 @@ bool remove_table_from_cache(THD *thd, const char *db, const char *table_name,
{
dropping_tables++;
if (likely(signalled))
- (void) pthread_cond_wait(&COND_refresh, &LOCK_open);
+ mysql_cond_wait(&COND_refresh, &LOCK_open);
else
{
struct timespec abstime;
@@ -8594,7 +8594,7 @@ bool remove_table_from_cache(THD *thd, const char *db, const char *table_name,
remove_table_from_cache routine.
*/
set_timespec(abstime, 10);
- pthread_cond_timedwait(&COND_refresh, &LOCK_open, &abstime);
+ mysql_cond_timedwait(&COND_refresh, &LOCK_open, &abstime);
}
dropping_tables--;
continue;
@@ -8740,12 +8740,12 @@ int abort_and_upgrade_lock(ALTER_PARTITION_PARAM_TYPE *lpt)
DBUG_ENTER("abort_and_upgrade_locks");
lpt->old_lock_type= lpt->table->reginfo.lock_type;
- pthread_mutex_lock(&LOCK_open);
+ mysql_mutex_lock(&LOCK_open);
/* If MERGE child, forward lock handling to parent. */
mysql_lock_abort(lpt->thd, lpt->table->parent ? lpt->table->parent :
lpt->table, TRUE);
(void) remove_table_from_cache(lpt->thd, lpt->db, lpt->table_name, flags);
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
DBUG_RETURN(0);
}
@@ -8767,10 +8767,10 @@ int abort_and_upgrade_lock(ALTER_PARTITION_PARAM_TYPE *lpt)
/* purecov: begin deadcode */
void close_open_tables_and_downgrade(ALTER_PARTITION_PARAM_TYPE *lpt)
{
- pthread_mutex_lock(&LOCK_open);
+ mysql_mutex_lock(&LOCK_open);
remove_table_from_cache(lpt->thd, lpt->db, lpt->table_name,
RTFC_WAIT_OTHER_THREAD_FLAG);
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
/* If MERGE child, forward lock handling to parent. */
mysql_lock_downgrade_write(lpt->thd, lpt->table->parent ? lpt->table->parent :
lpt->table, lpt->old_lock_type);
@@ -8809,7 +8809,7 @@ void mysql_wait_completed_table(ALTER_PARTITION_PARAM_TYPE *lpt, TABLE *my_table
DBUG_ENTER("mysql_wait_completed_table");
key_length=(uint) (strmov(strmov(key,lpt->db)+1,lpt->table_name)-key)+1;
- pthread_mutex_lock(&LOCK_open);
+ mysql_mutex_lock(&LOCK_open);
HASH_SEARCH_STATE state;
for (table= (TABLE*) my_hash_first(&open_cache,(uchar*) key,key_length,
&state) ;
@@ -8830,14 +8830,14 @@ void mysql_wait_completed_table(ALTER_PARTITION_PARAM_TYPE *lpt, TABLE *my_table
! in_use->killed)
{
in_use->killed= THD::KILL_CONNECTION;
- pthread_mutex_lock(&in_use->mysys_var->mutex);
+ mysql_mutex_lock(&in_use->mysys_var->mutex);
if (in_use->mysys_var->current_cond)
{
- pthread_mutex_lock(in_use->mysys_var->current_mutex);
- pthread_cond_broadcast(in_use->mysys_var->current_cond);
- pthread_mutex_unlock(in_use->mysys_var->current_mutex);
+ mysql_mutex_lock(in_use->mysys_var->current_mutex);
+ mysql_cond_broadcast(in_use->mysys_var->current_cond);
+ mysql_mutex_unlock(in_use->mysys_var->current_mutex);
}
- pthread_mutex_unlock(&in_use->mysys_var->mutex);
+ mysql_mutex_unlock(&in_use->mysys_var->mutex);
}
/*
Now we must abort all tables locks used by this thread
@@ -8867,7 +8867,7 @@ void mysql_wait_completed_table(ALTER_PARTITION_PARAM_TYPE *lpt, TABLE *my_table
*/
mysql_lock_abort(lpt->thd, my_table->parent ? my_table->parent : my_table,
FALSE);
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
DBUG_VOID_RETURN;
}
@@ -9106,7 +9106,7 @@ void close_performance_schema_table(THD *thd, Open_tables_state *backup)
mysql_unlock_tables(thd, thd->lock);
thd->lock= 0;
- pthread_mutex_lock(&LOCK_open);
+ mysql_mutex_lock(&LOCK_open);
found_old_table= false;
/*
@@ -9122,7 +9122,7 @@ void close_performance_schema_table(THD *thd, Open_tables_state *backup)
if (found_old_table)
broadcast_refresh();
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
thd->restore_backup_open_tables_state(backup);
}
diff --git a/sql/sql_class.cc b/sql/sql_class.cc
index ff573c67627..019c22d9dd2 100644
--- a/sql/sql_class.cc
+++ b/sql/sql_class.cc
@@ -962,9 +962,9 @@ void THD::init_for_queries()
void THD::change_user(void)
{
- pthread_mutex_lock(&LOCK_status);
+ mysql_mutex_lock(&LOCK_status);
add_to_status(&global_status_var, &status_var);
- pthread_mutex_unlock(&LOCK_status);
+ mysql_mutex_unlock(&LOCK_status);
cleanup();
killed= NOT_KILLED;
@@ -1023,9 +1023,9 @@ void THD::cleanup(void)
unlock_global_read_lock(this);
if (ull)
{
- pthread_mutex_lock(&LOCK_user_locks);
+ mysql_mutex_lock(&LOCK_user_locks);
item_user_lock_release(ull);
- pthread_mutex_unlock(&LOCK_user_locks);
+ mysql_mutex_unlock(&LOCK_user_locks);
ull= NULL;
}
@@ -1164,7 +1164,7 @@ void THD::awake(THD::killed_state state_to_set)
}
if (mysys_var)
{
- pthread_mutex_lock(&mysys_var->mutex);
+ mysql_mutex_lock(&mysys_var->mutex);
if (!system_thread) // Don't abort locks
mysys_var->abort=1;
/*
@@ -1188,11 +1188,11 @@ void THD::awake(THD::killed_state state_to_set)
*/
if (mysys_var->current_cond && mysys_var->current_mutex)
{
- pthread_mutex_lock(mysys_var->current_mutex);
- pthread_cond_broadcast(mysys_var->current_cond);
- pthread_mutex_unlock(mysys_var->current_mutex);
+ mysql_mutex_lock(mysys_var->current_mutex);
+ mysql_cond_broadcast(mysys_var->current_cond);
+ mysql_mutex_unlock(mysys_var->current_mutex);
}
- pthread_mutex_unlock(&mysys_var->mutex);
+ mysql_mutex_unlock(&mysys_var->mutex);
}
DBUG_VOID_RETURN;
}
diff --git a/sql/sql_class.h b/sql/sql_class.h
index d946b9610fa..d3e3f2a48b6 100644
--- a/sql/sql_class.h
+++ b/sql/sql_class.h
@@ -1876,21 +1876,21 @@ public:
enter_cond(); this mutex is then released by exit_cond().
Usage must be: lock mutex; enter_cond(); your code; exit_cond().
*/
- inline const char* enter_cond(pthread_cond_t *cond, pthread_mutex_t* mutex,
- const char* msg)
+ inline const char* enter_cond(mysql_cond_t *cond, mysql_mutex_t* mutex,
+ const char* msg)
{
const char* old_msg = proc_info;
- safe_mutex_assert_owner(mutex);
+ mysql_mutex_assert_owner(mutex);
mysys_var->current_mutex = mutex;
mysys_var->current_cond = cond;
proc_info = msg;
return old_msg;
}
- inline const char* enter_cond(mysql_cond_t *cond, mysql_mutex_t *mutex,
+ inline const char* enter_cond(pthread_cond_t *cond, pthread_mutex_t *mutex,
const char *msg)
{
/* TO BE REMOVED: temporary helper, to help with merges */
- return enter_cond(&cond->m_cond, &mutex->m_mutex, msg);
+ return enter_cond((mysql_cond_t*) cond, (mysql_mutex_t*) mutex, msg);
}
inline void exit_cond(const char* old_msg)
{
@@ -1900,12 +1900,12 @@ public:
locked (if that would not be the case, you'll get a deadlock if someone
does a THD::awake() on you).
*/
- pthread_mutex_unlock(mysys_var->current_mutex);
- pthread_mutex_lock(&mysys_var->mutex);
+ mysql_mutex_unlock(mysys_var->current_mutex);
+ mysql_mutex_lock(&mysys_var->mutex);
mysys_var->current_mutex = 0;
mysys_var->current_cond = 0;
proc_info = old_msg;
- pthread_mutex_unlock(&mysys_var->mutex);
+ mysql_mutex_unlock(&mysys_var->mutex);
return;
}
inline time_t query_start() { query_start_used=1; return start_time; }
diff --git a/sql/sql_db.cc b/sql/sql_db.cc
index 2ae876985b7..aa124a0a004 100644
--- a/sql/sql_db.cc
+++ b/sql/sql_db.cc
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2003 MySQL AB
+/* Copyright (C) 2000-2003 MySQL AB, 2008-2009 Sun Microsystems, Inc
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -47,7 +47,7 @@ static void mysql_change_db_impl(THD *thd,
/* Database lock hash */
HASH lock_db_cache;
-pthread_mutex_t LOCK_lock_db;
+mysql_mutex_t LOCK_lock_db;
int creating_database= 0; // how many database locks are made
@@ -103,7 +103,7 @@ static my_bool lock_db_insert(const char *dbname, uint length)
my_bool error= 0;
DBUG_ENTER("lock_db_insert");
- safe_mutex_assert_owner(&LOCK_lock_db);
+ mysql_mutex_assert_owner(&LOCK_lock_db);
if (!(opt= (my_dblock_t*) my_hash_search(&lock_db_cache,
(uchar*) dbname, length)))
@@ -138,7 +138,7 @@ end:
void lock_db_delete(const char *name, uint length)
{
my_dblock_t *opt;
- safe_mutex_assert_owner(&LOCK_lock_db);
+ mysql_mutex_assert_owner(&LOCK_lock_db);
if ((opt= (my_dblock_t *)my_hash_search(&lock_db_cache,
(const uchar*) name, length)))
my_hash_delete(&lock_db_cache, (uchar*) opt);
@@ -148,7 +148,7 @@ void lock_db_delete(const char *name, uint length)
/* Database options hash */
static HASH dboptions;
static my_bool dboptions_init= 0;
-static rw_lock_t LOCK_dboptions;
+static mysql_rwlock_t LOCK_dboptions;
/* Structure for database options */
typedef struct my_dbopt_st
@@ -199,6 +199,26 @@ void free_dbopt(void *dbopt)
my_free((uchar*) dbopt, MYF(0));
}
+#ifdef HAVE_PSI_INTERFACE
+static PSI_rwlock_key key_rwlock_LOCK_dboptions;
+
+static PSI_rwlock_info all_database_names_rwlocks[]=
+{
+ { &key_rwlock_LOCK_dboptions, "LOCK_dboptions", PSI_FLAG_GLOBAL}
+};
+
+static void init_database_names_psi_keys(void)
+{
+ const char* category= "sql";
+ int count;
+
+ if (PSI_server == NULL)
+ return;
+
+ count= array_elements(all_database_names_rwlocks);
+ PSI_server->register_rwlock(category, all_database_names_rwlocks, count);
+}
+#endif
/*
Initialize database option hash and locked database hash.
@@ -216,8 +236,12 @@ void free_dbopt(void *dbopt)
bool my_database_names_init(void)
{
+#ifdef HAVE_PSI_INTERFACE
+ init_database_names_psi_keys();
+#endif
+
bool error= 0;
- (void) my_rwlock_init(&LOCK_dboptions, NULL);
+ mysql_rwlock_init(key_rwlock_LOCK_dboptions, &LOCK_dboptions);
if (!dboptions_init)
{
dboptions_init= 1;
@@ -246,7 +270,7 @@ void my_database_names_free(void)
{
dboptions_init= 0;
my_hash_free(&dboptions);
- (void) rwlock_destroy(&LOCK_dboptions);
+ mysql_rwlock_destroy(&LOCK_dboptions);
my_hash_free(&lock_db_cache);
}
}
@@ -258,13 +282,13 @@ void my_database_names_free(void)
void my_dbopt_cleanup(void)
{
- rw_wrlock(&LOCK_dboptions);
+ mysql_rwlock_wrlock(&LOCK_dboptions);
my_hash_free(&dboptions);
my_hash_init(&dboptions, lower_case_table_names ?
&my_charset_bin : system_charset_info,
32, 0, 0, (my_hash_get_key) dboptions_get_key,
free_dbopt,0);
- rw_unlock(&LOCK_dboptions);
+ mysql_rwlock_unlock(&LOCK_dboptions);
}
@@ -288,13 +312,13 @@ static my_bool get_dbopt(const char *dbname, HA_CREATE_INFO *create)
length= (uint) strlen(dbname);
- rw_rdlock(&LOCK_dboptions);
+ mysql_rwlock_rdlock(&LOCK_dboptions);
if ((opt= (my_dbopt_t*) my_hash_search(&dboptions, (uchar*) dbname, length)))
{
create->default_table_charset= opt->charset;
error= 0;
}
- rw_unlock(&LOCK_dboptions);
+ mysql_rwlock_unlock(&LOCK_dboptions);
return error;
}
@@ -320,7 +344,7 @@ static my_bool put_dbopt(const char *dbname, HA_CREATE_INFO *create)
length= (uint) strlen(dbname);
- rw_wrlock(&LOCK_dboptions);
+ mysql_rwlock_wrlock(&LOCK_dboptions);
if (!(opt= (my_dbopt_t*) my_hash_search(&dboptions, (uchar*) dbname,
length)))
{
@@ -349,7 +373,7 @@ static my_bool put_dbopt(const char *dbname, HA_CREATE_INFO *create)
opt->charset= create->default_table_charset;
end:
- rw_unlock(&LOCK_dboptions);
+ mysql_rwlock_unlock(&LOCK_dboptions);
DBUG_RETURN(error);
}
@@ -361,11 +385,11 @@ end:
void del_dbopt(const char *path)
{
my_dbopt_t *opt;
- rw_wrlock(&LOCK_dboptions);
+ mysql_rwlock_wrlock(&LOCK_dboptions);
if ((opt= (my_dbopt_t *)my_hash_search(&dboptions, (const uchar*) path,
strlen(path))))
my_hash_delete(&dboptions, (uchar*) opt);
- rw_unlock(&LOCK_dboptions);
+ mysql_rwlock_unlock(&LOCK_dboptions);
}
@@ -392,7 +416,8 @@ static bool write_db_opt(THD *thd, const char *path, HA_CREATE_INFO *create)
if (put_dbopt(path, create))
return 1;
- if ((file=my_create(path, CREATE_MODE,O_RDWR | O_TRUNC,MYF(MY_WME))) >= 0)
+ if ((file= mysql_file_create(key_file_dbopt, path, CREATE_MODE,
+ O_RDWR | O_TRUNC, MYF(MY_WME))) >= 0)
{
ulong length;
length= (ulong) (strxnmov(buf, sizeof(buf)-1, "default-character-set=",
@@ -401,10 +426,10 @@ static bool write_db_opt(THD *thd, const char *path, HA_CREATE_INFO *create)
create->default_table_charset->name,
"\n", NullS) - buf);
- /* Error is written by my_write */
- if (!my_write(file,(uchar*) buf, length, MYF(MY_NABP+MY_WME)))
+ /* Error is written by mysql_file_write */
+ if (!mysql_file_write(file, (uchar*) buf, length, MYF(MY_NABP+MY_WME)))
error=0;
- my_close(file,MYF(0));
+ mysql_file_close(file, MYF(0));
}
return error;
}
@@ -441,7 +466,8 @@ bool load_db_opt(THD *thd, const char *path, HA_CREATE_INFO *create)
DBUG_RETURN(0);
/* Otherwise, load options from the .opt file */
- if ((file=my_open(path, O_RDONLY | O_SHARE, MYF(0))) < 0)
+ if ((file= mysql_file_open(key_file_dbopt,
+ path, O_RDONLY | O_SHARE, MYF(0))) < 0)
goto err1;
IO_CACHE cache;
@@ -499,7 +525,7 @@ bool load_db_opt(THD *thd, const char *path, HA_CREATE_INFO *create)
end_io_cache(&cache);
err2:
- my_close(file,MYF(0));
+ mysql_file_close(file, MYF(0));
err1:
DBUG_RETURN(error);
}
@@ -643,13 +669,13 @@ int mysql_create_db(THD *thd, char *db, HA_CREATE_INFO *create_info,
goto exit2;
}
- pthread_mutex_lock(&LOCK_mysql_create_db);
+ mysql_mutex_lock(&LOCK_mysql_create_db);
/* Check directory */
path_len= build_table_filename(path, sizeof(path) - 1, db, "", "", 0);
path[path_len-1]= 0; // Remove last '/' from path
- if (my_stat(path,&stat_info,MYF(0)))
+ if (mysql_file_stat(key_file_misc, path, &stat_info, MYF(0)))
{
if (!(create_options & HA_LEX_CREATE_IF_NOT_EXISTS))
{
@@ -758,7 +784,7 @@ not_silent:
}
exit:
- pthread_mutex_unlock(&LOCK_mysql_create_db);
+ mysql_mutex_unlock(&LOCK_mysql_create_db);
start_waiting_global_read_lock(thd);
exit2:
DBUG_RETURN(error);
@@ -789,7 +815,7 @@ bool mysql_alter_db(THD *thd, const char *db, HA_CREATE_INFO *create_info)
if ((error=wait_if_global_read_lock(thd,0,1)))
goto exit2;
- pthread_mutex_lock(&LOCK_mysql_create_db);
+ mysql_mutex_lock(&LOCK_mysql_create_db);
/*
Recreate db options file: /dbpath/.db.opt
@@ -835,7 +861,7 @@ bool mysql_alter_db(THD *thd, const char *db, HA_CREATE_INFO *create_info)
my_ok(thd, result);
exit:
- pthread_mutex_unlock(&LOCK_mysql_create_db);
+ mysql_mutex_unlock(&LOCK_mysql_create_db);
start_waiting_global_read_lock(thd);
exit2:
DBUG_RETURN(error);
@@ -887,7 +913,7 @@ bool mysql_rm_db(THD *thd,char *db,bool if_exists, bool silent)
goto exit2;
}
- pthread_mutex_lock(&LOCK_mysql_create_db);
+ mysql_mutex_lock(&LOCK_mysql_create_db);
length= build_table_filename(path, sizeof(path) - 1, db, "", "", 0);
strmov(path+length, MY_DB_OPT_FILE); // Append db option file name
@@ -909,9 +935,9 @@ bool mysql_rm_db(THD *thd,char *db,bool if_exists, bool silent)
}
else
{
- pthread_mutex_lock(&LOCK_open);
+ mysql_mutex_lock(&LOCK_open);
remove_db_from_cache(db);
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
Drop_table_error_handler err_handler(thd->get_internal_handler());
thd->push_internal_handler(&err_handler);
@@ -1046,7 +1072,7 @@ exit:
*/
if (thd->db && !strcmp(thd->db, db) && error == 0)
mysql_change_db_impl(thd, NULL, 0, thd->variables.collation_server);
- pthread_mutex_unlock(&LOCK_mysql_create_db);
+ mysql_mutex_unlock(&LOCK_mysql_create_db);
start_waiting_global_read_lock(thd);
exit2:
DBUG_RETURN(error);
@@ -1172,7 +1198,7 @@ static long mysql_rm_known_files(THD *thd, MY_DIR *dirp, const char *db,
else
{
strxmov(filePath, org_path, "/", file->name, NullS);
- if (my_delete_with_symlink(filePath,MYF(MY_WME)))
+ if (mysql_file_delete_with_symlink(key_file_misc, filePath, MYF(MY_WME)))
{
goto err;
}
@@ -1250,7 +1276,7 @@ static my_bool rm_dir_w_symlink(const char *org_path, my_bool send_error)
DBUG_RETURN(1);
if (!error)
{
- if (my_delete(path, MYF(send_error ? MY_WME : 0)))
+ if (mysql_file_delete(key_file_misc, path, MYF(send_error ? MY_WME : 0)))
{
DBUG_RETURN(send_error);
}
@@ -1327,7 +1353,7 @@ long mysql_rm_arc_files(THD *thd, MY_DIR *dirp, const char *org_path)
continue;
}
strxmov(filePath, org_path, "/", file->name, NullS);
- if (my_delete_with_symlink(filePath,MYF(MY_WME)))
+ if (mysql_file_delete_with_symlink(key_file_misc, filePath, MYF(MY_WME)))
{
goto err;
}
@@ -1734,18 +1760,18 @@ static int
lock_databases(THD *thd, const char *db1, uint length1,
const char *db2, uint length2)
{
- pthread_mutex_lock(&LOCK_lock_db);
+ mysql_mutex_lock(&LOCK_lock_db);
while (!thd->killed &&
(my_hash_search(&lock_db_cache,(uchar*) db1, length1) ||
my_hash_search(&lock_db_cache,(uchar*) db2, length2)))
{
wait_for_condition(thd, &LOCK_lock_db, &COND_refresh);
- pthread_mutex_lock(&LOCK_lock_db);
+ mysql_mutex_lock(&LOCK_lock_db);
}
if (thd->killed)
{
- pthread_mutex_unlock(&LOCK_lock_db);
+ mysql_mutex_unlock(&LOCK_lock_db);
return 1;
}
@@ -1762,7 +1788,7 @@ lock_databases(THD *thd, const char *db1, uint length1,
while (!thd->killed && creating_table)
{
wait_for_condition(thd, &LOCK_lock_db, &COND_refresh);
- pthread_mutex_lock(&LOCK_lock_db);
+ mysql_mutex_lock(&LOCK_lock_db);
}
if (thd->killed)
@@ -1770,8 +1796,8 @@ lock_databases(THD *thd, const char *db1, uint length1,
lock_db_delete(db1, length1);
lock_db_delete(db2, length2);
creating_database--;
- pthread_mutex_unlock(&LOCK_lock_db);
- pthread_cond_signal(&COND_refresh);
+ mysql_mutex_unlock(&LOCK_lock_db);
+ mysql_cond_signal(&COND_refresh);
return(1);
}
@@ -1779,7 +1805,7 @@ lock_databases(THD *thd, const char *db1, uint length1,
We can unlock now as the hash will protect against anyone creating a table
in the databases we are using
*/
- pthread_mutex_unlock(&LOCK_lock_db);
+ mysql_mutex_unlock(&LOCK_lock_db);
return 0;
}
@@ -1908,7 +1934,7 @@ bool mysql_upgrade_db(THD *thd, LEX_STRING *old_db)
*/
build_table_filename(path, sizeof(path)-1,
new_db.str,"",MY_DB_OPT_FILE, 0);
- my_delete(path, MYF(MY_WME));
+ mysql_file_delete(key_file_dbopt, path, MYF(MY_WME));
length= build_table_filename(path, sizeof(path)-1, new_db.str, "", "", 0);
if (length && path[length-1] == FN_LIBCHAR)
path[length-1]=0; // remove ending '\'
@@ -1964,7 +1990,7 @@ bool mysql_upgrade_db(THD *thd, LEX_STRING *old_db)
old_db->str, "", file->name, 0);
build_table_filename(newname, sizeof(newname)-1,
new_db.str, "", file->name, 0);
- my_rename(oldname, newname, MYF(MY_WME));
+ mysql_file_rename(key_file_misc, oldname, newname, MYF(MY_WME));
}
my_dirend(dirp);
}
@@ -1992,14 +2018,14 @@ bool mysql_upgrade_db(THD *thd, LEX_STRING *old_db)
error|= mysql_change_db(thd, & new_db, FALSE);
exit:
- pthread_mutex_lock(&LOCK_lock_db);
+ mysql_mutex_lock(&LOCK_lock_db);
/* Remove the databases from db lock cache */
lock_db_delete(old_db->str, old_db->length);
lock_db_delete(new_db.str, new_db.length);
creating_database--;
/* Signal waiting CREATE TABLE's to continue */
- pthread_cond_signal(&COND_refresh);
- pthread_mutex_unlock(&LOCK_lock_db);
+ mysql_cond_signal(&COND_refresh);
+ mysql_mutex_unlock(&LOCK_lock_db);
DBUG_RETURN(error);
}
diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc
index c59e7dd5873..ab898950a1d 100644
--- a/sql/sql_delete.cc
+++ b/sql/sql_delete.cc
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000 MySQL AB
+/* Copyright (C) 2000 MySQL AB, 2008-2009 Sun Microsystems, Inc
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -1170,10 +1170,10 @@ bool mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok)
// crashes, replacement works. *(path + path_length - reg_ext_length)=
// '\0';
path[path_length - reg_ext_length] = 0;
- pthread_mutex_lock(&LOCK_open);
+ mysql_mutex_lock(&LOCK_open);
error= ha_create_table(thd, path, table_list->db, table_list->table_name,
&create_info, 1);
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
query_cache_invalidate3(thd, table_list, 0);
end:
@@ -1187,15 +1187,15 @@ end:
if (!error)
my_ok(thd); // This should return record count
}
- pthread_mutex_lock(&LOCK_open);
+ mysql_mutex_lock(&LOCK_open);
unlock_table_name(thd, table_list);
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
}
else if (error)
{
- pthread_mutex_lock(&LOCK_open);
+ mysql_mutex_lock(&LOCK_open);
unlock_table_name(thd, table_list);
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
}
DBUG_RETURN(error);
diff --git a/sql/sql_handler.cc b/sql/sql_handler.cc
index da5ee93fcb9..5b45c35dd22 100644
--- a/sql/sql_handler.cc
+++ b/sql/sql_handler.cc
@@ -1,4 +1,5 @@
-/* Copyright (C) 2000-2004 MySQL AB
+/* Copyright (C) 2000-2004 MySQL AB, 2008-2009 Sun Microsystems, Inc
+
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
@@ -143,14 +144,14 @@ static void mysql_ha_close_table(THD *thd, TABLE_LIST *tables,
{
(*table_ptr)->file->ha_index_or_rnd_end();
if (! is_locked)
- pthread_mutex_lock(&LOCK_open);
+ mysql_mutex_lock(&LOCK_open);
if (close_thread_table(thd, table_ptr))
{
/* Tell threads waiting for refresh that something has happened */
broadcast_refresh();
}
if (! is_locked)
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
}
else if (tables->table)
{
@@ -775,7 +776,7 @@ void mysql_ha_flush(THD *thd)
TABLE_LIST *hash_tables;
DBUG_ENTER("mysql_ha_flush");
- safe_mutex_assert_owner(&LOCK_open);
+ mysql_mutex_assert_owner(&LOCK_open);
for (uint i= 0; i < thd->handler_tables_hash.records; i++)
{
diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc
index 93f04a9199d..147e03ddf55 100644
--- a/sql/sql_insert.cc
+++ b/sql/sql_insert.cc
@@ -1,4 +1,4 @@
-/* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
+/* Copyright 2000-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -913,7 +913,7 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list,
thd->net.last_error/errno. For example if there has
been a disk full error when writing the row, and it was
MyISAM, then thd->net.last_error/errno will be set to
- "disk full"... and the my_pwrite() will wait until free
+ "disk full"... and the mysql_file_pwrite() will wait until free
space appears, and so when it finishes then the
write_row() was entirely successful
*/
@@ -1772,8 +1772,8 @@ class Delayed_insert :public ilink {
public:
THD thd;
TABLE *table;
- pthread_mutex_t mutex;
- pthread_cond_t cond,cond_client;
+ mysql_mutex_t mutex;
+ mysql_cond_t cond, cond_client;
volatile uint tables_in_use,stacked_inserts;
volatile bool status,dead;
COPY_INFO info;
@@ -1805,9 +1805,9 @@ public:
thd.system_thread= SYSTEM_THREAD_DELAYED_INSERT;
thd.security_ctx->host_or_ip= "";
bzero((char*) &info,sizeof(info));
- pthread_mutex_init(&mutex,MY_MUTEX_INIT_FAST);
- pthread_cond_init(&cond,NULL);
- pthread_cond_init(&cond_client,NULL);
+ mysql_mutex_init(key_delayed_insert_mutex, &mutex, MY_MUTEX_INIT_FAST);
+ mysql_cond_init(key_delayed_insert_cond, &cond, NULL);
+ mysql_cond_init(key_delayed_insert_cond_client, &cond_client, NULL);
pthread_mutex_lock(&LOCK_thread_count);
delayed_insert_threads++;
delayed_lock= global_system_variables.low_priority_updates ?
@@ -1823,9 +1823,9 @@ public:
if (table)
close_thread_tables(&thd);
pthread_mutex_lock(&LOCK_thread_count);
- pthread_mutex_destroy(&mutex);
- pthread_cond_destroy(&cond);
- pthread_cond_destroy(&cond_client);
+ mysql_mutex_destroy(&mutex);
+ mysql_cond_destroy(&cond);
+ mysql_cond_destroy(&cond_client);
thd.unlink(); // Must be unlinked under lock
x_free(thd.query());
thd.security_ctx->user= thd.security_ctx->host=0;
@@ -1842,18 +1842,18 @@ public:
}
void unlock()
{
- pthread_mutex_lock(&LOCK_delayed_insert);
+ mysql_mutex_lock(&LOCK_delayed_insert);
if (!--locks_in_memory)
{
- pthread_mutex_lock(&mutex);
+ mysql_mutex_lock(&mutex);
if (thd.killed && ! stacked_inserts && ! tables_in_use)
{
- pthread_cond_signal(&cond);
+ mysql_cond_signal(&cond);
status=1;
}
- pthread_mutex_unlock(&mutex);
+ mysql_mutex_unlock(&mutex);
}
- pthread_mutex_unlock(&LOCK_delayed_insert);
+ mysql_mutex_unlock(&LOCK_delayed_insert);
}
inline uint lock_count() { return locks_in_memory; }
@@ -1874,7 +1874,7 @@ static
Delayed_insert *find_handler(THD *thd, TABLE_LIST *table_list)
{
thd_proc_info(thd, "waiting for delay_list");
- pthread_mutex_lock(&LOCK_delayed_insert); // Protect master list
+ mysql_mutex_lock(&LOCK_delayed_insert); // Protect master list
I_List_iterator<Delayed_insert> it(delayed_threads);
Delayed_insert *di;
while ((di= it++))
@@ -1886,7 +1886,7 @@ Delayed_insert *find_handler(THD *thd, TABLE_LIST *table_list)
break;
}
}
- pthread_mutex_unlock(&LOCK_delayed_insert); // For unlink from list
+ mysql_mutex_unlock(&LOCK_delayed_insert); // For unlink from list
return di;
}
@@ -1956,7 +1956,7 @@ bool delayed_get_table(THD *thd, TABLE_LIST *table_list)
if (delayed_insert_threads >= thd->variables.max_insert_delayed_threads)
DBUG_RETURN(0);
thd_proc_info(thd, "Creating delayed handler");
- pthread_mutex_lock(&LOCK_delayed_create);
+ mysql_mutex_lock(&LOCK_delayed_create);
/*
The first search above was done without LOCK_delayed_create.
Another thread might have created the handler in between. Search again.
@@ -1982,14 +1982,15 @@ bool delayed_get_table(THD *thd, TABLE_LIST *table_list)
di->table_list.alias= di->table_list.table_name= di->thd.query();
di->table_list.db= di->thd.db;
di->lock();
- pthread_mutex_lock(&di->mutex);
- if ((error= pthread_create(&di->thd.real_id, &connection_attrib,
- handle_delayed_insert, (void*) di)))
+ mysql_mutex_lock(&di->mutex);
+ if ((error= mysql_thread_create(key_thread_delayed_insert,
+ &di->thd.real_id, &connection_attrib,
+ handle_delayed_insert, (void*) di)))
{
DBUG_PRINT("error",
("Can't create thread to handle delayed insert (error %d)",
error));
- pthread_mutex_unlock(&di->mutex);
+ mysql_mutex_unlock(&di->mutex);
di->unlock();
delete di;
my_error(ER_CANT_CREATE_THREAD, MYF(ME_FATALERROR), error);
@@ -2000,9 +2001,9 @@ bool delayed_get_table(THD *thd, TABLE_LIST *table_list)
thd_proc_info(thd, "waiting for handler open");
while (!di->thd.killed && !di->table && !thd->killed)
{
- pthread_cond_wait(&di->cond_client, &di->mutex);
+ mysql_cond_wait(&di->cond_client, &di->mutex);
}
- pthread_mutex_unlock(&di->mutex);
+ mysql_mutex_unlock(&di->mutex);
thd_proc_info(thd, "got old table");
if (di->thd.killed)
{
@@ -2025,16 +2026,16 @@ bool delayed_get_table(THD *thd, TABLE_LIST *table_list)
di->unlock();
goto end_create;
}
- pthread_mutex_lock(&LOCK_delayed_insert);
+ mysql_mutex_lock(&LOCK_delayed_insert);
delayed_threads.append(di);
- pthread_mutex_unlock(&LOCK_delayed_insert);
+ mysql_mutex_unlock(&LOCK_delayed_insert);
}
- pthread_mutex_unlock(&LOCK_delayed_create);
+ mysql_mutex_unlock(&LOCK_delayed_create);
}
- pthread_mutex_lock(&di->mutex);
+ mysql_mutex_lock(&di->mutex);
table_list->table= di->get_local_table(thd);
- pthread_mutex_unlock(&di->mutex);
+ mysql_mutex_unlock(&di->mutex);
if (table_list->table)
{
DBUG_ASSERT(! thd->is_error());
@@ -2045,7 +2046,7 @@ bool delayed_get_table(THD *thd, TABLE_LIST *table_list)
DBUG_RETURN((table_list->table == NULL));
end_create:
- pthread_mutex_unlock(&LOCK_delayed_create);
+ mysql_mutex_unlock(&LOCK_delayed_create);
DBUG_RETURN(thd->is_error());
}
@@ -2081,10 +2082,10 @@ TABLE *Delayed_insert::get_local_table(THD* client_thd)
if (!thd.lock) // Table is not locked
{
thd_proc_info(client_thd, "waiting for handler lock");
- pthread_cond_signal(&cond); // Tell handler to lock table
+ mysql_cond_signal(&cond); // Tell handler to lock table
while (!dead && !thd.lock && ! client_thd->killed)
{
- pthread_cond_wait(&cond_client,&mutex);
+ mysql_cond_wait(&cond_client, &mutex);
}
thd_proc_info(client_thd, "got handler lock");
if (client_thd->killed)
@@ -2171,7 +2172,7 @@ TABLE *Delayed_insert::get_local_table(THD* client_thd)
error:
tables_in_use--;
status=1;
- pthread_cond_signal(&cond); // Inform thread about abort
+ mysql_cond_signal(&cond); // Inform thread about abort
DBUG_RETURN(0);
}
@@ -2190,9 +2191,9 @@ int write_delayed(THD *thd, TABLE *table, enum_duplicates duplic,
(ulong) query.length));
thd_proc_info(thd, "waiting for handler insert");
- pthread_mutex_lock(&di->mutex);
+ mysql_mutex_lock(&di->mutex);
while (di->stacked_inserts >= delayed_queue_size && !thd->killed)
- pthread_cond_wait(&di->cond_client,&di->mutex);
+ mysql_cond_wait(&di->cond_client, &di->mutex);
thd_proc_info(thd, "storing row into queue");
if (thd->killed)
@@ -2267,15 +2268,15 @@ int write_delayed(THD *thd, TABLE *table, enum_duplicates duplic,
di->status=1;
if (table->s->blob_fields)
unlink_blobs(table);
- pthread_cond_signal(&di->cond);
+ mysql_cond_signal(&di->cond);
thread_safe_increment(delayed_rows_in_use,&LOCK_delayed_status);
- pthread_mutex_unlock(&di->mutex);
+ mysql_mutex_unlock(&di->mutex);
DBUG_RETURN(0);
err:
delete row;
- pthread_mutex_unlock(&di->mutex);
+ mysql_mutex_unlock(&di->mutex);
DBUG_RETURN(1);
}
@@ -2288,14 +2289,14 @@ static void end_delayed_insert(THD *thd)
{
DBUG_ENTER("end_delayed_insert");
Delayed_insert *di=thd->di;
- pthread_mutex_lock(&di->mutex);
+ mysql_mutex_lock(&di->mutex);
DBUG_PRINT("info",("tables in use: %d",di->tables_in_use));
if (!--di->tables_in_use || di->thd.killed)
{ // Unlock table
di->status=1;
- pthread_cond_signal(&di->cond);
+ mysql_cond_signal(&di->cond);
}
- pthread_mutex_unlock(&di->mutex);
+ mysql_mutex_unlock(&di->mutex);
DBUG_VOID_RETURN;
}
@@ -2304,7 +2305,7 @@ static void end_delayed_insert(THD *thd)
void kill_delayed_threads(void)
{
- pthread_mutex_lock(&LOCK_delayed_insert); // For unlink from list
+ mysql_mutex_lock(&LOCK_delayed_insert); // For unlink from list
I_List_iterator<Delayed_insert> it(delayed_threads);
Delayed_insert *di;
@@ -2313,7 +2314,7 @@ void kill_delayed_threads(void)
di->thd.killed= THD::KILL_CONNECTION;
if (di->thd.mysys_var)
{
- pthread_mutex_lock(&di->thd.mysys_var->mutex);
+ mysql_mutex_lock(&di->thd.mysys_var->mutex);
if (di->thd.mysys_var->current_cond)
{
/*
@@ -2321,15 +2322,15 @@ void kill_delayed_threads(void)
in handle_delayed_insert()
*/
if (&di->mutex != di->thd.mysys_var->current_mutex)
- pthread_mutex_lock(di->thd.mysys_var->current_mutex);
- pthread_cond_broadcast(di->thd.mysys_var->current_cond);
+ mysql_mutex_lock(di->thd.mysys_var->current_mutex);
+ mysql_cond_broadcast(di->thd.mysys_var->current_cond);
if (&di->mutex != di->thd.mysys_var->current_mutex)
- pthread_mutex_unlock(di->thd.mysys_var->current_mutex);
+ mysql_mutex_unlock(di->thd.mysys_var->current_mutex);
}
- pthread_mutex_unlock(&di->thd.mysys_var->mutex);
+ mysql_mutex_unlock(&di->thd.mysys_var->mutex);
}
}
- pthread_mutex_unlock(&LOCK_delayed_insert); // For unlink from list
+ mysql_mutex_unlock(&LOCK_delayed_insert); // For unlink from list
}
@@ -2351,15 +2352,17 @@ pthread_handler_t handle_delayed_insert(void *arg)
thd->killed=abort_loop ? THD::KILL_CONNECTION : THD::NOT_KILLED;
pthread_mutex_unlock(&LOCK_thread_count);
+ mysql_thread_set_psi_id(thd->thread_id);
+
/*
- Wait until the client runs into pthread_cond_wait(),
+ Wait until the client runs into mysql_cond_wait(),
where we free it after the table is opened and di linked in the list.
If we did not wait here, the client might detect the opened table
before it is linked to the list. It would release LOCK_delayed_create
and allow another thread to create another handler for the same table,
since it does not find one in the list.
*/
- pthread_mutex_lock(&di->mutex);
+ mysql_mutex_lock(&di->mutex);
if (my_thread_init())
{
/* Can't use my_error since store_globals has not yet been called */
@@ -2418,7 +2421,7 @@ pthread_handler_t handle_delayed_insert(void *arg)
di->table->copy_blobs=1;
/* Tell client that the thread is initialized */
- pthread_cond_signal(&di->cond_client);
+ mysql_cond_signal(&di->cond_client);
/* Now wait until we get an insert or lock to handle */
/* We will not abort as long as a client thread uses this thread */
@@ -2432,12 +2435,12 @@ pthread_handler_t handle_delayed_insert(void *arg)
Remove this from delay insert list so that no one can request a
table from this
*/
- pthread_mutex_unlock(&di->mutex);
- pthread_mutex_lock(&LOCK_delayed_insert);
+ mysql_mutex_unlock(&di->mutex);
+ mysql_mutex_lock(&LOCK_delayed_insert);
di->unlink();
lock_count=di->lock_count();
- pthread_mutex_unlock(&LOCK_delayed_insert);
- pthread_mutex_lock(&di->mutex);
+ mysql_mutex_unlock(&LOCK_delayed_insert);
+ mysql_mutex_lock(&di->mutex);
if (!lock_count && !di->tables_in_use && !di->stacked_inserts)
break; // Time to die
}
@@ -2457,15 +2460,15 @@ pthread_handler_t handle_delayed_insert(void *arg)
{
int error;
#if defined(HAVE_BROKEN_COND_TIMEDWAIT)
- error=pthread_cond_wait(&di->cond,&di->mutex);
+ error= mysql_cond_wait(&di->cond, &di->mutex);
#else
- error=pthread_cond_timedwait(&di->cond,&di->mutex,&abstime);
+ error= mysql_cond_timedwait(&di->cond, &di->mutex, &abstime);
#ifdef EXTRA_DEBUG
if (error && error != EINTR && error != ETIMEDOUT)
{
- fprintf(stderr, "Got error %d from pthread_cond_timedwait\n",error);
- DBUG_PRINT("error",("Got error %d from pthread_cond_timedwait",
- error));
+ fprintf(stderr, "Got error %d from mysql_cond_timedwait\n", error);
+ DBUG_PRINT("error", ("Got error %d from mysql_cond_timedwait",
+ error));
}
#endif
#endif
@@ -2478,12 +2481,12 @@ pthread_handler_t handle_delayed_insert(void *arg)
}
}
/* We can't lock di->mutex and mysys_var->mutex at the same time */
- pthread_mutex_unlock(&di->mutex);
- pthread_mutex_lock(&di->thd.mysys_var->mutex);
+ mysql_mutex_unlock(&di->mutex);
+ mysql_mutex_lock(&di->thd.mysys_var->mutex);
di->thd.mysys_var->current_mutex= 0;
di->thd.mysys_var->current_cond= 0;
- pthread_mutex_unlock(&di->thd.mysys_var->mutex);
- pthread_mutex_lock(&di->mutex);
+ mysql_mutex_unlock(&di->thd.mysys_var->mutex);
+ mysql_mutex_lock(&di->mutex);
}
thd_proc_info(&(di->thd), 0);
@@ -2508,7 +2511,7 @@ pthread_handler_t handle_delayed_insert(void *arg)
di->dead= 1;
thd->killed= THD::KILL_CONNECTION;
}
- pthread_cond_broadcast(&di->cond_client);
+ mysql_cond_broadcast(&di->cond_client);
}
if (di->stacked_inserts)
{
@@ -2528,7 +2531,7 @@ pthread_handler_t handle_delayed_insert(void *arg)
*/
MYSQL_LOCK *lock=thd->lock;
thd->lock=0;
- pthread_mutex_unlock(&di->mutex);
+ mysql_mutex_unlock(&di->mutex);
/*
We need to release next_insert_id before unlocking. This is
enforced by handler::ha_external_lock().
@@ -2537,10 +2540,10 @@ pthread_handler_t handle_delayed_insert(void *arg)
mysql_unlock_tables(thd, lock);
ha_autocommit_or_rollback(thd, 0);
di->group_count=0;
- pthread_mutex_lock(&di->mutex);
+ mysql_mutex_lock(&di->mutex);
}
if (di->tables_in_use)
- pthread_cond_broadcast(&di->cond_client); // If waiting clients
+ mysql_cond_broadcast(&di->cond_client); // If waiting clients
}
err:
@@ -2569,14 +2572,14 @@ pthread_handler_t handle_delayed_insert(void *arg)
di->table=0;
di->dead= 1; // If error
thd->killed= THD::KILL_CONNECTION; // If error
- pthread_cond_broadcast(&di->cond_client); // Safety
- pthread_mutex_unlock(&di->mutex);
+ mysql_cond_broadcast(&di->cond_client); // Safety
+ mysql_mutex_unlock(&di->mutex);
- pthread_mutex_lock(&LOCK_delayed_create); // Because of delayed_get_table
- pthread_mutex_lock(&LOCK_delayed_insert);
+ mysql_mutex_lock(&LOCK_delayed_create); // Because of delayed_get_table
+ mysql_mutex_lock(&LOCK_delayed_insert);
delete di;
- pthread_mutex_unlock(&LOCK_delayed_insert);
- pthread_mutex_unlock(&LOCK_delayed_create);
+ mysql_mutex_unlock(&LOCK_delayed_insert);
+ mysql_mutex_unlock(&LOCK_delayed_create);
my_thread_end();
pthread_exit(0);
@@ -2623,7 +2626,7 @@ bool Delayed_insert::handle_inserts(void)
DBUG_ENTER("handle_inserts");
/* Allow client to insert new rows */
- pthread_mutex_unlock(&mutex);
+ mysql_mutex_unlock(&mutex);
table->next_number_field=table->found_next_number_field;
table->use_all_columns();
@@ -2656,12 +2659,12 @@ bool Delayed_insert::handle_inserts(void)
*/
if (!using_bin_log)
table->file->extra(HA_EXTRA_WRITE_CACHE);
- pthread_mutex_lock(&mutex);
+ mysql_mutex_lock(&mutex);
while ((row=rows.get()))
{
stacked_inserts--;
- pthread_mutex_unlock(&mutex);
+ mysql_mutex_unlock(&mutex);
memcpy(table->record[0],row->record,table->s->reclength);
thd.start_time=row->start_time;
@@ -2780,7 +2783,7 @@ bool Delayed_insert::handle_inserts(void)
free_delayed_insert_blobs(table);
thread_safe_decrement(delayed_rows_in_use,&LOCK_delayed_status);
thread_safe_increment(delayed_insert_writes,&LOCK_delayed_status);
- pthread_mutex_lock(&mutex);
+ mysql_mutex_lock(&mutex);
/*
Reset the table->auto_increment_field_not_null as it is valid for
@@ -2802,9 +2805,9 @@ bool Delayed_insert::handle_inserts(void)
if (stacked_inserts || tables_in_use) // Let these wait a while
{
if (tables_in_use)
- pthread_cond_broadcast(&cond_client); // If waiting clients
+ mysql_cond_broadcast(&cond_client); // If waiting clients
thd_proc_info(&thd, "reschedule");
- pthread_mutex_unlock(&mutex);
+ mysql_mutex_unlock(&mutex);
if ((error=table->file->extra(HA_EXTRA_NO_CACHE)))
{
/* This should never happen */
@@ -2823,15 +2826,15 @@ bool Delayed_insert::handle_inserts(void)
}
if (!using_bin_log)
table->file->extra(HA_EXTRA_WRITE_CACHE);
- pthread_mutex_lock(&mutex);
+ mysql_mutex_lock(&mutex);
thd_proc_info(&thd, "insert");
}
if (tables_in_use)
- pthread_cond_broadcast(&cond_client); // If waiting clients
+ mysql_cond_broadcast(&cond_client); // If waiting clients
}
}
thd_proc_info(&thd, 0);
- pthread_mutex_unlock(&mutex);
+ mysql_mutex_unlock(&mutex);
/*
We need to flush the pending event when using row-based
@@ -2857,7 +2860,7 @@ bool Delayed_insert::handle_inserts(void)
goto err;
}
query_cache_invalidate3(&thd, table, 1);
- pthread_mutex_lock(&mutex);
+ mysql_mutex_lock(&mutex);
DBUG_RETURN(0);
err:
@@ -2881,7 +2884,7 @@ bool Delayed_insert::handle_inserts(void)
}
DBUG_PRINT("error", ("dropped %lu rows after an error", max_rows));
thread_safe_increment(delayed_insert_errors, &LOCK_delayed_status);
- pthread_mutex_lock(&mutex);
+ mysql_mutex_lock(&mutex);
DBUG_RETURN(1);
}
#endif /* EMBEDDED_LIBRARY */
@@ -3544,7 +3547,7 @@ static TABLE *create_table_from_items(THD *thd, HA_CREATE_INFO *create_info,
if (!(create_info->options & HA_LEX_CREATE_TMP_TABLE))
{
- pthread_mutex_lock(&LOCK_open);
+ mysql_mutex_lock(&LOCK_open);
if (reopen_name_locked_table(thd, create_table, FALSE))
{
quick_rm_table(create_info->db_type, create_table->db,
@@ -3553,7 +3556,7 @@ static TABLE *create_table_from_items(THD *thd, HA_CREATE_INFO *create_info,
}
else
table= create_table->table;
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
}
else
{
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index ee141c82c28..0774e373908 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -1,4 +1,4 @@
-/* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
+/* Copyright 2000-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -2075,11 +2075,11 @@ mysql_execute_command(THD *thd)
restore status variables, as we don't want 'show status' to cause
changes
*/
- pthread_mutex_lock(&LOCK_status);
+ mysql_mutex_lock(&LOCK_status);
add_diff_to_status(&global_status_var, &thd->status_var,
&old_status_var);
thd->status_var= old_status_var;
- pthread_mutex_unlock(&LOCK_status);
+ mysql_mutex_unlock(&LOCK_status);
break;
}
case SQLCOM_SHOW_DATABASES:
diff --git a/sql/sql_partition.cc b/sql/sql_partition.cc
index 4586879dec4..b6112e51565 100644
--- a/sql/sql_partition.cc
+++ b/sql/sql_partition.cc
@@ -6281,7 +6281,7 @@ static void alter_partition_lock_handling(ALTER_PARTITION_PARAM_TYPE *lpt)
since all table objects were closed and removed as part of the
ALTER TABLE of partitioning structure.
*/
- pthread_mutex_lock(&LOCK_open);
+ mysql_mutex_lock(&LOCK_open);
lpt->thd->in_lock_tables= 1;
err= reopen_tables(lpt->thd, 1, 1);
lpt->thd->in_lock_tables= 0;
@@ -6295,7 +6295,7 @@ static void alter_partition_lock_handling(ALTER_PARTITION_PARAM_TYPE *lpt)
unlink_open_table(lpt->thd, lpt->table, FALSE);
sql_print_warning("We failed to reacquire LOCKs in ALTER TABLE");
}
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
}
}
@@ -6319,9 +6319,9 @@ static int alter_close_tables(ALTER_PARTITION_PARAM_TYPE *lpt)
We set lock to zero to ensure we don't do this twice
and we set db_stat to zero to ensure we don't close twice.
*/
- pthread_mutex_lock(&LOCK_open);
+ mysql_mutex_lock(&LOCK_open);
close_data_files_and_morph_locks(thd, db, table_name);
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
DBUG_RETURN(0);
}
diff --git a/sql/sql_plugin.cc b/sql/sql_plugin.cc
index d15c97de912..4d60caf2931 100644
--- a/sql/sql_plugin.cc
+++ b/sql/sql_plugin.cc
@@ -1371,10 +1371,10 @@ static void plugin_load(MEM_ROOT *tmp_root, int *argc, char **argv)
When building an embedded library, if the mysql.plugin table
does not exist, we silently ignore the missing table
*/
- pthread_mutex_lock(&LOCK_open);
+ mysql_mutex_lock(&LOCK_open);
if (check_if_table_exists(new_thd, &tables, &table_exists))
table_exists= FALSE;
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
if (!table_exists)
goto end;
#endif /* EMBEDDED_LIBRARY */
diff --git a/sql/sql_rename.cc b/sql/sql_rename.cc
index e85e730db5b..7c52a12c072 100644
--- a/sql/sql_rename.cc
+++ b/sql/sql_rename.cc
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2006 MySQL AB
+/* Copyright (C) 2000-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -134,10 +134,10 @@ bool mysql_rename_tables(THD *thd, TABLE_LIST *table_list, bool silent)
}
}
- pthread_mutex_lock(&LOCK_open);
+ mysql_mutex_lock(&LOCK_open);
if (lock_table_names_exclusively(thd, table_list))
{
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
goto err;
}
@@ -173,7 +173,7 @@ bool mysql_rename_tables(THD *thd, TABLE_LIST *table_list, bool silent)
higher concurrency - query_cache_invalidate can take minutes to
complete.
*/
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
if (!silent && !error)
{
@@ -185,9 +185,9 @@ bool mysql_rename_tables(THD *thd, TABLE_LIST *table_list, bool silent)
if (!error)
query_cache_invalidate3(thd, table_list, 0);
- pthread_mutex_lock(&LOCK_open);
+ mysql_mutex_lock(&LOCK_open);
unlock_table_names(thd, table_list, (TABLE_LIST*) 0);
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
err:
start_waiting_global_read_lock(thd);
diff --git a/sql/sql_show.cc b/sql/sql_show.cc
index 7ba62c62259..bf92717e79d 100644
--- a/sql/sql_show.cc
+++ b/sql/sql_show.cc
@@ -1,4 +1,4 @@
-/* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
+/* Copyright 2000-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -1759,11 +1759,11 @@ void mysqld_list_processes(THD *thd,const char *user, bool verbose)
thd_info->db=thd->strdup(thd_info->db);
thd_info->command=(int) tmp->command;
if ((mysys_var= tmp->mysys_var))
- pthread_mutex_lock(&mysys_var->mutex);
+ mysql_mutex_lock(&mysys_var->mutex);
thd_info->proc_info= (char*) (tmp->killed == THD::KILL_CONNECTION? "Killed" : 0);
thd_info->state_info= thread_state_info(tmp);
if (mysys_var)
- pthread_mutex_unlock(&mysys_var->mutex);
+ mysql_mutex_unlock(&mysys_var->mutex);
thd_info->start_time= tmp->start_time;
thd_info->query=0;
@@ -1862,7 +1862,7 @@ int fill_schema_processlist(THD* thd, TABLE_LIST* tables, COND* cond)
}
if ((mysys_var= tmp->mysys_var))
- pthread_mutex_lock(&mysys_var->mutex);
+ mysql_mutex_lock(&mysys_var->mutex);
/* COMMAND */
if ((val= (char *) (tmp->killed == THD::KILL_CONNECTION? "Killed" : 0)))
table->field[4]->store(val, strlen(val), cs);
@@ -1880,7 +1880,7 @@ int fill_schema_processlist(THD* thd, TABLE_LIST* tables, COND* cond)
}
if (mysys_var)
- pthread_mutex_unlock(&mysys_var->mutex);
+ mysql_mutex_unlock(&mysys_var->mutex);
/* INFO */
if (tmp->query())
@@ -1958,7 +1958,7 @@ int add_status_vars(SHOW_VAR *list)
{
int res= 0;
if (status_vars_inited)
- pthread_mutex_lock(&LOCK_status);
+ mysql_mutex_lock(&LOCK_status);
if (!all_status_vars.buffer && // array is not allocated yet - do it now
my_init_dynamic_array(&all_status_vars, sizeof(SHOW_VAR), 200, 20))
{
@@ -1973,7 +1973,7 @@ int add_status_vars(SHOW_VAR *list)
sort_dynamic(&all_status_vars, show_var_cmp);
err:
if (status_vars_inited)
- pthread_mutex_unlock(&LOCK_status);
+ mysql_mutex_unlock(&LOCK_status);
return res;
}
@@ -2035,7 +2035,7 @@ void remove_status_vars(SHOW_VAR *list)
{
if (status_vars_inited)
{
- pthread_mutex_lock(&LOCK_status);
+ mysql_mutex_lock(&LOCK_status);
SHOW_VAR *all= dynamic_element(&all_status_vars, 0, SHOW_VAR *);
int a= 0, b= all_status_vars.elements, c= (a+b)/2;
@@ -2056,7 +2056,7 @@ void remove_status_vars(SHOW_VAR *list)
all[c].type= SHOW_UNDEF;
}
shrink_var_array(&all_status_vars);
- pthread_mutex_unlock(&LOCK_status);
+ mysql_mutex_unlock(&LOCK_status);
}
else
{
@@ -3102,7 +3102,7 @@ static int fill_schema_table_from_frm(THD *thd,TABLE *table,
}
key_length= create_table_def_key(thd, key, &table_list, 0);
- pthread_mutex_lock(&LOCK_open);
+ mysql_mutex_lock(&LOCK_open);
share= get_table_share(thd, &table_list, key,
key_length, OPEN_VIEW, &error);
if (!share)
@@ -3149,7 +3149,7 @@ err1:
release_table_share(share, RELEASE_NORMAL);
err:
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
thd->clear_error();
return res;
}
@@ -5524,14 +5524,14 @@ int fill_status(THD *thd, TABLE_LIST *tables, COND *cond)
tmp1= &thd->status_var;
}
- pthread_mutex_lock(&LOCK_status);
+ mysql_mutex_lock(&LOCK_status);
if (option_type == OPT_GLOBAL)
calc_sum_of_all_status(&tmp);
res= show_status_array(thd, wild,
(SHOW_VAR *)all_status_vars.buffer,
option_type, tmp1, "", tables->table,
upper_case_names, cond);
- pthread_mutex_unlock(&LOCK_status);
+ mysql_mutex_unlock(&LOCK_status);
DBUG_RETURN(res);
}
@@ -7218,7 +7218,7 @@ static TABLE_LIST *get_trigger_table(THD *thd, const sp_name *trg_name)
{
/* Acquire LOCK_open (stop the server). */
- pthread_mutex_lock(&LOCK_open);
+ mysql_mutex_lock(&LOCK_open);
/*
Load base table name from the TRN-file and create TABLE_LIST object.
@@ -7228,7 +7228,7 @@ static TABLE_LIST *get_trigger_table(THD *thd, const sp_name *trg_name)
/* Release LOCK_open (continue the server). */
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
/* That's it. */
diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index e06659a549c..c4904feffa6 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -1,4 +1,4 @@
-/* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
+/* Copyright 2000-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -1653,7 +1653,7 @@ bool mysql_write_frm(ALTER_PARTITION_PARAM_TYPE *lpt, uint flags)
completing this we write a new phase to the log entry that will
deactivate it.
*/
- pthread_mutex_lock(&LOCK_open);
+ mysql_mutex_lock(&LOCK_open);
if (my_delete(frm_name, MYF(MY_WME)) ||
#ifdef WITH_PARTITION_STORAGE_ENGINE
lpt->table->file->ha_create_handler_files(path, shadow_path,
@@ -1706,7 +1706,7 @@ bool mysql_write_frm(ALTER_PARTITION_PARAM_TYPE *lpt, uint flags)
#endif
err:
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
#ifdef WITH_PARTITION_STORAGE_ENGINE
deactivate_ddl_log_entry(part_info->frm_log_entry->entry_pos);
part_info->frm_log_entry= NULL;
@@ -1871,7 +1871,7 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists,
mysql_ha_rm_tables(thd, tables, FALSE);
- pthread_mutex_lock(&LOCK_open);
+ mysql_mutex_lock(&LOCK_open);
/*
If we have the table in the definition cache, we don't have to check the
@@ -1892,14 +1892,14 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists,
table->table_name_length, table->table_name, 1))
{
my_error(ER_BAD_LOG_STATEMENT, MYF(0), "DROP");
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
DBUG_RETURN(1);
}
}
if (!drop_temporary && lock_table_names_exclusively(thd, tables))
{
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
DBUG_RETURN(1);
}
@@ -2070,7 +2070,7 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists,
It's safe to unlock LOCK_open: we have an exclusive lock
on the table name.
*/
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
thd->thread_specific_used|= tmp_table_deleted;
error= 0;
if (wrong_tables.length())
@@ -2153,10 +2153,10 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists,
*/
}
}
- pthread_mutex_lock(&LOCK_open);
+ mysql_mutex_lock(&LOCK_open);
err_with_placeholders:
unlock_table_names(thd, tables, (TABLE_LIST*) 0);
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
DBUG_RETURN(error);
}
@@ -3872,7 +3872,7 @@ bool mysql_create_table_no_lock(THD *thd,
goto err;
}
- pthread_mutex_lock(&LOCK_open);
+ mysql_mutex_lock(&LOCK_open);
if (!internal_tmp_table && !(create_info->options & HA_LEX_CREATE_TMP_TABLE))
{
if (!access(path,F_OK))
@@ -4016,7 +4016,7 @@ bool mysql_create_table_no_lock(THD *thd,
error= write_create_table_bin_log(thd, create_info, internal_tmp_table);
unlock_and_end:
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
err:
thd_proc_info(thd, "After create");
@@ -4049,21 +4049,21 @@ bool mysql_create_table(THD *thd, const char *db, const char *table_name,
DBUG_ENTER("mysql_create_table");
/* Wait for any database locks */
- pthread_mutex_lock(&LOCK_lock_db);
+ mysql_mutex_lock(&LOCK_lock_db);
while (!thd->killed &&
my_hash_search(&lock_db_cache,(uchar*) db, strlen(db)))
{
wait_for_condition(thd, &LOCK_lock_db, &COND_refresh);
- pthread_mutex_lock(&LOCK_lock_db);
+ mysql_mutex_lock(&LOCK_lock_db);
}
if (thd->killed)
{
- pthread_mutex_unlock(&LOCK_lock_db);
+ mysql_mutex_unlock(&LOCK_lock_db);
DBUG_RETURN(TRUE);
}
creating_table++;
- pthread_mutex_unlock(&LOCK_lock_db);
+ mysql_mutex_unlock(&LOCK_lock_db);
if (!(create_info->options & HA_LEX_CREATE_TMP_TABLE))
{
@@ -4100,14 +4100,14 @@ bool mysql_create_table(THD *thd, const char *db, const char *table_name,
unlock:
if (name_lock)
{
- pthread_mutex_lock(&LOCK_open);
+ mysql_mutex_lock(&LOCK_open);
unlink_open_table(thd, name_lock, FALSE);
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
}
- pthread_mutex_lock(&LOCK_lock_db);
+ mysql_mutex_lock(&LOCK_lock_db);
if (!--creating_table && creating_database)
- pthread_cond_signal(&COND_refresh);
- pthread_mutex_unlock(&LOCK_lock_db);
+ mysql_cond_signal(&COND_refresh);
+ mysql_mutex_unlock(&LOCK_lock_db);
DBUG_RETURN(result);
}
@@ -4268,7 +4268,7 @@ void wait_while_table_is_used(THD *thd, TABLE *table,
table->s->table_name.str, (ulong) table->s,
table->db_stat, table->s->version));
- safe_mutex_assert_owner(&LOCK_open);
+ mysql_mutex_assert_owner(&LOCK_open);
(void) table->file->extra(function);
/* Mark all tables that are in use as 'old' */
@@ -4353,22 +4353,22 @@ static int prepare_for_repair(THD *thd, TABLE_LIST *table_list,
uint key_length;
key_length= create_table_def_key(thd, key, table_list, 0);
- pthread_mutex_lock(&LOCK_open);
+ mysql_mutex_lock(&LOCK_open);
if (!(share= (get_table_share(thd, table_list, key, key_length, 0,
&error))))
{
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
DBUG_RETURN(0); // Can't open frm file
}
if (open_table_from_share(thd, share, "", 0, 0, 0, &tmp_table, FALSE))
{
release_table_share(share, RELEASE_NORMAL);
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
DBUG_RETURN(0); // Out of memory
}
table= &tmp_table;
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
}
/* A MERGE table must not come here. */
@@ -4422,9 +4422,9 @@ static int prepare_for_repair(THD *thd, TABLE_LIST *table_list,
/* If we could open the table, close it */
if (table_list->table)
{
- pthread_mutex_lock(&LOCK_open);
+ mysql_mutex_lock(&LOCK_open);
close_cached_table(thd, table);
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
}
if (lock_and_wait_for_table_name(thd,table_list))
{
@@ -4433,27 +4433,27 @@ static int prepare_for_repair(THD *thd, TABLE_LIST *table_list,
}
if (my_rename(from, tmp, MYF(MY_WME)))
{
- pthread_mutex_lock(&LOCK_open);
+ mysql_mutex_lock(&LOCK_open);
unlock_table_name(thd, table_list);
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
error= send_check_errmsg(thd, table_list, "repair",
"Failed renaming data file");
goto end;
}
if (mysql_truncate(thd, table_list, 1))
{
- pthread_mutex_lock(&LOCK_open);
+ mysql_mutex_lock(&LOCK_open);
unlock_table_name(thd, table_list);
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
error= send_check_errmsg(thd, table_list, "repair",
"Failed generating table from .frm file");
goto end;
}
if (my_rename(tmp, from, MYF(MY_WME)))
{
- pthread_mutex_lock(&LOCK_open);
+ mysql_mutex_lock(&LOCK_open);
unlock_table_name(thd, table_list);
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
error= send_check_errmsg(thd, table_list, "repair",
"Failed restoring .MYD file");
goto end;
@@ -4463,23 +4463,23 @@ static int prepare_for_repair(THD *thd, TABLE_LIST *table_list,
Now we should be able to open the partially repaired table
to finish the repair in the handler later on.
*/
- pthread_mutex_lock(&LOCK_open);
+ mysql_mutex_lock(&LOCK_open);
if (reopen_name_locked_table(thd, table_list, TRUE))
{
unlock_table_name(thd, table_list);
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
error= send_check_errmsg(thd, table_list, "repair",
"Failed to open partially repaired table");
goto end;
}
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
end:
if (table == &tmp_table)
{
- pthread_mutex_lock(&LOCK_open);
+ mysql_mutex_lock(&LOCK_open);
closefrm(table, 1); // Free allocated memory
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
}
DBUG_RETURN(error);
}
@@ -4706,7 +4706,7 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables,
if (lock_type == TL_WRITE && table->table->s->version)
{
DBUG_PRINT("admin", ("removing table from cache"));
- pthread_mutex_lock(&LOCK_open);
+ mysql_mutex_lock(&LOCK_open);
const char *old_message=thd->enter_cond(&COND_refresh, &LOCK_open,
"Waiting to get writelock");
mysql_lock_abort(thd,table->table, TRUE);
@@ -4969,10 +4969,10 @@ send_result_message:
table->table->file->info(HA_STATUS_CONST);
else
{
- pthread_mutex_lock(&LOCK_open);
+ mysql_mutex_lock(&LOCK_open);
remove_table_from_cache(thd, table->table->s->db.str,
table->table->s->table_name.str, RTFC_NO_FLAG);
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
}
/* May be something modified consequently we have to invalidate cache */
query_cache_invalidate3(thd, table->table, 0);
@@ -5275,12 +5275,12 @@ bool mysql_create_like_table(THD* thd, TABLE_LIST* table, TABLE_LIST* src_table,
Also some engines (e.g. NDB cluster) require that LOCK_open should be held
during the call to ha_create_table(). See bug #28614 for more info.
*/
- pthread_mutex_lock(&LOCK_open);
+ mysql_mutex_lock(&LOCK_open);
if (src_table->schema_table)
{
if (mysql_create_like_schema_frm(thd, src_table, dst_path, create_info))
{
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
goto err;
}
}
@@ -5290,7 +5290,7 @@ bool mysql_create_like_table(THD* thd, TABLE_LIST* table, TABLE_LIST* src_table,
my_error(ER_BAD_DB_ERROR,MYF(0),db);
else
my_error(ER_CANT_CREATE_FILE,MYF(0),dst_path,my_errno);
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
goto err;
}
@@ -5319,7 +5319,7 @@ bool mysql_create_like_table(THD* thd, TABLE_LIST* table, TABLE_LIST* src_table,
if (thd->variables.keep_files_on_create)
create_info->options|= HA_CREATE_KEEP_FILES;
err= ha_create_table(thd, dst_path, db, table_name, create_info, 1);
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
if (create_info->options & HA_LEX_CREATE_TMP_TABLE)
{
@@ -5393,13 +5393,13 @@ binlog:
of this function.
*/
table->table= name_lock;
- pthread_mutex_lock(&LOCK_open);
+ mysql_mutex_lock(&LOCK_open);
if (reopen_name_locked_table(thd, table, FALSE))
{
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
goto err;
}
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
/*
The condition avoids a crash as described in BUG#48506. Other
@@ -5433,9 +5433,9 @@ binlog:
err:
if (name_lock)
{
- pthread_mutex_lock(&LOCK_open);
+ mysql_mutex_lock(&LOCK_open);
unlink_open_table(thd, name_lock, FALSE);
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
}
DBUG_RETURN(res);
}
@@ -6552,7 +6552,7 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
if (wait_if_global_read_lock(thd,0,1))
DBUG_RETURN(TRUE);
- pthread_mutex_lock(&LOCK_open);
+ mysql_mutex_lock(&LOCK_open);
if (lock_table_names(thd, table_list))
{
error= 1;
@@ -6576,7 +6576,7 @@ view_err_unlock:
unlock_table_names(thd, table_list, (TABLE_LIST*) 0);
view_err:
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
start_waiting_global_read_lock(thd);
DBUG_RETURN(error);
}
@@ -6737,17 +6737,17 @@ view_err:
while the fact that the table is still open gives us protection
from concurrent DDL statements.
*/
- pthread_mutex_lock(&LOCK_open);
+ mysql_mutex_lock(&LOCK_open);
wait_while_table_is_used(thd, table, HA_EXTRA_FORCE_REOPEN);
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
DBUG_EXECUTE_IF("sleep_alter_enable_indexes", my_sleep(6000000););
error= table->file->ha_enable_indexes(HA_KEY_SWITCH_NONUNIQ_SAVE);
/* COND_refresh will be signaled in close_thread_tables() */
break;
case DISABLE:
- pthread_mutex_lock(&LOCK_open);
+ mysql_mutex_lock(&LOCK_open);
wait_while_table_is_used(thd, table, HA_EXTRA_FORCE_REOPEN);
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
error=table->file->ha_disable_indexes(HA_KEY_SWITCH_NONUNIQ_SAVE);
/* COND_refresh will be signaled in close_thread_tables() */
break;
@@ -6764,7 +6764,7 @@ view_err:
table->alias);
}
- pthread_mutex_lock(&LOCK_open);
+ mysql_mutex_lock(&LOCK_open);
/*
Unlike to the above case close_cached_table() below will remove ALL
instances of TABLE from table cache (it will also remove table lock
@@ -6831,7 +6831,7 @@ view_err:
}
if (name_lock)
unlink_open_table(thd, name_lock, FALSE);
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
table_list->table= NULL; // For query cache
query_cache_invalidate3(thd, table_list, 0);
DBUG_RETURN(error);
@@ -7192,9 +7192,9 @@ view_err:
}
else
{
- pthread_mutex_lock(&LOCK_open);
+ mysql_mutex_lock(&LOCK_open);
wait_while_table_is_used(thd, table, HA_EXTRA_FORCE_REOPEN);
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
thd_proc_info(thd, "manage keys");
alter_table_manage_keys(table, table->file->indexes_are_disabled(),
alter_info->keys_onoff);
@@ -7325,11 +7325,11 @@ view_err:
intern_close_table(new_table);
my_free(new_table,MYF(0));
}
- pthread_mutex_lock(&LOCK_open);
+ mysql_mutex_lock(&LOCK_open);
if (error)
{
(void) quick_rm_table(new_db_type, new_db, tmp_name, FN_IS_TMP);
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
goto err;
}
@@ -7462,7 +7462,7 @@ view_err:
if (error)
goto err_with_placeholders;
}
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
thd_proc_info(thd, "end");
@@ -7510,10 +7510,10 @@ view_err:
from the list of open tables and table cache. If we are not under
LOCK TABLES we can rely on close_thread_tables() doing this job.
*/
- pthread_mutex_lock(&LOCK_open);
+ mysql_mutex_lock(&LOCK_open);
unlink_open_table(thd, table, FALSE);
unlink_open_table(thd, name_lock, FALSE);
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
}
end_temporary:
@@ -7570,9 +7570,9 @@ err:
}
if (name_lock)
{
- pthread_mutex_lock(&LOCK_open);
+ mysql_mutex_lock(&LOCK_open);
unlink_open_table(thd, name_lock, FALSE);
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
}
DBUG_RETURN(TRUE);
@@ -7585,7 +7585,7 @@ err_with_placeholders:
unlink_open_table(thd, table, FALSE);
if (name_lock)
unlink_open_table(thd, name_lock, FALSE);
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
DBUG_RETURN(TRUE);
}
/* mysql_alter_table */
diff --git a/sql/sql_test.cc b/sql/sql_test.cc
index f95d19f099e..ac1dae3197d 100644
--- a/sql/sql_test.cc
+++ b/sql/sql_test.cc
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2006 MySQL AB
+/* Copyright (C) 2000-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -79,7 +79,7 @@ void print_cached_tables(void)
compile_time_assert(TL_WRITE_ONLY+1 == array_elements(lock_descriptions));
/* purecov: begin tested */
- pthread_mutex_lock(&LOCK_open);
+ mysql_mutex_lock(&LOCK_open);
puts("DB Table Version Thread Open Lock");
for (idx=unused=0 ; idx < open_cache.records ; idx++)
@@ -115,7 +115,7 @@ void print_cached_tables(void)
if (my_hash_check(&open_cache))
printf("Error: File hash table is corrupted\n");
fflush(stdout);
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
/* purecov: end */
return;
}
@@ -380,12 +380,12 @@ static void display_table_locks(void)
DYNAMIC_ARRAY saved_table_locks;
(void) my_init_dynamic_array(&saved_table_locks,sizeof(TABLE_LOCK_INFO),open_cache.records + 20,50);
- pthread_mutex_lock(&THR_LOCK_lock);
+ mysql_mutex_lock(&THR_LOCK_lock);
for (list= thr_lock_thread_list; list; list= list_rest(list))
{
THR_LOCK *lock=(THR_LOCK*) list->data;
- pthread_mutex_lock(&lock->mutex);
+ mysql_mutex_lock(&lock->mutex);
push_locks_into_array(&saved_table_locks, lock->write.data, FALSE,
"Locked - write");
push_locks_into_array(&saved_table_locks, lock->write_wait.data, TRUE,
@@ -394,9 +394,9 @@ static void display_table_locks(void)
"Locked - read");
push_locks_into_array(&saved_table_locks, lock->read_wait.data, TRUE,
"Waiting - read");
- pthread_mutex_unlock(&lock->mutex);
+ mysql_mutex_unlock(&lock->mutex);
}
- pthread_mutex_unlock(&THR_LOCK_lock);
+ mysql_mutex_unlock(&THR_LOCK_lock);
if (!saved_table_locks.elements) goto end;
qsort((uchar*) dynamic_element(&saved_table_locks,0,TABLE_LOCK_INFO *),saved_table_locks.elements,sizeof(TABLE_LOCK_INFO),(qsort_cmp) dl_compare);
@@ -472,7 +472,7 @@ void mysql_print_status()
/* Print key cache status */
puts("\nKey caches:");
process_key_caches(print_key_cache_status);
- pthread_mutex_lock(&LOCK_status);
+ mysql_mutex_lock(&LOCK_status);
printf("\nhandler status:\n\
read_key: %10lu\n\
read_next: %10lu\n\
@@ -488,7 +488,7 @@ update: %10lu\n",
tmp.ha_write_count,
tmp.ha_delete_count,
tmp.ha_update_count);
- pthread_mutex_unlock(&LOCK_status);
+ mysql_mutex_unlock(&LOCK_status);
printf("\nTable status:\n\
Opened tables: %10lu\n\
Open tables: %10lu\n\
diff --git a/sql/sql_trigger.cc b/sql/sql_trigger.cc
index 96af74df072..4ab9bba03ae 100644
--- a/sql/sql_trigger.cc
+++ b/sql/sql_trigger.cc
@@ -1,4 +1,4 @@
-/* Copyright (C) 2004-2005 MySQL AB
+/* Copyright (C) 2004-2005 MySQL AB, 2008-2009 Sun Microsystems, Inc
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -387,7 +387,7 @@ bool mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create)
!(need_start_waiting= !wait_if_global_read_lock(thd, 0, 1)))
DBUG_RETURN(TRUE);
- pthread_mutex_lock(&LOCK_open);
+ mysql_mutex_lock(&LOCK_open);
if (!create)
{
@@ -510,7 +510,7 @@ end:
result= write_bin_log(thd, TRUE, stmt_query.ptr(), stmt_query.length());
}
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
if (need_start_waiting)
start_waiting_global_read_lock(thd);
@@ -1884,7 +1884,7 @@ bool Table_triggers_list::change_table_name(THD *thd, const char *db,
old_table)-(char*)&key[0])+1;
if (!is_table_name_exclusively_locked_by_this_thread(thd, key, key_length))
- safe_mutex_assert_owner(&LOCK_open);
+ mysql_mutex_assert_owner(&LOCK_open);
#endif
DBUG_ASSERT(my_strcasecmp(table_alias_charset, db, new_db) ||
diff --git a/sql/sql_view.cc b/sql/sql_view.cc
index c911f4fe7b9..8305303f351 100644
--- a/sql/sql_view.cc
+++ b/sql/sql_view.cc
@@ -1,4 +1,4 @@
-/* Copyright (C) 2004 MySQL AB
+/* Copyright (C) 2004 MySQL AB, 2008-2009 Sun Microsystems, Inc
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -620,7 +620,7 @@ bool mysql_create_view(THD *thd, TABLE_LIST *views,
res= TRUE;
goto err;
}
- pthread_mutex_lock(&LOCK_open);
+ mysql_mutex_lock(&LOCK_open);
res= mysql_register_view(thd, view, mode);
if (mysql_bin_log.is_open())
@@ -667,7 +667,7 @@ bool mysql_create_view(THD *thd, TABLE_LIST *views,
res= TRUE;
}
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
if (mode != VIEW_CREATE_NEW)
query_cache_invalidate3(thd, view, 0);
start_waiting_global_read_lock(thd);
@@ -1581,7 +1581,7 @@ bool mysql_drop_view(THD *thd, TABLE_LIST *views, enum_drop_mode drop_mode)
bool something_wrong= FALSE;
DBUG_ENTER("mysql_drop_view");
- pthread_mutex_lock(&LOCK_open);
+ mysql_mutex_lock(&LOCK_open);
for (view= views; view; view= view->next_local)
{
TABLE_SHARE *share;
@@ -1659,7 +1659,7 @@ bool mysql_drop_view(THD *thd, TABLE_LIST *views, enum_drop_mode drop_mode)
something_wrong= 1;
}
- pthread_mutex_unlock(&LOCK_open);
+ mysql_mutex_unlock(&LOCK_open);
if (something_wrong)
{