List:Commits« Previous MessageNext Message »
From:Marc Alff Date:October 17 2008 2:24am
Subject:bzr commit into mysql-6.0-perf branch (marc.alff:2709)
View as plain text  
#At file:///home/malff/BZR-TREE/mysql-6.0-perf/

 2709 Marc Alff	2008-10-16
      Instrumentation continued, make dist continued
modified:
  BUILD/compile-dist
  mysys/my_init.c
  mysys/my_open.c
  mysys/my_pthread.c
  mysys/mysys_priv.h
  mysys/thr_alarm.c
  mysys/thr_lock.c
  storage/archive/azio.c
  storage/archive/azio.h
  storage/archive/ha_archive.cc
  storage/archive/ha_archive.h
  storage/blackhole/ha_blackhole.cc
  storage/csv/ha_tina.cc
  storage/csv/ha_tina.h
  storage/example/ha_example.cc
  storage/example/ha_example.h
  storage/maria/trnman.c

=== modified file 'BUILD/compile-dist'
--- a/BUILD/compile-dist	2008-10-16 21:34:55 +0000
+++ b/BUILD/compile-dist	2008-10-17 02:24:29 +0000
@@ -44,6 +44,6 @@ fi
   --with-maria-storage-engine \
   --with-embedded-server \
   --with-falcon \
-  --with-perfschema-storage-engine \
+  --with-perfschema \
   --with-ndbcluster
 make

=== modified file 'mysys/my_init.c'
--- a/mysys/my_init.c	2008-10-16 17:01:38 +0000
+++ b/mysys/my_init.c	2008-10-17 02:24:29 +0000
@@ -582,6 +582,10 @@ PSI_mutex_key key_my_thread_var_mutex;
 
 static PSI_mutex_info all_mysys_mutexes[]=
 {
+#if !defined(HAVE_PREAD) && !defined(__WIN__)
+  { & key_my_file_info_mutex,
+    "my_file_info::mutex", 0},
+#endif
 #if !defined(HAVE_LOCALTIME_R) || !defined(HAVE_GMTIME_R)
   { & key_LOCK_localtime_r,
     "LOCK_localtime_r", PSI_FLAG_GLOBAL},

=== modified file 'mysys/my_open.c'
--- a/mysys/my_open.c	2008-10-10 20:34:55 +0000
+++ b/mysys/my_open.c	2008-10-17 02:24:29 +0000
@@ -161,7 +161,8 @@ File my_register_filename(File fd, const
         my_file_total_opened++;
         my_file_info[fd].type = type_of_file;
 #if defined(THREAD) && !defined(HAVE_PREAD) && !defined(__WIN__)
-        pthread_mutex_init(&my_file_info[fd].mutex,MY_MUTEX_INIT_FAST);
+        MYSQL_MUTEX_INIT(&my_file_info[fd].mutex,
+                         key_my_file_info_mutex, MY_MUTEX_INIT_FAST);
 #endif
         MYSQL_MUTEX_UNLOCK(&THR_LOCK_open);
         DBUG_PRINT("exit",("fd: %d",fd));

=== modified file 'mysys/my_pthread.c'
--- a/mysys/my_pthread.c	2008-10-10 20:34:55 +0000
+++ b/mysys/my_pthread.c	2008-10-17 02:24:29 +0000
@@ -300,16 +300,16 @@ int sigwait(sigset_t *setp, int *sigp)
 
 static sigset_t pending_set;
 static bool inited=0;
-static mysql_cond_t  COND_sigwait;
-static mysql_mutex_t LOCK_sigwait;
+static pthread_cond_t  COND_sigwait;
+static pthread_mutex_t LOCK_sigwait;
 
 
 void sigwait_handle_sig(int sig)
 {
-  MYSQL_MUTEX_LOCK(&LOCK_sigwait);
+  pthread_mutex_lock(&LOCK_sigwait);
   sigaddset(&pending_set, sig);
-  MYSQL_COND_SIGNAL(&COND_sigwait); /* inform sigwait() about signal */
-  MYSQL_MUTEX_UNLOCK(&LOCK_sigwait);
+  pthread_cond_signal(&COND_sigwait); /* inform sigwait() about signal */
+  pthread_mutex_unlock(&LOCK_sigwait);
 }
 
 void *sigwait_thread(void *set_arg)
@@ -369,7 +369,7 @@ int sigwait(sigset_t *setp, int *sigp)
     pthread_attr_destroy(&thr_attr);
   }
 
-  MYSQL_MUTEX_LOCK(&LOCK_sigwait);
+  pthread_mutex_lock(&LOCK_sigwait);
   for (;;)
   {
     ulong *ptr= (ulong*) &pending_set;
@@ -388,11 +388,11 @@ int sigwait(sigset_t *setp, int *sigp)
 	}
 	*sigp=found;
 	sigdelset(&pending_set,found);
-	MYSQL_MUTEX_UNLOCK(&LOCK_sigwait);
+	pthread_mutex_unlock(&LOCK_sigwait);
 	return 0;
       }
     }
-    MYSQL_COND_WAIT(&COND_sigwait,&LOCK_sigwait);
+    pthread_cond_wait(&COND_sigwait,&LOCK_sigwait);
   }
   return 0;
 }
@@ -408,17 +408,17 @@ int sigwait(sigset_t *setp, int *sigp)
 
 /* Undefined wrappers set my_pthread.h so that we call os functions */
 #undef pthread_mutex_init
-#undef MYSQL_MUTEX_LOCK
-#undef MYSQL_MUTEX_UNLOCK
-#undef MYSQL_MUTEX_DESTROY
+#undef pthread_mutex_lock
+#undef pthread_mutex_unlock
+#undef pthread_mutex_destroy
 #undef pthread_mutex_wait
-#undef mysql_mutex_timedwait
-#undef mysql_mutex_trylock
-#undef mysql_mutex_t
+#undef pthread_mutex_timedwait
+#undef pthread_mutex_trylock
+#undef pthread_mutex_t
 #undef pthread_cond_init
-#undef MYSQL_COND_WAIT
-#undef MYSQL_COND_TIMEDWAIT
-#undef mysql_cond_t
+#undef pthread_cond_wait
+#undef pthread_cond_timedwait
+#undef pthread_cond_t
 #undef pthread_attr_getstacksize
 
 /*****************************************************************************
@@ -429,7 +429,7 @@ int sigwait(sigset_t *setp, int *sigp)
 
 #include <netdb.h>
 
-int my_pthread_mutex_init(mysql_mutex_t *mp, const pthread_mutexattr_t *attr)
+int my_pthread_mutex_init(pthread_mutex_t *mp, const pthread_mutexattr_t *attr)
 {
   int error;
   if (!attr)
@@ -439,7 +439,7 @@ int my_pthread_mutex_init(mysql_mutex_t 
   return error;
 }
 
-int my_pthread_cond_init(mysql_cond_t *mp, const pthread_condattr_t *attr)
+int my_pthread_cond_init(pthread_cond_t *mp, const pthread_condattr_t *attr)
 {
   int error;
   if (!attr)
@@ -464,10 +464,10 @@ int my_pthread_cond_init(mysql_cond_t *m
 
 #if defined(HPUX10) || defined(HAVE_BROKEN_PTHREAD_COND_TIMEDWAIT)
 
-int my_MYSQL_COND_TIMEDWAIT(mysql_cond_t *cond, mysql_mutex_t *mutex,
+int my_pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex,
 			      struct timespec *abstime)
 {
-  int error=MYSQL_COND_TIMEDWAIT(cond, mutex, abstime);
+  int error=pthread_cond_timedwait(cond, mutex, abstime);
   if (error == -1)			/* Safety if the lib is fixed */
   {
     if (!(error=errno))
@@ -492,8 +492,8 @@ void my_pthread_attr_getstacksize(pthrea
 #ifdef HAVE_POSIX1003_4a_MUTEX
 /*
   In HP-UX-10.20 and other old Posix 1003.4a Draft 4 implementations
-  mysql_mutex_trylock returns 1 on success, not 0 like
-  MYSQL_MUTEX_LOCK
+  pthread_mutex_trylock returns 1 on success, not 0 like
+  pthread_mutex_lock
 
   From the HP-UX-10.20 man page:
   RETURN VALUES
@@ -509,18 +509,18 @@ void my_pthread_attr_getstacksize(pthrea
 */
 
 /*
-  Convert mysql_mutex_trylock to return values according to latest POSIX
+  Convert pthread_mutex_trylock to return values according to latest POSIX
 
   RETURN VALUES
   0		If we are able successfully lock the mutex.
   EBUSY		Mutex was locked by another thread
-  #		Other error number returned by mysql_mutex_trylock()
+  #		Other error number returned by pthread_mutex_trylock()
 		(Not likely)  
 */
 
-int my_mysql_mutex_trylock(mysql_mutex_t *mutex)
+int my_pthread_mutex_trylock(pthread_mutex_t *mutex)
 {
-  int error= mysql_mutex_trylock(mutex);
+  int error= pthread_mutex_trylock(mutex);
   if (error == 1)
     return 0;				/* Got lock on mutex */
   if (error == 0)			/* Someon else is locking mutex */

=== modified file 'mysys/mysys_priv.h'
--- a/mysys/mysys_priv.h	2008-10-14 17:30:16 +0000
+++ b/mysys/mysys_priv.h	2008-10-17 02:24:29 +0000
@@ -56,6 +56,9 @@ extern PSI_mutex_key key_THR_LOCK_thread
 extern PSI_cond_key key_THR_COND_threads;
 extern PSI_mutex_key key_my_thread_var_mutex;
 extern PSI_cond_key key_my_thread_var_suspend;
+#if !defined(HAVE_PREAD) && !defined(__WIN__)
+extern PSI_mutex_key key_my_file_info_mutex;
+#endif
 #if !defined(HAVE_LOCALTIME_R) || !defined(HAVE_GMTIME_R)
 extern PSI_mutex_key key_LOCK_localtime_r;
 #endif

=== modified file 'mysys/thr_alarm.c'
--- a/mysys/thr_alarm.c	2008-10-14 01:55:03 +0000
+++ b/mysys/thr_alarm.c	2008-10-17 02:24:29 +0000
@@ -888,8 +888,8 @@ int main(int argc __attribute__((unused)
   {
     DBUG_PUSH(argv[1]+2);
   }
-  pthread_mutex_init(&LOCK_thread_count,MY_MUTEX_INIT_FAST);
-  pthread_cond_init(&COND_thread_count,NULL);
+  MYSQL_MUTEX_INIT(&LOCK_thread_count, 0, MY_MUTEX_INIT_FAST);
+  MYSQL_COND_INIT(&COND_thread_count, 0, NULL);
 
   /* Start a alarm handling thread */
   sigemptyset(&set);

=== modified file 'mysys/thr_lock.c'
--- a/mysys/thr_lock.c	2008-10-14 01:55:03 +0000
+++ b/mysys/thr_lock.c	2008-10-17 02:24:29 +0000
@@ -1734,13 +1734,13 @@ int main(int argc __attribute__((unused)
 
   printf("Main thread: %s\n",my_thread_name());
 
-  if ((error=pthread_cond_init(&COND_thread_count,NULL)))
+  if ((error= MYSQL_COND_INIT(&COND_thread_count, 0, NULL)))
   {
     fprintf(stderr,"Got error: %d from pthread_cond_init (errno: %d)",
 	    error,errno);
     exit(1);
   }
-  if ((error=pthread_mutex_init(&LOCK_thread_count,MY_MUTEX_INIT_FAST)))
+  if ((error= MYSQL_MUTEX_INIT(&LOCK_thread_count, 0, MY_MUTEX_INIT_FAST)))
   {
     fprintf(stderr,"Got error: %d from pthread_cond_init (errno: %d)",
 	    error,errno);

=== modified file 'storage/archive/azio.c'
--- a/storage/archive/azio.c	2008-05-08 16:01:15 +0000
+++ b/storage/archive/azio.c	2008-10-17 02:24:29 +0000
@@ -17,6 +17,11 @@
 #include <string.h>
 #include <assert.h>
 
+#ifdef HAVE_PSI_INTERFACE
+PSI_mutex_key key_azio_container_thresh_mutex;
+PSI_cond_key key_azio_container_threshhold;
+#endif
+
 static int const az_magic[3] = {0xfe, 0x03, 0x01}; /* az magic header */
 
 /* gzip flag uchar */
@@ -54,15 +59,15 @@ static pthread_handler_t run_task(void *
 
   while (1)
   {
-    pthread_mutex_lock(&s->container.thresh_mutex);
+    MYSQL_MUTEX_LOCK(&s->container.thresh_mutex);
     while (s->container.ready == AZ_THREAD_FINISHED)
     {
-      pthread_cond_wait(&s->container.threshhold, &s->container.thresh_mutex);
+      MYSQL_COND_WAIT(&s->container.threshhold, &s->container.thresh_mutex);
     }
     offset= s->container.offset;
     fd= s->container.fd;
     buffer= s->container.buffer;
-    pthread_mutex_unlock(&s->container.thresh_mutex);
+    MYSQL_MUTEX_UNLOCK(&s->container.thresh_mutex);
 
     if (s->container.ready == AZ_THREAD_DEAD)
       break;
@@ -70,9 +75,9 @@ static pthread_handler_t run_task(void *
     s->container.read_size= my_pread(fd, (uchar *)buffer, AZ_BUFSIZE_READ, 
                                      offset, MYF(0));
 
-    pthread_mutex_lock(&s->container.thresh_mutex);
+    MYSQL_MUTEX_LOCK(&s->container.thresh_mutex);
     s->container.ready= AZ_THREAD_FINISHED; 
-    pthread_mutex_unlock(&s->container.thresh_mutex);
+    MYSQL_MUTEX_UNLOCK(&s->container.thresh_mutex);
   }
 
   my_thread_end();
@@ -82,11 +87,11 @@ static pthread_handler_t run_task(void *
 
 static void azio_kill(azio_stream *s)
 {
-  pthread_mutex_lock(&s->container.thresh_mutex);
+  MYSQL_MUTEX_LOCK(&s->container.thresh_mutex);
   s->container.ready= AZ_THREAD_DEAD; 
-  pthread_mutex_unlock(&s->container.thresh_mutex);
+  MYSQL_MUTEX_UNLOCK(&s->container.thresh_mutex);
 
-  pthread_cond_signal(&s->container.threshhold);
+  MYSQL_COND_SIGNAL(&s->container.threshhold);
   pthread_join(s->container.mainthread, (void *)NULL);
 }
 
@@ -106,9 +111,9 @@ static az_thread_type azio_ready(azio_st
 
   while (1)
   {
-    pthread_mutex_lock(&s->container.thresh_mutex);
+    MYSQL_MUTEX_LOCK(&s->container.thresh_mutex);
     temp= s->container.ready;
-    pthread_mutex_unlock(&s->container.thresh_mutex);
+    MYSQL_MUTEX_UNLOCK(&s->container.thresh_mutex);
 
     if (temp == AZ_THREAD_FINISHED || temp == AZ_THREAD_DEAD)
       break;
@@ -139,10 +144,10 @@ static int azio_start(azio_stream *s)
 
 static int azio_read(azio_stream *s)
 {
-  pthread_mutex_lock(&s->container.thresh_mutex);
+  MYSQL_MUTEX_LOCK(&s->container.thresh_mutex);
   s->container.ready= AZ_THREAD_ACTIVE; 
-  pthread_mutex_unlock(&s->container.thresh_mutex);
-  pthread_cond_broadcast(&s->container.threshhold);
+  MYSQL_MUTEX_UNLOCK(&s->container.thresh_mutex);
+  MYSQL_COND_BROADCAST(&s->container.threshhold);
 
   return 0;
 }
@@ -706,8 +711,10 @@ int do_flush (azio_stream *s, int flush)
 
 static unsigned int azio_enable_aio(azio_stream *s)
 {
-  pthread_cond_init(&s->container.threshhold, NULL);
-  pthread_mutex_init(&s->container.thresh_mutex, NULL);
+  MYSQL_COND_INIT(&s->container.threshhold,
+                  key_azio_container_threshhold, NULL);
+  MYSQL_MUTEX_INIT(&s->container.thresh_mutex,
+                  key_azio_container_thresh_mutex, NULL);
   azio_start(s);
 
   return 0;
@@ -717,8 +724,8 @@ void azio_disable_aio(azio_stream *s)
 {
   azio_kill(s);
 
-  pthread_mutex_destroy(&s->container.thresh_mutex);
-  pthread_cond_destroy(&s->container.threshhold);
+  MYSQL_MUTEX_DESTROY(&s->container.thresh_mutex);
+  MYSQL_COND_DESTROY(&s->container.threshhold);
 
   s->method= AZ_METHOD_BLOCK;
 }

=== modified file 'storage/archive/azio.h'
--- a/storage/archive/azio.h	2008-04-17 20:54:31 +0000
+++ b/storage/archive/azio.h	2008-10-17 02:24:29 +0000
@@ -236,11 +236,15 @@ struct azio_container_st {
   size_t offset;
   size_t read_size;
   void *buffer;
-  pthread_mutex_t thresh_mutex;
-  pthread_cond_t threshhold;
+  mysql_mutex_t thresh_mutex;
+  mysql_cond_t threshhold;
   pthread_t mainthread;            /* Thread descriptor */
 };
 
+#ifdef HAVE_PSI_INTERFACE
+extern PSI_mutex_key key_azio_container_thresh_mutex;
+extern PSI_cond_key key_azio_container_threshhold;
+#endif
 
 typedef struct azio_stream {
   z_stream stream;

=== modified file 'storage/archive/ha_archive.cc'
--- a/storage/archive/ha_archive.cc	2008-06-05 16:11:22 +0000
+++ b/storage/archive/ha_archive.cc	2008-10-17 02:24:29 +0000
@@ -21,6 +21,7 @@
 #include <myisam.h>
 
 #include "ha_archive.h"
+#include "azio.h"
 #include <my_dir.h>
 
 #include <mysql/plugin.h>
@@ -94,7 +95,7 @@
 */
 
 /* Variables for archive share methods */
-pthread_mutex_t archive_mutex;
+mysql_mutex_t archive_mutex;
 static HASH archive_open_tables;
 static unsigned int global_version;
 
@@ -147,6 +148,42 @@ static uchar* archive_get_key(ARCHIVE_SH
   return (uchar*) share->table_name;
 }
 
+#ifdef HAVE_PSI_INTERFACE
+PSI_mutex_key key_archive_mutex;
+PSI_mutex_key key_ARCHIVE_SHARE_mutex;
+
+static PSI_mutex_info all_archive_mutexes[]=
+{
+  { & key_archive_mutex,
+    "archive_mutex", PSI_FLAG_GLOBAL},
+  { & key_ARCHIVE_SHARE_mutex,
+    "ARCHIVE_SHARE::mutex", 0},
+  { & key_azio_container_thresh_mutex,
+    "azio_container::thresh_mutex", 0},
+};
+
+static PSI_cond_info all_archive_conds[]=
+{
+  { & key_azio_container_threshhold,
+    "azio_container::threshhold", 0}
+};
+
+void init_archive_psi_keys()
+{
+  const char* category= "archive";
+  int count;
+
+  if (PSI_server == NULL)
+    return;
+
+  count= sizeof(all_archive_mutexes)/sizeof(all_archive_mutexes[0]);
+  PSI_server->register_mutex(category, all_archive_mutexes, count);
+
+  count= sizeof(all_archive_conds)/sizeof(all_archive_conds[0]);
+  PSI_server->register_cond(category, all_archive_conds, count);
+}
+#endif
+
 
 /*
   Initialize the archive handler.
@@ -165,6 +202,10 @@ int archive_db_init(void *p)
   DBUG_ENTER("archive_db_init");
   handlerton *archive_hton;
 
+#ifdef HAVE_PSI_INTERFACE
+  init_archive_psi_keys();
+#endif
+
   archive_hton= (handlerton *)p;
   archive_hton->state= SHOW_OPTION_YES;
   archive_hton->db_type= DB_TYPE_ARCHIVE_DB;
@@ -175,12 +216,12 @@ int archive_db_init(void *p)
   /* When the engine starts up set the first version */
   global_version= 1;
 
-  if (pthread_mutex_init(&archive_mutex, MY_MUTEX_INIT_FAST))
+  if (MYSQL_MUTEX_INIT(&archive_mutex, key_archive_mutex, MY_MUTEX_INIT_FAST))
     goto error;
   if (hash_init(&archive_open_tables, system_charset_info, 32, 0, 0,
                 (hash_get_key) archive_get_key, 0, 0))
   {
-    pthread_mutex_destroy(&archive_mutex);
+    MYSQL_MUTEX_DESTROY(&archive_mutex);
   }
   else
   {
@@ -204,7 +245,7 @@ error:
 int archive_db_done(void *p)
 {
   hash_free(&archive_open_tables);
-  pthread_mutex_destroy(&archive_mutex);
+  MYSQL_MUTEX_DESTROY(&archive_mutex);
 
   return 0;
 }
@@ -290,7 +331,7 @@ ARCHIVE_SHARE *ha_archive::get_share(con
   uint length;
   DBUG_ENTER("ha_archive::get_share");
 
-  pthread_mutex_lock(&archive_mutex);
+  MYSQL_MUTEX_LOCK(&archive_mutex);
   length=(uint) strlen(table_name);
 
   if (!(share=(ARCHIVE_SHARE*) hash_search(&archive_open_tables,
@@ -305,7 +346,7 @@ ARCHIVE_SHARE *ha_archive::get_share(con
                           &tmp_name, length+1,
                           NullS)) 
     {
-      pthread_mutex_unlock(&archive_mutex);
+      MYSQL_MUTEX_UNLOCK(&archive_mutex);
       *rc= HA_ERR_OUT_OF_MEM;
       DBUG_RETURN(NULL);
     }
@@ -323,8 +364,9 @@ ARCHIVE_SHARE *ha_archive::get_share(con
     /*
       We will use this lock for rows.
     */
-    pthread_mutex_init(&share->mutex,MY_MUTEX_INIT_FAST);
-    
+    MYSQL_MUTEX_INIT(&share->mutex,
+                     key_ARCHIVE_SHARE_mutex, MY_MUTEX_INIT_FAST);
+
     /*
       We read the meta file, but do not mark it dirty. Since we are not
       doing a write we won't mark it dirty (and we won't open it for
@@ -334,9 +376,9 @@ ARCHIVE_SHARE *ha_archive::get_share(con
     if (!(azopen(&archive_tmp, share->data_file_name, O_RDONLY|O_BINARY,
                  AZ_METHOD_BLOCK)))
     {
-      pthread_mutex_destroy(&share->mutex);
+      MYSQL_MUTEX_DESTROY(&share->mutex);
       free(share);
-      pthread_mutex_unlock(&archive_mutex);
+      MYSQL_MUTEX_UNLOCK(&archive_mutex);
       *rc= HA_ERR_CRASHED_ON_REPAIR;
       DBUG_RETURN(NULL);
     }
@@ -359,7 +401,7 @@ ARCHIVE_SHARE *ha_archive::get_share(con
                       share->use_count));
   if (share->crashed)
     *rc= HA_ERR_CRASHED_ON_USAGE;
-  pthread_mutex_unlock(&archive_mutex);
+  MYSQL_MUTEX_UNLOCK(&archive_mutex);
 
   DBUG_RETURN(share);
 }
@@ -378,12 +420,12 @@ int ha_archive::free_share()
               share->table_name_length, share->table_name,
               share->use_count));
 
-  pthread_mutex_lock(&archive_mutex);
+  MYSQL_MUTEX_LOCK(&archive_mutex);
   if (!--share->use_count)
   {
     hash_delete(&archive_open_tables, (uchar*) share);
     thr_lock_delete(&share->lock);
-    pthread_mutex_destroy(&share->mutex);
+    MYSQL_MUTEX_DESTROY(&share->mutex);
     /* 
       We need to make sure we don't reset the crashed state.
       If we open a crashed file, wee need to close it as crashed unless
@@ -398,7 +440,7 @@ int ha_archive::free_share()
     }
     my_free((uchar*) share, MYF(0));
   }
-  pthread_mutex_unlock(&archive_mutex);
+  MYSQL_MUTEX_UNLOCK(&archive_mutex);
 
   DBUG_RETURN(rc);
 }
@@ -799,7 +841,7 @@ int ha_archive::write_row(uchar *buf)
   ha_statistic_increment(&SSV::ha_write_count);
   if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_INSERT)
     table->timestamp_field->set_time();
-  pthread_mutex_lock(&share->mutex);
+  MYSQL_MUTEX_LOCK(&share->mutex);
 
   if (share->archive_write_open == FALSE)
     if (init_archive_writer())
@@ -882,7 +924,7 @@ int ha_archive::write_row(uchar *buf)
   share->rows_recorded++;
   rc= real_write_row(buf,  &(share->archive_write));
 error:
-  pthread_mutex_unlock(&share->mutex);
+  MYSQL_MUTEX_UNLOCK(&share->mutex);
   if (read_buf)
     my_free((uchar*) read_buf, MYF(0));
 
@@ -1354,7 +1396,7 @@ int ha_archive::info(uint flag)
     If dirty, we lock, and then reset/flush the data.
     I found that just calling azflush() doesn't always work.
   */
-  pthread_mutex_lock(&share->mutex);
+  MYSQL_MUTEX_LOCK(&share->mutex);
   if (share->dirty == TRUE)
   {
     DBUG_PRINT("ha_archive", ("archive flushing out rows for scan"));
@@ -1374,7 +1416,7 @@ int ha_archive::info(uint flag)
     cause the number to be inaccurate.
   */
   stats.records= share->rows_recorded;
-  pthread_mutex_unlock(&share->mutex);
+  MYSQL_MUTEX_UNLOCK(&share->mutex);
 
   scan_rows= stats.records;
   stats.deleted= 0;
@@ -1399,9 +1441,9 @@ int ha_archive::info(uint flag)
   if (flag & HA_STATUS_AUTO)
   {
     init_archive_reader();
-    pthread_mutex_lock(&share->mutex);
+    MYSQL_MUTEX_LOCK(&share->mutex);
     azflush(&archive, Z_SYNC_FLUSH);
-    pthread_mutex_unlock(&share->mutex);
+    MYSQL_MUTEX_UNLOCK(&share->mutex);
     stats.auto_increment_value= archive.auto_increment + 1;
   }
 
@@ -1469,9 +1511,9 @@ int ha_archive::check(THD* thd, HA_CHECK
 
   old_proc_info= thd_proc_info(thd, "Checking table");
   /* Flush any waiting data */
-  pthread_mutex_lock(&share->mutex);
+  MYSQL_MUTEX_LOCK(&share->mutex);
   azflush(&(share->archive_write), Z_SYNC_FLUSH);
-  pthread_mutex_unlock(&share->mutex);
+  MYSQL_MUTEX_UNLOCK(&share->mutex);
 
   /*
     Now we will rewind the archive file so that we are positioned at the 

=== modified file 'storage/archive/ha_archive.h'
--- a/storage/archive/ha_archive.h	2008-06-05 16:11:22 +0000
+++ b/storage/archive/ha_archive.h	2008-10-17 02:24:29 +0000
@@ -36,7 +36,7 @@ typedef struct st_archive_share {
   char *table_name;
   char data_file_name[FN_REFLEN];
   uint table_name_length,use_count;
-  pthread_mutex_t mutex;
+  mysql_mutex_t mutex;
   THR_LOCK lock;
   azio_stream archive_write;     /* Archive file we are working with */
   bool archive_write_open;

=== modified file 'storage/blackhole/ha_blackhole.cc'
--- a/storage/blackhole/ha_blackhole.cc	2008-04-25 16:43:25 +0000
+++ b/storage/blackhole/ha_blackhole.cc	2008-10-17 02:24:29 +0000
@@ -33,7 +33,7 @@ static handler *blackhole_create_handler
 
 /* Static declarations for shared structures */
 
-static pthread_mutex_t blackhole_mutex;
+static mysql_mutex_t blackhole_mutex;
 static HASH blackhole_open_tables;
 
 static st_blackhole_share *get_share(const char *table_name);
@@ -244,7 +244,7 @@ static st_blackhole_share *get_share(con
   uint length;
 
   length= (uint) strlen(table_name);
-  pthread_mutex_lock(&blackhole_mutex);
+  MYSQL_MUTEX_LOCK(&blackhole_mutex);
     
   if (!(share= (st_blackhole_share*) hash_search(&blackhole_open_tables,
                                                  (uchar*) table_name, length)))
@@ -269,16 +269,16 @@ static st_blackhole_share *get_share(con
   share->use_count++;
   
 error:
-  pthread_mutex_unlock(&blackhole_mutex);
+  MYSQL_MUTEX_UNLOCK(&blackhole_mutex);
   return share;
 }
 
 static void free_share(st_blackhole_share *share)
 {
-  pthread_mutex_lock(&blackhole_mutex);
+  MYSQL_MUTEX_LOCK(&blackhole_mutex);
   if (!--share->use_count)
     hash_delete(&blackhole_open_tables, (uchar*) share);
-  pthread_mutex_unlock(&blackhole_mutex);
+  MYSQL_MUTEX_UNLOCK(&blackhole_mutex);
 }
 
 static void blackhole_free_key(st_blackhole_share *share)
@@ -294,16 +294,43 @@ static uchar* blackhole_get_key(st_black
   return (uchar*) share->table_name;
 }
 
+#ifdef HAVE_PSI_INTERFACE
+PSI_mutex_key key_blackhole_mutex;
+
+static PSI_mutex_info all_blackhole_mutexes[]=
+{
+  { & key_blackhole_mutex,
+    "key_blackhole_mutex", PSI_FLAG_GLOBAL},
+};
+
+void init_blackhole_psi_keys()
+{
+  const char* category= "blackhole";
+  int count;
+
+  if (PSI_server == NULL)
+    return;
+
+  count= sizeof(all_blackhole_mutexes)/sizeof(all_blackhole_mutexes[0]);
+  PSI_server->register_mutex(category, all_blackhole_mutexes, count);
+}
+#endif
+
 static int blackhole_init(void *p)
 {
   handlerton *blackhole_hton;
+
+#ifdef HAVE_PSI_INTERFACE
+  init_blackhole_psi_keys();
+#endif
+
   blackhole_hton= (handlerton *)p;
   blackhole_hton->state= SHOW_OPTION_YES;
   blackhole_hton->db_type= DB_TYPE_BLACKHOLE_DB;
   blackhole_hton->create= blackhole_create_handler;
   blackhole_hton->flags= HTON_CAN_RECREATE;
   
-  pthread_mutex_init(&blackhole_mutex, MY_MUTEX_INIT_FAST);
+  MYSQL_MUTEX_INIT(&blackhole_mutex, key_blackhole_mutex, MY_MUTEX_INIT_FAST);
   (void) hash_init(&blackhole_open_tables, system_charset_info,32,0,0,
                    (hash_get_key) blackhole_get_key,
                    (hash_free_key) blackhole_free_key, 0);
@@ -314,7 +341,7 @@ static int blackhole_init(void *p)
 static int blackhole_fini(void *p)
 {
   hash_free(&blackhole_open_tables);
-  pthread_mutex_destroy(&blackhole_mutex);
+  MYSQL_MUTEX_DESTROY(&blackhole_mutex);
 
   return 0;
 }

=== modified file 'storage/csv/ha_tina.cc'
--- a/storage/csv/ha_tina.cc	2008-08-15 18:34:18 +0000
+++ b/storage/csv/ha_tina.cc	2008-10-17 02:24:29 +0000
@@ -74,7 +74,7 @@ extern "C" void tina_update_status(void*
 extern "C" my_bool tina_check_status(void* param);
 
 /* Stuff for shares */
-pthread_mutex_t tina_mutex;
+mysql_mutex_t tina_mutex;
 static HASH tina_open_tables;
 static handler *tina_create_handler(handlerton *hton,
                                     TABLE_SHARE *table, 
@@ -104,12 +104,41 @@ static uchar* tina_get_key(TINA_SHARE *s
   return (uchar*) share->table_name;
 }
 
+#ifdef HAVE_PSI_INTERFACE
+PSI_mutex_key key_tina_mutex;
+PSI_mutex_key key_TINA_SHARE_mutex;
+
+static PSI_mutex_info all_tina_mutexes[]=
+{
+  { & key_tina_mutex,
+    "tina_mutex", PSI_FLAG_GLOBAL},
+  { & key_TINA_SHARE_mutex,
+    "TINA_SHARE::mutex", 0}
+};
+
+void init_tina_psi_keys()
+{
+  const char* category= "tina";
+  int count;
+
+  if (PSI_server == NULL)
+    return;
+
+  count= sizeof(all_tina_mutexes)/sizeof(all_tina_mutexes[0]);
+  PSI_server->register_mutex(category, all_tina_mutexes, count);
+}
+#endif
+
 static int tina_init_func(void *p)
 {
   handlerton *tina_hton;
 
+#ifdef HAVE_PSI_INTERFACE
+  init_tina_psi_keys();
+#endif
+
   tina_hton= (handlerton *)p;
-  pthread_mutex_init(&tina_mutex,MY_MUTEX_INIT_FAST);
+  MYSQL_MUTEX_INIT(&tina_mutex, key_tina_mutex, MY_MUTEX_INIT_FAST);
   (void) hash_init(&tina_open_tables,system_charset_info,32,0,0,
                    (hash_get_key) tina_get_key,0,0);
   tina_hton->state= SHOW_OPTION_YES;
@@ -123,7 +152,7 @@ static int tina_init_func(void *p)
 static int tina_done_func(void *p)
 {
   hash_free(&tina_open_tables);
-  pthread_mutex_destroy(&tina_mutex);
+  MYSQL_MUTEX_DESTROY(&tina_mutex);
 
   return 0;
 }
@@ -140,7 +169,7 @@ static TINA_SHARE *get_share(const char 
   char *tmp_name;
   uint length;
 
-  pthread_mutex_lock(&tina_mutex);
+  MYSQL_MUTEX_LOCK(&tina_mutex);
   length=(uint) strlen(table_name);
 
   /*
@@ -156,7 +185,7 @@ static TINA_SHARE *get_share(const char 
                          &tmp_name, length+1,
                          NullS))
     {
-      pthread_mutex_unlock(&tina_mutex);
+      MYSQL_MUTEX_UNLOCK(&tina_mutex);
       return NULL;
     }
 
@@ -182,7 +211,7 @@ static TINA_SHARE *get_share(const char 
     if (my_hash_insert(&tina_open_tables, (uchar*) share))
       goto error;
     thr_lock_init(&share->lock);
-    pthread_mutex_init(&share->mutex,MY_MUTEX_INIT_FAST);
+    MYSQL_MUTEX_INIT(&share->mutex, key_TINA_SHARE_mutex, MY_MUTEX_INIT_FAST);
 
     /*
       Open or create the meta file. In the latter case, we'll get
@@ -197,12 +226,12 @@ static TINA_SHARE *get_share(const char 
   }
 
   share->use_count++;
-  pthread_mutex_unlock(&tina_mutex);
+  MYSQL_MUTEX_UNLOCK(&tina_mutex);
 
   return share;
 
 error:
-  pthread_mutex_unlock(&tina_mutex);
+  MYSQL_MUTEX_UNLOCK(&tina_mutex);
   my_free((uchar*) share, MYF(0));
 
   return NULL;
@@ -361,7 +390,7 @@ bool ha_tina::is_crashed() const
 static int free_share(TINA_SHARE *share)
 {
   DBUG_ENTER("ha_tina::free_share");
-  pthread_mutex_lock(&tina_mutex);
+  MYSQL_MUTEX_LOCK(&tina_mutex);
   int result_code= 0;
   if (!--share->use_count){
     /* Write the meta file. Mark it as crashed if needed. */
@@ -378,10 +407,10 @@ static int free_share(TINA_SHARE *share)
 
     hash_delete(&tina_open_tables, (uchar*) share);
     thr_lock_delete(&share->lock);
-    pthread_mutex_destroy(&share->mutex);
+    MYSQL_MUTEX_DESTROY(&share->mutex);
     my_free((uchar*) share, MYF(0));
   }
-  pthread_mutex_unlock(&tina_mutex);
+  MYSQL_MUTEX_UNLOCK(&tina_mutex);
 
   DBUG_RETURN(result_code);
 }
@@ -768,9 +797,9 @@ void ha_tina::get_status()
       We have to use mutex to follow pthreads memory visibility
       rules for share->saved_data_file_length
     */
-    pthread_mutex_lock(&share->mutex);
+    MYSQL_MUTEX_LOCK(&share->mutex);
     local_saved_data_file_length= share->saved_data_file_length;
-    pthread_mutex_unlock(&share->mutex);
+    MYSQL_MUTEX_UNLOCK(&share->mutex);
     return;
   }
   local_saved_data_file_length= share->saved_data_file_length;
@@ -892,12 +921,12 @@ int ha_tina::write_row(uchar * buf)
   local_saved_data_file_length+= size;
 
   /* update shared info */
-  pthread_mutex_lock(&share->mutex);
+  MYSQL_MUTEX_LOCK(&share->mutex);
   share->rows_recorded++;
   /* update status for the log tables */
   if (share->is_log_table)
     update_status();
-  pthread_mutex_unlock(&share->mutex);
+  MYSQL_MUTEX_UNLOCK(&share->mutex);
 
   stats.records++;
   DBUG_RETURN(0);
@@ -991,9 +1020,9 @@ int ha_tina::delete_row(const uchar * bu
   stats.records--;
   /* Update shared info */
   DBUG_ASSERT(share->rows_recorded);
-  pthread_mutex_lock(&share->mutex);
+  MYSQL_MUTEX_LOCK(&share->mutex);
   share->rows_recorded--;
-  pthread_mutex_unlock(&share->mutex);
+  MYSQL_MUTEX_UNLOCK(&share->mutex);
 
   /* DELETE should never happen on the log table */
   DBUG_ASSERT(!share->is_log_table);
@@ -1167,9 +1196,9 @@ int ha_tina::extra(enum ha_extra_functio
   DBUG_ENTER("ha_tina::extra");
  if (operation == HA_EXTRA_MARK_AS_LOG_TABLE)
  {
-   pthread_mutex_lock(&share->mutex);
+   MYSQL_MUTEX_LOCK(&share->mutex);
    share->is_log_table= TRUE;
-   pthread_mutex_unlock(&share->mutex);
+   MYSQL_MUTEX_UNLOCK(&share->mutex);
  }
   DBUG_RETURN(0);
 }
@@ -1475,9 +1504,9 @@ int ha_tina::delete_all_rows()
 
   stats.records=0;
   /* Update shared info */
-  pthread_mutex_lock(&share->mutex);
+  MYSQL_MUTEX_LOCK(&share->mutex);
   share->rows_recorded= 0;
-  pthread_mutex_unlock(&share->mutex);
+  MYSQL_MUTEX_UNLOCK(&share->mutex);
   local_saved_data_file_length= 0;
   DBUG_RETURN(rc);
 }

=== modified file 'storage/csv/ha_tina.h'
--- a/storage/csv/ha_tina.h	2008-06-28 11:00:59 +0000
+++ b/storage/csv/ha_tina.h	2008-10-17 02:24:29 +0000
@@ -41,7 +41,7 @@ typedef struct st_tina_share {
     share initialization.
   */
   off_t saved_data_file_length;
-  pthread_mutex_t mutex;
+  mysql_mutex_t mutex;
   THR_LOCK lock;
   bool update_file_opened;
   bool tina_write_opened;

=== modified file 'storage/example/ha_example.cc'
--- a/storage/example/ha_example.cc	2008-04-09 00:56:49 +0000
+++ b/storage/example/ha_example.cc	2008-10-17 02:24:29 +0000
@@ -111,7 +111,7 @@ handlerton *example_hton;
 static HASH example_open_tables;
 
 /* The mutex used to init the hash; variable for example share methods */
-pthread_mutex_t example_mutex;
+mysql_mutex_t example_mutex;
 
 /**
   @brief
@@ -125,13 +125,41 @@ static uchar* example_get_key(EXAMPLE_SH
   return (uchar*) share->table_name;
 }
 
+#ifdef HAVE_PSI_INTERFACE
+PSI_mutex_key key_example_mutex;
+PSI_mutex_key key_EXAMPLE_SHARE_mutex;
+
+static PSI_mutex_info all_example_mutexes[]=
+{
+  { & key_example_mutex,
+    "example_mutex", 0},
+  { & key_EXAMPLE_SHARE_mutex,
+    "EXAMPLE_SHARE::mutex", PSI_FLAG_GLOBAL}
+};
+
+void init_example_psi_keys()
+{
+  const char* category= "example";
+  int count;
+
+  if (PSI_server == NULL)
+    return;
+
+  count= sizeof(all_example_mutexes)/sizeof(all_example_mutexes[0]);
+  PSI_server->register_mutex(category, all_example_mutexes, count);
+}
+#endif
 
 static int example_init_func(void *p)
 {
   DBUG_ENTER("example_init_func");
 
+#ifdef HAVE_PSI_INTERFACE
+  init_example_psi_keys();
+#endif
+
   example_hton= (handlerton *)p;
-  pthread_mutex_init(&example_mutex,MY_MUTEX_INIT_FAST);
+  MYSQL_MUTEX_INIT(&example_mutex, key_example_mutex, MY_MUTEX_INIT_FAST);
   (void) hash_init(&example_open_tables,system_charset_info,32,0,0,
                    (hash_get_key) example_get_key,0,0);
 
@@ -151,7 +179,7 @@ static int example_done_func(void *p)
   if (example_open_tables.records)
     error= 1;
   hash_free(&example_open_tables);
-  pthread_mutex_destroy(&example_mutex);
+  MYSQL_MUTEX_DESTROY(&example_mutex);
 
   DBUG_RETURN(0);
 }
@@ -171,7 +199,7 @@ static EXAMPLE_SHARE *get_share(const ch
   uint length;
   char *tmp_name;
 
-  pthread_mutex_lock(&example_mutex);
+  MYSQL_MUTEX_LOCK(&example_mutex);
   length=(uint) strlen(table_name);
 
   if (!(share=(EXAMPLE_SHARE*) hash_search(&example_open_tables,
@@ -184,7 +212,7 @@ static EXAMPLE_SHARE *get_share(const ch
                           &tmp_name, length+1,
                           NullS)))
     {
-      pthread_mutex_unlock(&example_mutex);
+      MYSQL_MUTEX_UNLOCK(&example_mutex);
       return NULL;
     }
 
@@ -195,15 +223,16 @@ static EXAMPLE_SHARE *get_share(const ch
     if (my_hash_insert(&example_open_tables, (uchar*) share))
       goto error;
     thr_lock_init(&share->lock);
-    pthread_mutex_init(&share->mutex,MY_MUTEX_INIT_FAST);
+    MYSQL_MUTEX_INIT(&share->mutex,
+                     key_EXAMPLE_SHARE_mutex, MY_MUTEX_INIT_FAST);
   }
   share->use_count++;
-  pthread_mutex_unlock(&example_mutex);
+  MYSQL_MUTEX_UNLOCK(&example_mutex);
 
   return share;
 
 error:
-  pthread_mutex_destroy(&share->mutex);
+  MYSQL_MUTEX_DESTROY(&share->mutex);
   my_free(share, MYF(0));
 
   return NULL;
@@ -218,15 +247,15 @@ error:
 
 static int free_share(EXAMPLE_SHARE *share)
 {
-  pthread_mutex_lock(&example_mutex);
+  MYSQL_MUTEX_LOCK(&example_mutex);
   if (!--share->use_count)
   {
     hash_delete(&example_open_tables, (uchar*) share);
     thr_lock_delete(&share->lock);
-    pthread_mutex_destroy(&share->mutex);
+    MYSQL_MUTEX_DESTROY(&share->mutex);
     my_free(share, MYF(0));
   }
-  pthread_mutex_unlock(&example_mutex);
+  MYSQL_MUTEX_UNLOCK(&example_mutex);
 
   return 0;
 }

=== modified file 'storage/example/ha_example.h'
--- a/storage/example/ha_example.h	2007-08-13 13:11:25 +0000
+++ b/storage/example/ha_example.h	2008-10-17 02:24:29 +0000
@@ -42,7 +42,7 @@
 typedef struct st_example_share {
   char *table_name;
   uint table_name_length,use_count;
-  pthread_mutex_t mutex;
+  mysql_mutex_t mutex;
   THR_LOCK lock;
 } EXAMPLE_SHARE;
 

=== modified file 'storage/maria/trnman.c'
--- a/storage/maria/trnman.c	2008-10-15 03:57:32 +0000
+++ b/storage/maria/trnman.c	2008-10-17 02:24:29 +0000
@@ -168,7 +168,7 @@ int trnman_init(TrID initial_trid)
   global_trid_generator= initial_trid;
   lf_hash_init(&trid_to_committed_trn, sizeof(TRN*), LF_HASH_UNIQUE,
                0, 0, trn_get_hash_key, 0);
-  DBUG_PRINT("info", ("pthread_mutex_init LOCK_trn_list"));
+  DBUG_PRINT("info", ("MYSQL_MUTEX_INIT LOCK_trn_list"));
   MYSQL_MUTEX_INIT(&LOCK_trn_list, key_LOCK_trn_list, MY_MUTEX_INIT_FAST);
   my_atomic_rwlock_init(&LOCK_short_trid_to_trn);
   my_atomic_rwlock_init(&LOCK_pool);

Thread
bzr commit into mysql-6.0-perf branch (marc.alff:2709) Marc Alff17 Oct