List:Commits« Previous MessageNext Message »
From:Marc Alff Date:January 9 2012 8:29am
Subject:bzr push into mysql-trunk-marc branch (marc.alff:3584 to 3585)
View as plain text  
 3585 Marc Alff	2012-01-09 [merge]
      Merge mysql-trunk --> mysql-trunk-marc

    modified:
      include/mysql/psi/mysql_socket.h
      include/mysql/psi/mysql_table.h
      include/mysql/psi/mysql_thread.h
      include/mysql/psi/psi.h
      include/mysql/psi/psi_abi_v0.h.pp
      include/mysql/psi/psi_abi_v1.h.pp
      include/mysql/psi/psi_abi_v2.h.pp
      mysql-test/include/show_slave_status.inc
      mysql-test/r/myisampack.result
      mysql-test/suite/binlog/r/binlog_stm_unsafe_warning.result
      mysql-test/suite/binlog/t/binlog_stm_unsafe_warning.test
      mysql-test/suite/engines/funcs/r/tc_rename_error.result
      mysql-test/suite/perfschema/r/dml_handler.result
      mysql-test/suite/perfschema/r/innodb_table_io.result
      mysql-test/suite/perfschema/r/misc.result
      mysql-test/suite/perfschema/r/temp_table_io.result
      mysql-test/suite/perfschema/t/dml_handler.test
      mysql-test/suite/perfschema/t/misc.test
      mysql-test/suite/rpl/r/rpl_log_pos.result
      mysql-test/suite/rpl/r/rpl_manual_change_index_file.result
      mysql-test/suite/rpl/t/rpl_log_pos.test
      mysql-test/suite/rpl/t/rpl_manual_change_index_file.test
      mysql-test/t/myisampack.test
      mysys/psi_noop.c
      sql/handler.cc
      sql/sql_db.cc
      sql/sql_table.cc
      storage/innobase/include/os0sync.ic
      storage/innobase/include/sync0rw.ic
      storage/innobase/include/sync0sync.ic
      storage/perfschema/pfs.cc
      storage/perfschema/pfs_instr.cc
      storage/perfschema/pfs_instr.h
      storage/perfschema/pfs_instr_class.cc
      storage/perfschema/pfs_server.cc
      storage/perfschema/pfs_stat.h
      storage/perfschema/table_events_waits.cc
      storage/perfschema/unittest/pfs-t.cc
 3584 Marc Alff	2012-01-05 [merge]
      Merge mysql-trunk --> mysql-trunk-marc

    modified:
      mysql-test/collections/default.experimental
      mysql-test/r/distinct.result
      mysql-test/r/group_by.result
      mysql-test/r/having.result
      mysql-test/r/innodb_explain_non_select_all.result
      mysql-test/r/innodb_icp.result
      mysql-test/r/innodb_icp_all.result
      mysql-test/r/innodb_icp_none.result
      mysql-test/r/innodb_mrr_all.result
      mysql-test/r/innodb_mrr_cost_all.result
      mysql-test/r/join.result
      mysql-test/r/join_outer.result
      mysql-test/r/join_outer_bka.result
      mysql-test/r/join_outer_bka_nixbnl.result
      mysql-test/r/myisam_icp.result
      mysql-test/r/myisam_icp_all.result
      mysql-test/r/myisam_icp_none.result
      mysql-test/r/select_all_bka.result
      mysql-test/r/select_all_bka_nixbnl.result
      mysql-test/suite/opt_trace/include/general2.inc
      mysql-test/suite/opt_trace/r/general2_no_prot.result
      mysql-test/suite/opt_trace/r/general2_ps_prot.result
      mysql-test/suite/opt_trace/r/temp_table.result
      mysql-test/t/distinct.test
      mysql-test/t/group_by.test
      mysql-test/t/having.test
      mysql-test/t/join.test
      mysql-test/t/join_outer.test
      sql/field.cc
      sql/field.h
      sql/field_conv.cc
      sql/item_sum.cc
      sql/opt_sum.cc
      sql/rpl_slave.cc
      sql/sql_base.cc
      sql/sql_executor.cc
      sql/sql_lex.cc
      sql/sql_optimizer.cc
      sql/sql_parse.cc
      sql/sql_planner.cc
      sql/sql_select.cc
      sql/sql_tmp_table.cc
      sql/table.cc
      sql/table.h
      storage/myisam/mi_create.c
      unittest/gunit/bounded_queue-t.cc
      unittest/gunit/bounds_checked_array-t.cc
      unittest/gunit/cost_estimate-t.cc
      unittest/gunit/dbug-t.cc
      unittest/gunit/dynarray-t.cc
      unittest/gunit/field-t.cc
      unittest/gunit/filesort_buffer-t.cc
      unittest/gunit/get_diagnostics-t.cc
      unittest/gunit/gunit_test_main.cc
      unittest/gunit/item-t.cc
      unittest/gunit/mdl-t.cc
      unittest/gunit/mdl_mytap-t.cc
      unittest/gunit/my_regex-t.cc
      unittest/gunit/opt_range-t.cc
      unittest/gunit/opt_trace-t.cc
      unittest/gunit/sql_list-t.cc
      unittest/gunit/sql_plist-t.cc
      unittest/gunit/stdcxx-t.cc
      unittest/gunit/tap_event_listener.cc
      unittest/gunit/test_utils.cc
      unittest/gunit/thread_utils-t.cc
      unittest/gunit/thread_utils.cc
=== modified file 'include/mysql/psi/mysql_socket.h'
--- a/include/mysql/psi/mysql_socket.h	2011-11-08 15:56:29 +0000
+++ b/include/mysql/psi/mysql_socket.h	2012-01-09 08:27:58 +0000
@@ -120,7 +120,8 @@ mysql_socket_set_address(
 )
 {
 #ifdef HAVE_PSI_SOCKET_INTERFACE
-  PSI_CALL(set_socket_info)(socket.m_psi, NULL, addr, addr_len);
+  if (socket.m_psi != NULL)
+    PSI_CALL(set_socket_info)(socket.m_psi, NULL, addr, addr_len);
 #endif
 }
 
@@ -139,7 +140,8 @@ MYSQL_SOCKET socket __attribute__ ((unus
 )
 {
 #ifdef HAVE_PSI_SOCKET_INTERFACE
-  PSI_CALL(set_socket_thread_owner)(socket.m_psi);
+  if (socket.m_psi != NULL)
+    PSI_CALL(set_socket_thread_owner)(socket.m_psi);
 #endif
 }
 
@@ -243,9 +245,13 @@ inline_mysql_start_socket_wait(PSI_socke
                                const char *src_file, int src_line)
 {
   struct PSI_socket_locker *locker;
-  locker= PSI_CALL(get_thread_socket_locker)(state, mysql_socket.m_psi, op);
-  if (likely(locker != NULL))
-    PSI_CALL(start_socket_wait)(locker, byte_count, src_file, src_line);
+  if (mysql_socket.m_psi != NULL)
+  {
+    locker= PSI_CALL(start_socket_wait)(state, mysql_socket.m_psi, op,
+                                        byte_count, src_file, src_line);
+  }
+  else
+    locker= NULL;
   return locker;
 }
 
@@ -256,7 +262,7 @@ inline_mysql_start_socket_wait(PSI_socke
 static inline void
 inline_mysql_end_socket_wait(struct PSI_socket_locker *locker, size_t byte_count)
 {
-  if (likely(locker != NULL))
+  if (locker != NULL)
     PSI_CALL(end_socket_wait)(locker, byte_count);
 }
 
@@ -269,7 +275,8 @@ inline_mysql_end_socket_wait(struct PSI_
 static inline void
 inline_mysql_socket_set_state(MYSQL_SOCKET socket, enum PSI_socket_state state)
 {
-  PSI_CALL(set_socket_state)(socket.m_psi, state);
+  if (socket.m_psi != NULL)
+    PSI_CALL(set_socket_state)(socket.m_psi, state);
 }
 #endif /* HAVE_PSI_SOCKET_INTERFACE */
 
@@ -569,20 +576,30 @@ inline_mysql_socket_bind
   MYSQL_SOCKET mysql_socket, const struct sockaddr *addr, socklen_t len)
 {
   int result;
+
 #ifdef HAVE_PSI_SOCKET_INTERFACE
-  PSI_socket_locker_state state;
-  struct PSI_socket_locker *locker;
-  locker= PSI_CALL(get_thread_socket_locker)(&state, mysql_socket.m_psi,
-                                             PSI_SOCKET_BIND);
-  if (likely(locker != NULL))
+  if (mysql_socket.m_psi != NULL)
   {
-    PSI_CALL(start_socket_wait)(locker, (size_t)0, src_file, src_line);
+    /* Instrumentation start */
+    PSI_socket_locker_state state;
+    PSI_socket_locker *locker;
+    locker= PSI_CALL(start_socket_wait)(&state, mysql_socket.m_psi,
+                                        PSI_SOCKET_BIND, (size_t)0, src_file, src_line);
+
+    /* Instrumented code */
     result= bind(mysql_socket.fd, addr, len);
+
+    /* Instrumentation end */
     PSI_CALL(set_socket_info)(mysql_socket.m_psi, NULL, addr, len);
-    PSI_CALL(end_socket_wait)(locker, (size_t)0);
+
+    if (locker != NULL)
+      PSI_CALL(end_socket_wait)(locker, (size_t)0);
+
     return result;
   }
 #endif
+
+  /* Non instrumented code */
   result= bind(mysql_socket.fd, addr, len);
   return result;
 }
@@ -598,20 +615,30 @@ inline_mysql_socket_getsockname
  MYSQL_SOCKET mysql_socket, struct sockaddr *addr, socklen_t *len)
 {
   int result;
+
 #ifdef HAVE_PSI_SOCKET_INTERFACE
-  struct PSI_socket_locker *locker;
-  PSI_socket_locker_state state;
-  locker= PSI_CALL(get_thread_socket_locker)(&state, mysql_socket.m_psi,
-                                             PSI_SOCKET_BIND);
-  if (likely(locker !=NULL))
+  if (mysql_socket.m_psi != NULL)
   {
-    PSI_CALL(start_socket_wait)(locker, (size_t)0, src_file, src_line);
+    /* Instrumentation start */
+    PSI_socket_locker *locker;
+    PSI_socket_locker_state state;
+    locker= PSI_CALL(start_socket_wait)(&state, mysql_socket.m_psi,
+                                        PSI_SOCKET_BIND, (size_t)0, src_file, src_line);
+
+    /* Instrumented code */
     result= getsockname(mysql_socket.fd, addr, len);
-    PSI_CALL(end_socket_wait)(locker, (size_t)0);
+
+    /* Instrumentation end */
+    if (locker != NULL)
+      PSI_CALL(end_socket_wait)(locker, (size_t)0);
+
     return result;
   }
 #endif
+
+  /* Non instrumented code */
   result= getsockname(mysql_socket.fd, addr, len);
+
   return result;
 }
 
@@ -626,20 +653,30 @@ inline_mysql_socket_connect
  MYSQL_SOCKET mysql_socket, const struct sockaddr *addr, socklen_t len)
 {
   int result;
+
 #ifdef HAVE_PSI_SOCKET_INTERFACE
-  struct PSI_socket_locker *locker;
-  PSI_socket_locker_state state;
-  locker= PSI_CALL(get_thread_socket_locker)(&state, mysql_socket.m_psi,
-                                             PSI_SOCKET_CONNECT);
-  if (likely(locker != NULL))
+  if (mysql_socket.m_psi != NULL)
   {
-    PSI_CALL(start_socket_wait)(locker, (size_t)0, src_file, src_line);
+    /* Instrumentation start */
+    PSI_socket_locker *locker;
+    PSI_socket_locker_state state;
+    locker= PSI_CALL(start_socket_wait)(&state, mysql_socket.m_psi,
+                                        PSI_SOCKET_CONNECT, (size_t)0, src_file, src_line);
+
+    /* Instrumented code */
     result= connect(mysql_socket.fd, addr, len);
-    PSI_CALL(end_socket_wait)(locker, (size_t)0);
+
+    /* Instrumentation end */
+    if (locker != NULL)
+      PSI_CALL(end_socket_wait)(locker, (size_t)0);
+
     return result;
   }
 #endif
+
+  /* Non instrumented code */
   result= connect(mysql_socket.fd, addr, len);
+
   return result;
 }
 
@@ -654,20 +691,30 @@ inline_mysql_socket_getpeername
  MYSQL_SOCKET mysql_socket, struct sockaddr *addr, socklen_t *len)
 {
   int result;
+
 #ifdef HAVE_PSI_SOCKET_INTERFACE
-  struct PSI_socket_locker *locker;
-  PSI_socket_locker_state state;
-  locker= PSI_CALL(get_thread_socket_locker)(&state, mysql_socket.m_psi,
-                                             PSI_SOCKET_BIND);
-  if (likely(locker != NULL))
+  if (mysql_socket.m_psi != NULL)
   {
-    PSI_CALL(start_socket_wait)(locker, (size_t)0, src_file, src_line);
+    /* Instrumentation start */
+    PSI_socket_locker *locker;
+    PSI_socket_locker_state state;
+    locker= PSI_CALL(start_socket_wait)(&state, mysql_socket.m_psi,
+                                        PSI_SOCKET_BIND, (size_t)0, src_file, src_line);
+
+    /* Instrumented code */
     result= getpeername(mysql_socket.fd, addr, len);
-    PSI_CALL(end_socket_wait)(locker, (size_t)0);
+
+    /* Instrumentation end */
+    if (locker != NULL)
+      PSI_CALL(end_socket_wait)(locker, (size_t)0);
+
     return result;
   }
 #endif
+
+  /* Non instrumented code */
   result= getpeername(mysql_socket.fd, addr, len);
+
   return result;
 }
 
@@ -682,22 +729,34 @@ inline_mysql_socket_send
  MYSQL_SOCKET mysql_socket, const SOCKBUF_T *buf, size_t n, int flags)
 {
   ssize_t result;
+
 #ifdef HAVE_PSI_SOCKET_INTERFACE
-  struct PSI_socket_locker *locker;
-  PSI_socket_locker_state state;
-  size_t bytes_written;
-  locker= PSI_CALL(get_thread_socket_locker)(&state, mysql_socket.m_psi,
-                                             PSI_SOCKET_SEND);
-  if (likely(locker != NULL))
+  if (mysql_socket.m_psi != NULL)
   {
-    PSI_CALL(start_socket_wait)(locker, n, src_file, src_line);
+    /* Instrumentation start */
+    PSI_socket_locker *locker;
+    PSI_socket_locker_state state;
+    locker= PSI_CALL(start_socket_wait)(&state, mysql_socket.m_psi,
+                                        PSI_SOCKET_SEND, n, src_file, src_line);
+
+    /* Instrumented code */
     result= send(mysql_socket.fd, buf, n, flags);
-    bytes_written= (result > -1) ? result : 0;
-    PSI_CALL(end_socket_wait)(locker, bytes_written);
+
+    /* Instrumentation end */
+    if (locker != NULL)
+    {
+      size_t bytes_written;
+      bytes_written= (result > -1) ? result : 0;
+      PSI_CALL(end_socket_wait)(locker, bytes_written);
+    }
+
     return result;
   }
 #endif
+
+  /* Non instrumented code */
   result= send(mysql_socket.fd, buf, n, flags);
+
   return result;
 }
 
@@ -712,22 +771,34 @@ inline_mysql_socket_recv
  MYSQL_SOCKET mysql_socket,  SOCKBUF_T *buf, size_t n, int flags)
 {
   ssize_t result;
+
 #ifdef HAVE_PSI_SOCKET_INTERFACE
-  struct PSI_socket_locker *locker;
-  PSI_socket_locker_state state;
-  size_t bytes_read;
-  locker= PSI_CALL(get_thread_socket_locker)(&state, mysql_socket.m_psi,
-                                             PSI_SOCKET_RECV);
-  if (likely(locker != NULL))
+  if (mysql_socket.m_psi != NULL)
   {
-    PSI_CALL(start_socket_wait)(locker, (size_t)0, src_file, src_line);
+    /* Instrumentation start */
+    PSI_socket_locker *locker;
+    PSI_socket_locker_state state;
+    locker= PSI_CALL(start_socket_wait)(&state, mysql_socket.m_psi,
+                                        PSI_SOCKET_RECV, (size_t)0, src_file, src_line);
+
+    /* Instrumented code */
     result= recv(mysql_socket.fd, buf, n, flags);
-    bytes_read= (result > -1) ? result : 0;
-    PSI_CALL(end_socket_wait)(locker, bytes_read);
+
+    /* Instrumentation end */
+    if (locker != NULL)
+    {
+      size_t bytes_read;
+      bytes_read= (result > -1) ? result : 0;
+      PSI_CALL(end_socket_wait)(locker, bytes_read);
+    }
+
     return result;
   }
 #endif
+
+  /* Non instrumented code */
   result= recv(mysql_socket.fd, buf, n, flags);
+
   return result;
 }
 
@@ -742,22 +813,34 @@ inline_mysql_socket_sendto
  MYSQL_SOCKET mysql_socket, const SOCKBUF_T *buf, size_t n, int flags, const struct sockaddr *addr, socklen_t addr_len)
 {
   ssize_t result;
+
 #ifdef HAVE_PSI_SOCKET_INTERFACE
-  struct PSI_socket_locker *locker;
-  PSI_socket_locker_state state;
-  size_t bytes_written;
-  locker= PSI_CALL(get_thread_socket_locker)(&state, mysql_socket.m_psi,
-                                             PSI_SOCKET_SEND);
-  if (likely(locker != NULL))
+  if (mysql_socket.m_psi != NULL)
   {
-    PSI_CALL(start_socket_wait)(locker, n, src_file, src_line);
+    /* Instrumentation start */
+    PSI_socket_locker *locker;
+    PSI_socket_locker_state state;
+    locker= PSI_CALL(start_socket_wait)(&state, mysql_socket.m_psi,
+                                        PSI_SOCKET_SEND, n, src_file, src_line);
+
+    /* Instrumented code */
     result= sendto(mysql_socket.fd, buf, n, flags, addr, addr_len);
-    bytes_written = (result > -1) ? result : 0;
-    PSI_CALL(end_socket_wait)(locker, bytes_written);
+
+    /* Instrumentation end */
+    if (locker != NULL)
+    {
+      size_t bytes_written;
+      bytes_written = (result > -1) ? result : 0;
+      PSI_CALL(end_socket_wait)(locker, bytes_written);
+    }
+
     return result;
   }
 #endif
+
+  /* Non instrumented code */
   result= sendto(mysql_socket.fd, buf, n, flags, addr, addr_len);
+
   return result;
 }
 
@@ -773,22 +856,34 @@ inline_mysql_socket_recvfrom
  struct sockaddr *addr, socklen_t *addr_len)
 {
   ssize_t result;
+
 #ifdef HAVE_PSI_SOCKET_INTERFACE
-  struct PSI_socket_locker *locker;
-  PSI_socket_locker_state state;
-  size_t bytes_read;
-  locker= PSI_CALL(get_thread_socket_locker)(&state, mysql_socket.m_psi,
-                                             PSI_SOCKET_RECV);
-  if (likely(locker != NULL))
+  if (mysql_socket.m_psi != NULL)
   {
-    PSI_CALL(start_socket_wait)(locker, (size_t)0, src_file, src_line);
+    /* Instrumentation start */
+    PSI_socket_locker *locker;
+    PSI_socket_locker_state state;
+    locker= PSI_CALL(start_socket_wait)(&state, mysql_socket.m_psi,
+                                        PSI_SOCKET_RECV, (size_t)0, src_file, src_line);
+
+    /* Instrumented code */
     result= recvfrom(mysql_socket.fd, buf, n, flags, addr, addr_len);
-    bytes_read = (result > -1) ? result : 0;
-    PSI_CALL(end_socket_wait)(locker, bytes_read);
+
+    /* Instrumentation end */
+    if (locker != NULL)
+    {
+      size_t bytes_read;
+      bytes_read = (result > -1) ? result : 0;
+      PSI_CALL(end_socket_wait)(locker, bytes_read);
+    }
+
     return result;
   }
 #endif
+
+  /* Non instrumented code */
   result= recvfrom(mysql_socket.fd, buf, n, flags, addr, addr_len);
+
   return result;
 }
 
@@ -803,20 +898,30 @@ inline_mysql_socket_getsockopt
  MYSQL_SOCKET mysql_socket, int level, int optname, SOCKBUF_T *optval, socklen_t *optlen)
 {
   int result;
+
 #ifdef HAVE_PSI_SOCKET_INTERFACE
-  struct PSI_socket_locker *locker;
-  PSI_socket_locker_state state;
-  locker= PSI_CALL(get_thread_socket_locker)(&state, mysql_socket.m_psi,
-                                             PSI_SOCKET_OPT);
-  if (likely(locker != NULL))
+  if (mysql_socket.m_psi != NULL)
   {
-    PSI_CALL(start_socket_wait)(locker, (size_t)0, src_file, src_line);
+    /* Instrumentation start */
+    PSI_socket_locker *locker;
+    PSI_socket_locker_state state;
+    locker= PSI_CALL(start_socket_wait)(&state, mysql_socket.m_psi,
+                                        PSI_SOCKET_OPT, (size_t)0, src_file, src_line);
+
+    /* Instrumented code */
     result= getsockopt(mysql_socket.fd, level, optname, optval, optlen);
-    PSI_CALL(end_socket_wait)(locker, (size_t)0);
+
+    /* Instrumentation end */
+    if (locker != NULL)
+      PSI_CALL(end_socket_wait)(locker, (size_t)0);
+
     return result;
   }
 #endif
+
+  /* Non instrumented code */
   result= getsockopt(mysql_socket.fd, level, optname, optval, optlen);
+
   return result;
 }
 
@@ -832,20 +937,30 @@ inline_mysql_socket_setsockopt
  socklen_t optlen)
 {
   int result;
+
 #ifdef HAVE_PSI_SOCKET_INTERFACE
-  struct PSI_socket_locker *locker;
-  PSI_socket_locker_state state;
-  locker= PSI_CALL(get_thread_socket_locker)(&state, mysql_socket.m_psi,
-                   PSI_SOCKET_OPT);
-  if (likely(locker != NULL))
+  if (mysql_socket.m_psi)
   {
-    PSI_CALL(start_socket_wait)(locker, (size_t)0, src_file, src_line);
+    /* Instrumentation start */
+    PSI_socket_locker *locker;
+    PSI_socket_locker_state state;
+    locker= PSI_CALL(start_socket_wait)(&state, mysql_socket.m_psi,
+                                        PSI_SOCKET_OPT, (size_t)0, src_file, src_line);
+
+    /* Instrumented code */
     result= setsockopt(mysql_socket.fd, level, optname, optval, optlen);
-    PSI_CALL(end_socket_wait)(locker, (size_t)0);
+
+    /* Instrumentation end */
+    if (locker != NULL)
+      PSI_CALL(end_socket_wait)(locker, (size_t)0);
+
     return result;
   }
 #endif
+
+  /* Non instrumented code */
   result= setsockopt(mysql_socket.fd, level, optname, optval, optlen);
+
   return result;
 }
 
@@ -860,20 +975,30 @@ inline_mysql_socket_listen
  MYSQL_SOCKET mysql_socket, int backlog)
 {
   int result;
+
 #ifdef HAVE_PSI_SOCKET_INTERFACE
-  struct PSI_socket_locker *locker;
-  PSI_socket_locker_state state;
-  locker= PSI_CALL(get_thread_socket_locker)(&state, mysql_socket.m_psi,
-                                             PSI_SOCKET_CONNECT);
-  if (likely(locker != NULL))
+  if (mysql_socket.m_psi != NULL)
   {
-    PSI_CALL(start_socket_wait)(locker, (size_t)0, src_file, src_line);
+    /* Instrumentation start */
+    PSI_socket_locker *locker;
+    PSI_socket_locker_state state;
+    locker= PSI_CALL(start_socket_wait)(&state, mysql_socket.m_psi,
+                                        PSI_SOCKET_CONNECT, (size_t)0, src_file, src_line);
+
+    /* Instrumented code */
     result= listen(mysql_socket.fd, backlog);
-    PSI_CALL(end_socket_wait)(locker, (size_t)0);
+
+    /* Instrumentation end */
+    if (locker != NULL)
+      PSI_CALL(end_socket_wait)(locker, (size_t)0);
+
     return result;
   }
 #endif
+
+  /* Non instrumented code */
   result= listen(mysql_socket.fd, backlog);
+
   return result;
 }
 
@@ -888,35 +1013,43 @@ inline_mysql_socket_accept
   MYSQL_SOCKET socket_listen, struct sockaddr *addr, socklen_t *addr_len)
 {
   MYSQL_SOCKET socket_accept= MYSQL_INVALID_SOCKET;
-#ifdef HAVE_PSI_SOCKET_INTERFACE
   socklen_t addr_length= (addr_len != NULL) ? *addr_len : 0;
-  struct PSI_socket_locker *locker;
-  PSI_socket_locker_state state;
-  locker= PSI_CALL(get_thread_socket_locker)(&state, socket_listen.m_psi,
-                                             PSI_SOCKET_CONNECT);
-  if (likely(locker != NULL))
+
+#ifdef HAVE_PSI_SOCKET_INTERFACE
+  if (socket_listen.m_psi != NULL)
   {
-    PSI_CALL(start_socket_wait)(locker, (size_t)0, src_file, src_line);
+    /* Instrumentation start */
+    PSI_socket_locker *locker;
+    PSI_socket_locker_state state;
+    locker= PSI_CALL(start_socket_wait)(&state, socket_listen.m_psi,
+                                        PSI_SOCKET_CONNECT, (size_t)0, src_file, src_line);
+
+    /* Instrumented code */
     socket_accept.fd= accept(socket_listen.fd, addr, &addr_length);
-    PSI_CALL(end_socket_wait)(locker, (size_t)0);
+
+    /* Instrumentation end */
+    if (locker != NULL)
+      PSI_CALL(end_socket_wait)(locker, (size_t)0);
   }
   else
+#endif
   {
+    /* Non instrumented code */
     socket_accept.fd= accept(socket_listen.fd, addr, &addr_length);
   }
 
-  /** Initialize the instrument with the new socket descriptor and address */
+#ifdef HAVE_PSI_SOCKET_INTERFACE
+  /* Initialize the instrument with the new socket descriptor and address */
   socket_accept.m_psi=
             PSI_CALL(init_socket)(key, (const my_socket*)&socket_accept.fd);
 
-  if (likely(socket_accept.fd != INVALID_SOCKET && socket_accept.m_psi != NULL))
+  /* FIXME: simplify this with just 1 call to init_socket(). */
+  if (socket_accept.m_psi != NULL)
     PSI_CALL(set_socket_info)(socket_accept.m_psi, &socket_accept.fd, addr,
                               addr_length);
-  return socket_accept;
-#else
-  socket_accept.fd= accept(socket_listen.fd, addr, addr_len);
-  return socket_accept;
 #endif
+
+  return socket_accept;
 }
 
 /** mysql_socket_close */
@@ -930,26 +1063,33 @@ inline_mysql_socket_close
   MYSQL_SOCKET mysql_socket)
 {
   int result;
+
 #ifdef HAVE_PSI_SOCKET_INTERFACE
-  struct PSI_socket_locker *locker;
-  PSI_socket_locker_state state;
-  locker= PSI_CALL(get_thread_socket_locker)(&state, mysql_socket.m_psi,
-                                             PSI_SOCKET_CLOSE);
-  if (likely(locker != NULL))
+  if (mysql_socket.m_psi != NULL)
   {
-    PSI_CALL(start_socket_wait)(locker, (size_t)0, src_file, src_line);
+    /* Instrumentation start */
+    PSI_socket_locker *locker;
+    PSI_socket_locker_state state;
+    locker= PSI_CALL(start_socket_wait)(&state, mysql_socket.m_psi,
+                                        PSI_SOCKET_CLOSE, (size_t)0, src_file, src_line);
+
+    /* Instrumented code */
     result= closesocket(mysql_socket.fd);
-    PSI_CALL(end_socket_wait)(locker, (size_t)0);
+
+    /* Instrumentation end */
+    if (locker != NULL)
+      PSI_CALL(end_socket_wait)(locker, (size_t)0);
     /* Remove the instrumentation for this socket. */
-    PSI_CALL(destroy_socket)(mysql_socket.m_psi);
+    if (mysql_socket.m_psi != NULL)
+      PSI_CALL(destroy_socket)(mysql_socket.m_psi);
+
     return result;
   }
 #endif
+
+  /* Non instrumented code */
   result= closesocket(mysql_socket.fd);
-#ifdef HAVE_PSI_SOCKET_INTERFACE
-  /* Remove the instrumentation for this socket. */
-  PSI_CALL(destroy_socket)(mysql_socket.m_psi);
-#endif
+
   return result;
 }
 
@@ -964,20 +1104,30 @@ inline_mysql_socket_shutdown
   MYSQL_SOCKET mysql_socket, int how)
 {
   int result;
+
+  /* Instrumentation start */
 #ifdef HAVE_PSI_SOCKET_INTERFACE
-  struct PSI_socket_locker *locker;
-  PSI_socket_locker_state state;
-  locker= PSI_CALL(get_thread_socket_locker)(&state, mysql_socket.m_psi,
-                                             PSI_SOCKET_SHUTDOWN);
-  if (likely(locker != NULL))
+  if (mysql_socket.m_psi != NULL)
   {
-    PSI_CALL(start_socket_wait)(locker, (size_t)0, src_file, src_line);
+    PSI_socket_locker *locker;
+    PSI_socket_locker_state state;
+    locker= PSI_CALL(start_socket_wait)(&state, mysql_socket.m_psi,
+                                        PSI_SOCKET_SHUTDOWN, (size_t)0, src_file, src_line);
+
+    /* Instrumented code */
     result= shutdown(mysql_socket.fd, how);
-    PSI_CALL(end_socket_wait)(locker, (size_t)0);
+
+    /* Instrumentation end */
+    if (locker != NULL)
+      PSI_CALL(end_socket_wait)(locker, (size_t)0);
+
     return result;
   }
 #endif
+
+  /* Non instrumented code */
   result= shutdown(mysql_socket.fd, how);
+
   return result;
 }
 

=== modified file 'include/mysql/psi/mysql_table.h'
--- a/include/mysql/psi/mysql_table.h	2011-07-05 08:15:52 +0000
+++ b/include/mysql/psi/mysql_table.h	2012-01-06 09:03:53 +0000
@@ -50,11 +50,9 @@
 #endif
 
 /**
-  @def MYSQL_START_TABLE_IO_WAIT
+  @def MYSQL_TABLE_IO_WAIT
   Instrumentation helper for table io_waits.
   This instrumentation marks the start of a wait event.
-  @param LOCKER the locker
-  @param STATE the locker state
   @param PSI the instrumented table
   @param OP the table operation to be performed
   @param INDEX the table index used if any, or MAY_KEY.
@@ -62,58 +60,59 @@
   @sa MYSQL_END_TABLE_WAIT.
 */
 #ifdef HAVE_PSI_TABLE_INTERFACE
-  #define MYSQL_START_TABLE_IO_WAIT(LOCKER, STATE, PSI, OP, INDEX, FLAGS) \
-    LOCKER= inline_mysql_start_table_io_wait(STATE, PSI, \
-                                             OP, INDEX, __FILE__, __LINE__)
+  #define MYSQL_TABLE_IO_WAIT(PSI, OP, INDEX, FLAGS, PAYLOAD)          \
+    {                                                                  \
+      if (PSI != NULL)                                                 \
+      {                                                                \
+        PSI_table_locker *locker;                                      \
+        PSI_table_locker_state state;                                  \
+        locker= PSI_CALL(start_table_io_wait)(& state, PSI, OP, INDEX, \
+                                              __FILE__, __LINE__);     \
+        PAYLOAD                                                        \
+        if (locker != NULL)                                            \
+          PSI_CALL(end_table_io_wait)(locker);                         \
+      }                                                                \
+      else                                                             \
+      {                                                                \
+        PAYLOAD                                                        \
+      }                                                                \
+    }
 #else
-  #define MYSQL_START_TABLE_IO_WAIT(LOCKER, STATE, PSI, OP, INDEX, FLAGS) \
-    do {} while (0)
+  #define MYSQL_TABLE_IO_WAIT(PSI, OP, INDEX, FLAGS, PAYLOAD) \
+    PAYLOAD
 #endif
 
 /**
-  @def MYSQL_END_TABLE_IO_WAIT
-  Instrumentation helper for table io waits.
-  This instrumentation marks the end of a wait event.
-  @param LOCKER the locker
-  @sa MYSQL_START_TABLE_IO_WAIT.
+  @def MYSQL_TABLE_LOCK_WAIT
+  Instrumentation helper for table io_waits.
+  This instrumentation marks the start of a wait event.
+  @param PSI the instrumented table
+  @param OP the table operation to be performed
+  @param INDEX the table index used if any, or MAY_KEY.
+  @param FLAGS per table operation flags.
+  @sa MYSQL_END_TABLE_WAIT.
 */
 #ifdef HAVE_PSI_TABLE_INTERFACE
-  #define MYSQL_END_TABLE_IO_WAIT(LOCKER) \
-    inline_mysql_end_table_io_wait(LOCKER)
+  #define MYSQL_TABLE_LOCK_WAIT(PSI, OP, FLAGS, PAYLOAD)                 \
+    {                                                                    \
+      if (PSI != NULL)                                                   \
+      {                                                                  \
+        PSI_table_locker *locker;                                        \
+        PSI_table_locker_state state;                                    \
+        locker= PSI_CALL(start_table_lock_wait)(& state, PSI, OP, FLAGS, \
+                                                __FILE__, __LINE__);     \
+        PAYLOAD                                                          \
+        if (locker != NULL)                                              \
+          PSI_CALL(end_table_lock_wait)(locker);                         \
+      }                                                                  \
+      else                                                               \
+      {                                                                  \
+        PAYLOAD                                                          \
+      }                                                                  \
+    }
 #else
-  #define MYSQL_END_TABLE_IO_WAIT(LOCKER) \
-    do {} while (0)
-#endif
-
-#ifdef HAVE_PSI_TABLE_INTERFACE
-/**
-  Instrumentation calls for MYSQL_START_TABLE_IO_WAIT.
-  @sa MYSQL_END_TABLE_IO_WAIT.
-*/
-static inline struct PSI_table_locker *
-inline_mysql_start_table_io_wait(PSI_table_locker_state *state,
-                                 struct PSI_table *psi,
-                                 enum PSI_table_io_operation op,
-                                 uint index,
-                                 const char *src_file, int src_line)
-{
-  struct PSI_table_locker *locker;
-  locker= PSI_CALL(get_thread_table_io_locker)(state, psi, op, index);
-  if (likely(locker != NULL))
-    PSI_CALL(start_table_io_wait)(locker, src_file, src_line);
-  return locker;
-}
-
-/**
-  Instrumentation calls for MYSQL_END_TABLE_IO_WAIT.
-  @sa MYSQL_START_TABLE_IO_WAIT.
-*/
-static inline void
-inline_mysql_end_table_io_wait(struct PSI_table_locker *locker)
-{
-  if (likely(locker != NULL))
-    PSI_CALL(end_table_io_wait)(locker);
-}
+  #define MYSQL_TABLE_LOCK_WAIT(PSI, OP, FLAGS, PAYLOAD) \
+    PAYLOAD
 #endif
 
 /**
@@ -162,11 +161,13 @@ inline_mysql_start_table_lock_wait(PSI_t
                                    enum PSI_table_lock_operation op,
                                    ulong flags, const char *src_file, int src_line)
 {
-  struct PSI_table_locker *locker;
-  locker= PSI_CALL(get_thread_table_lock_locker)(state, psi, op, flags);
-  if (likely(locker != NULL))
-    PSI_CALL(start_table_lock_wait)(locker, src_file, src_line);
-  return locker;
+  if (psi != NULL)
+  {
+    struct PSI_table_locker *locker;
+    locker= PSI_CALL(start_table_lock_wait)(state, psi, op, flags, src_file, src_line);
+    return locker;
+  }
+  return NULL;
 }
 
 /**
@@ -176,7 +177,7 @@ inline_mysql_start_table_lock_wait(PSI_t
 static inline void
 inline_mysql_end_table_lock_wait(struct PSI_table_locker *locker)
 {
-  if (likely(locker != NULL))
+  if (locker != NULL)
     PSI_CALL(end_table_lock_wait)(locker);
 }
 #endif

=== modified file 'include/mysql/psi/mysql_thread.h'
--- a/include/mysql/psi/mysql_thread.h	2011-10-17 10:28:01 +0000
+++ b/include/mysql/psi/mysql_thread.h	2012-01-06 09:03:53 +0000
@@ -631,8 +631,11 @@ static inline int inline_mysql_mutex_des
   )
 {
 #ifdef HAVE_PSI_MUTEX_INTERFACE
-  PSI_CALL(destroy_mutex)(that->m_psi);
-  that->m_psi= NULL;
+  if (that->m_psi != NULL)
+  {
+    PSI_CALL(destroy_mutex)(that->m_psi);
+    that->m_psi= NULL;
+  }
 #endif
 #ifdef SAFE_MUTEX
   return safe_mutex_destroy(&that->m_mutex, src_file, src_line);
@@ -651,13 +654,17 @@ static inline int inline_mysql_mutex_loc
   )
 {
   int result;
+
 #ifdef HAVE_PSI_MUTEX_INTERFACE
-  struct PSI_mutex_locker *locker;
-  PSI_mutex_locker_state state;
-  locker= PSI_CALL(get_thread_mutex_locker)(&state, that->m_psi, PSI_MUTEX_LOCK);
-  if (likely(locker != NULL))
+  if (that->m_psi != NULL)
   {
-    PSI_CALL(start_mutex_wait)(locker, src_file, src_line);
+    /* Instrumentation start */
+    PSI_mutex_locker *locker;
+    PSI_mutex_locker_state state;
+    locker= PSI_CALL(start_mutex_wait)(&state, that->m_psi,
+                                       PSI_MUTEX_LOCK, src_file, src_line);
+
+    /* Instrumented code */
 #ifdef SAFE_MUTEX
     result= safe_mutex_lock(&that->m_mutex, FALSE, src_file, src_line);
 #elif defined(MY_PTHREAD_FASTMUTEX)
@@ -665,11 +672,16 @@ static inline int inline_mysql_mutex_loc
 #else
     result= pthread_mutex_lock(&that->m_mutex);
 #endif
-    PSI_CALL(end_mutex_wait)(locker, result);
+
+    /* Instrumentation end */
+    if (locker != NULL)
+      PSI_CALL(end_mutex_wait)(locker, result);
+
     return result;
   }
 #endif
 
+  /* Non instrumented code */
 #ifdef SAFE_MUTEX
   result= safe_mutex_lock(&that->m_mutex, FALSE, src_file, src_line);
 #elif defined(MY_PTHREAD_FASTMUTEX)
@@ -677,6 +689,7 @@ static inline int inline_mysql_mutex_loc
 #else
   result= pthread_mutex_lock(&that->m_mutex);
 #endif
+
   return result;
 }
 
@@ -688,13 +701,17 @@ static inline int inline_mysql_mutex_try
   )
 {
   int result;
+
 #ifdef HAVE_PSI_MUTEX_INTERFACE
-  struct PSI_mutex_locker *locker;
-  PSI_mutex_locker_state state;
-  locker= PSI_CALL(get_thread_mutex_locker)(&state, that->m_psi, PSI_MUTEX_TRYLOCK);
-  if (likely(locker != NULL))
+  if (that->m_psi != NULL)
   {
-    PSI_CALL(start_mutex_wait)(locker, src_file, src_line);
+    /* Instrumentation start */
+    PSI_mutex_locker *locker;
+    PSI_mutex_locker_state state;
+    locker= PSI_CALL(start_mutex_wait)(&state, that->m_psi,
+                                       PSI_MUTEX_TRYLOCK, src_file, src_line);
+
+    /* Instrumented code */
 #ifdef SAFE_MUTEX
     result= safe_mutex_lock(&that->m_mutex, TRUE, src_file, src_line);
 #elif defined(MY_PTHREAD_FASTMUTEX)
@@ -702,11 +719,16 @@ static inline int inline_mysql_mutex_try
 #else
     result= pthread_mutex_trylock(&that->m_mutex);
 #endif
-    PSI_CALL(end_mutex_wait)(locker, result);
+
+    /* Instrumentation end */
+    if (locker != NULL)
+      PSI_CALL(end_mutex_wait)(locker, result);
+
     return result;
   }
 #endif
 
+  /* Non instrumented code */
 #ifdef SAFE_MUTEX
   result= safe_mutex_lock(&that->m_mutex, TRUE, src_file, src_line);
 #elif defined(MY_PTHREAD_FASTMUTEX)
@@ -714,6 +736,7 @@ static inline int inline_mysql_mutex_try
 #else
   result= pthread_mutex_trylock(&that->m_mutex);
 #endif
+
   return result;
 }
 
@@ -725,9 +748,12 @@ static inline int inline_mysql_mutex_unl
   )
 {
   int result;
+
 #ifdef HAVE_PSI_MUTEX_INTERFACE
-  PSI_CALL(unlock_mutex)(that->m_psi);
+  if (that->m_psi != NULL)
+    PSI_CALL(unlock_mutex)(that->m_psi);
 #endif
+
 #ifdef SAFE_MUTEX
   result= safe_mutex_unlock(&that->m_mutex, src_file, src_line);
 #elif defined(MY_PTHREAD_FASTMUTEX)
@@ -735,6 +761,7 @@ static inline int inline_mysql_mutex_unl
 #else
   result= pthread_mutex_unlock(&that->m_mutex);
 #endif
+
   return result;
 }
 
@@ -792,8 +819,11 @@ static inline int inline_mysql_rwlock_de
   mysql_rwlock_t *that)
 {
 #ifdef HAVE_PSI_RWLOCK_INTERFACE
-  PSI_CALL(destroy_rwlock)(that->m_psi);
-  that->m_psi= NULL;
+  if (that->m_psi != NULL)
+  {
+    PSI_CALL(destroy_rwlock)(that->m_psi);
+    that->m_psi= NULL;
+  }
 #endif
   return rwlock_destroy(&that->m_rwlock);
 }
@@ -803,8 +833,11 @@ static inline int inline_mysql_prlock_de
   mysql_prlock_t *that)
 {
 #ifdef HAVE_PSI_RWLOCK_INTERFACE
-  PSI_CALL(destroy_rwlock)(that->m_psi);
-  that->m_psi= NULL;
+  if (that->m_psi != NULL)
+  {
+    PSI_CALL(destroy_rwlock)(that->m_psi);
+    that->m_psi= NULL;
+  }
 #endif
   return rw_pr_destroy(&that->m_prlock);
 }
@@ -818,21 +851,30 @@ static inline int inline_mysql_rwlock_rd
   )
 {
   int result;
+
 #ifdef HAVE_PSI_RWLOCK_INTERFACE
-  struct PSI_rwlock_locker *locker;
-  PSI_rwlock_locker_state state;
-  locker= PSI_CALL(get_thread_rwlock_locker)(&state, that->m_psi,
-                                             PSI_RWLOCK_READLOCK);
-  if (likely(locker != NULL))
+  if (that->m_psi != NULL)
   {
-    PSI_CALL(start_rwlock_rdwait)(locker, src_file, src_line);
+    /* Instrumentation start */
+    PSI_rwlock_locker *locker;
+    PSI_rwlock_locker_state state;
+    locker= PSI_CALL(start_rwlock_rdwait)(&state, that->m_psi,
+                                          PSI_RWLOCK_READLOCK, src_file, src_line);
+
+    /* Instrumented code */
     result= rw_rdlock(&that->m_rwlock);
-    PSI_CALL(end_rwlock_rdwait)(locker, result);
+
+    /* Instrumentation end */
+    if (locker != NULL)
+      PSI_CALL(end_rwlock_rdwait)(locker, result);
+
     return result;
   }
 #endif
 
+  /* Non instrumented code */
   result= rw_rdlock(&that->m_rwlock);
+
   return result;
 }
 
@@ -845,21 +887,30 @@ static inline int inline_mysql_prlock_rd
   )
 {
   int result;
+
 #ifdef HAVE_PSI_RWLOCK_INTERFACE
-  struct PSI_rwlock_locker *locker;
-  PSI_rwlock_locker_state state;
-  locker= PSI_CALL(get_thread_rwlock_locker)(&state, that->m_psi,
-                                             PSI_RWLOCK_READLOCK);
-  if (likely(locker != NULL))
+  if (that->m_psi != NULL)
   {
-    PSI_CALL(start_rwlock_rdwait)(locker, src_file, src_line);
+    /* Instrumentation start */
+    PSI_rwlock_locker *locker;
+    PSI_rwlock_locker_state state;
+    locker= PSI_CALL(start_rwlock_rdwait)(&state, that->m_psi,
+                                          PSI_RWLOCK_READLOCK, src_file, src_line);
+
+    /* Instrumented code */
     result= rw_pr_rdlock(&that->m_prlock);
-    PSI_CALL(end_rwlock_rdwait)(locker, result);
+
+    /* Instrumentation end */
+    if (locker != NULL)
+      PSI_CALL(end_rwlock_rdwait)(locker, result);
+
     return result;
   }
 #endif
 
+  /* Non instrumented code */
   result= rw_pr_rdlock(&that->m_prlock);
+
   return result;
 }
 #endif
@@ -872,21 +923,30 @@ static inline int inline_mysql_rwlock_wr
   )
 {
   int result;
+
 #ifdef HAVE_PSI_RWLOCK_INTERFACE
-  struct PSI_rwlock_locker *locker;
-  PSI_rwlock_locker_state state;
-  locker= PSI_CALL(get_thread_rwlock_locker)(&state, that->m_psi,
-                                             PSI_RWLOCK_WRITELOCK);
-  if (likely(locker != NULL))
+  if (that->m_psi != NULL)
   {
-    PSI_CALL(start_rwlock_wrwait)(locker, src_file, src_line);
+    /* Instrumentation start */
+    PSI_rwlock_locker *locker;
+    PSI_rwlock_locker_state state;
+    locker= PSI_CALL(start_rwlock_wrwait)(&state, that->m_psi,
+                                          PSI_RWLOCK_WRITELOCK, src_file, src_line);
+
+    /* Instrumented code */
     result= rw_wrlock(&that->m_rwlock);
-    PSI_CALL(end_rwlock_wrwait)(locker, result);
+
+    /* Instrumentation end */
+    if (locker != NULL)
+      PSI_CALL(end_rwlock_wrwait)(locker, result);
+
     return result;
   }
 #endif
 
+  /* Non instrumented code */
   result= rw_wrlock(&that->m_rwlock);
+
   return result;
 }
 
@@ -899,21 +959,30 @@ static inline int inline_mysql_prlock_wr
   )
 {
   int result;
+
 #ifdef HAVE_PSI_RWLOCK_INTERFACE
-  struct PSI_rwlock_locker *locker;
-  PSI_rwlock_locker_state state;
-  locker= PSI_CALL(get_thread_rwlock_locker)(&state, that->m_psi,
-                                             PSI_RWLOCK_WRITELOCK);
-  if (likely(locker != NULL))
+  if (that->m_psi != NULL)
   {
-    PSI_CALL(start_rwlock_wrwait)(locker, src_file, src_line);
+    /* Instrumentation start */
+    PSI_rwlock_locker *locker;
+    PSI_rwlock_locker_state state;
+    locker= PSI_CALL(start_rwlock_wrwait)(&state, that->m_psi,
+                                          PSI_RWLOCK_WRITELOCK, src_file, src_line);
+
+    /* Instrumented code */
     result= rw_pr_wrlock(&that->m_prlock);
-    PSI_CALL(end_rwlock_wrwait)(locker, result);
+
+    /* Instrumentation end */
+    if (locker != NULL)
+      PSI_CALL(end_rwlock_wrwait)(locker, result);
+
     return result;
   }
 #endif
 
+  /* Non instrumented code */
   result= rw_pr_wrlock(&that->m_prlock);
+
   return result;
 }
 #endif
@@ -926,21 +995,30 @@ static inline int inline_mysql_rwlock_tr
   )
 {
   int result;
+
 #ifdef HAVE_PSI_RWLOCK_INTERFACE
-  struct PSI_rwlock_locker *locker;
-  PSI_rwlock_locker_state state;
-  locker= PSI_CALL(get_thread_rwlock_locker)(&state, that->m_psi,
-                                             PSI_RWLOCK_TRYREADLOCK);
-  if (likely(locker != NULL))
+  if (that->m_psi != NULL)
   {
-    PSI_CALL(start_rwlock_rdwait)(locker, src_file, src_line);
+    /* Instrumentation start */
+    PSI_rwlock_locker *locker;
+    PSI_rwlock_locker_state state;
+    locker= PSI_CALL(start_rwlock_rdwait)(&state, that->m_psi,
+                                          PSI_RWLOCK_TRYREADLOCK, src_file, src_line);
+
+    /* Instrumented code */
     result= rw_tryrdlock(&that->m_rwlock);
-    PSI_CALL(end_rwlock_rdwait)(locker, result);
+
+    /* Instrumentation end */
+    if (locker != NULL)
+      PSI_CALL(end_rwlock_rdwait)(locker, result);
+
     return result;
   }
 #endif
 
+  /* Non instrumented code */
   result= rw_tryrdlock(&that->m_rwlock);
+
   return result;
 }
 
@@ -952,21 +1030,30 @@ static inline int inline_mysql_rwlock_tr
   )
 {
   int result;
+
 #ifdef HAVE_PSI_RWLOCK_INTERFACE
-  struct PSI_rwlock_locker *locker;
-  PSI_rwlock_locker_state state;
-  locker= PSI_CALL(get_thread_rwlock_locker)(&state, that->m_psi,
-                                             PSI_RWLOCK_TRYWRITELOCK);
-  if (likely(locker != NULL))
+  if (that->m_psi != NULL)
   {
-    PSI_CALL(start_rwlock_wrwait)(locker, src_file, src_line);
+    /* Instrumentation start */
+    PSI_rwlock_locker *locker;
+    PSI_rwlock_locker_state state;
+    locker= PSI_CALL(start_rwlock_wrwait)(&state, that->m_psi,
+                                          PSI_RWLOCK_TRYWRITELOCK, src_file, src_line);
+
+    /* Instrumented code */
     result= rw_trywrlock(&that->m_rwlock);
-    PSI_CALL(end_rwlock_wrwait)(locker, result);
+
+    /* Instrumentation end */
+    if (locker != NULL)
+      PSI_CALL(end_rwlock_wrwait)(locker, result);
+
     return result;
   }
 #endif
 
+  /* Non instrumented code */
   result= rw_trywrlock(&that->m_rwlock);
+
   return result;
 }
 
@@ -975,7 +1062,8 @@ static inline int inline_mysql_rwlock_un
 {
   int result;
 #ifdef HAVE_PSI_RWLOCK_INTERFACE
-  PSI_CALL(unlock_rwlock)(that->m_psi);
+  if (that->m_psi != NULL)
+    PSI_CALL(unlock_rwlock)(that->m_psi);
 #endif
   result= rw_unlock(&that->m_rwlock);
   return result;
@@ -987,7 +1075,8 @@ static inline int inline_mysql_prlock_un
 {
   int result;
 #ifdef HAVE_PSI_RWLOCK_INTERFACE
-  PSI_CALL(unlock_rwlock)(that->m_psi);
+  if (that->m_psi != NULL)
+    PSI_CALL(unlock_rwlock)(that->m_psi);
 #endif
   result= rw_pr_unlock(&that->m_prlock);
   return result;
@@ -1030,8 +1119,11 @@ static inline int inline_mysql_cond_dest
   mysql_cond_t *that)
 {
 #ifdef HAVE_PSI_COND_INTERFACE
-  PSI_CALL(destroy_cond)(that->m_psi);
-  that->m_psi= NULL;
+  if (that->m_psi != NULL)
+  {
+    PSI_CALL(destroy_cond)(that->m_psi);
+    that->m_psi= NULL;
+  }
 #endif
   return pthread_cond_destroy(&that->m_cond);
 }
@@ -1045,21 +1137,30 @@ static inline int inline_mysql_cond_wait
   )
 {
   int result;
+
 #ifdef HAVE_PSI_COND_INTERFACE
-  struct PSI_cond_locker *locker;
-  PSI_cond_locker_state state;
-  locker= PSI_CALL(get_thread_cond_locker)(&state, that->m_psi, mutex->m_psi,
-                                           PSI_COND_WAIT);
-  if (likely(locker != NULL))
+  if (that->m_psi != NULL)
   {
-    PSI_CALL(start_cond_wait)(locker, src_file, src_line);
+    /* Instrumentation start */
+    PSI_cond_locker *locker;
+    PSI_cond_locker_state state;
+    locker= PSI_CALL(start_cond_wait)(&state, that->m_psi, mutex->m_psi,
+                                      PSI_COND_WAIT, src_file, src_line);
+
+    /* Instrumented code */
     result= my_cond_wait(&that->m_cond, &mutex->m_mutex);
-    PSI_CALL(end_cond_wait)(locker, result);
+
+    /* Instrumentation end */
+    if (locker != NULL)
+      PSI_CALL(end_cond_wait)(locker, result);
+
     return result;
   }
 #endif
 
+  /* Non instrumented code */
   result= my_cond_wait(&that->m_cond, &mutex->m_mutex);
+
   return result;
 }
 
@@ -1073,21 +1174,30 @@ static inline int inline_mysql_cond_time
   )
 {
   int result;
+
 #ifdef HAVE_PSI_COND_INTERFACE
-  struct PSI_cond_locker *locker;
-  PSI_cond_locker_state state;
-  locker= PSI_CALL(get_thread_cond_locker)(&state, that->m_psi, mutex->m_psi,
-                                           PSI_COND_TIMEDWAIT);
-  if (likely(locker != NULL))
+  if (that->m_psi != NULL)
   {
-    PSI_CALL(start_cond_wait)(locker, src_file, src_line);
+    /* Instrumentation start */
+    PSI_cond_locker *locker;
+    PSI_cond_locker_state state;
+    locker= PSI_CALL(start_cond_wait)(&state, that->m_psi, mutex->m_psi,
+                                      PSI_COND_TIMEDWAIT, src_file, src_line);
+
+    /* Instrumented code */
     result= my_cond_timedwait(&that->m_cond, &mutex->m_mutex, abstime);
-    PSI_CALL(end_cond_wait)(locker, result);
+
+    /* Instrumentation end */
+    if (locker != NULL)
+      PSI_CALL(end_cond_wait)(locker, result);
+
     return result;
   }
 #endif
 
+  /* Non instrumented code */
   result= my_cond_timedwait(&that->m_cond, &mutex->m_mutex, abstime);
+
   return result;
 }
 
@@ -1096,7 +1206,8 @@ static inline int inline_mysql_cond_sign
 {
   int result;
 #ifdef HAVE_PSI_COND_INTERFACE
-  PSI_CALL(signal_cond)(that->m_psi);
+  if (that->m_psi != NULL)
+    PSI_CALL(signal_cond)(that->m_psi);
 #endif
   result= pthread_cond_signal(&that->m_cond);
   return result;
@@ -1107,7 +1218,8 @@ static inline int inline_mysql_cond_broa
 {
   int result;
 #ifdef HAVE_PSI_COND_INTERFACE
-  PSI_CALL(broadcast_cond)(that->m_psi);
+  if (that->m_psi != NULL)
+    PSI_CALL(broadcast_cond)(that->m_psi);
 #endif
   result= pthread_cond_broadcast(&that->m_cond);
   return result;

=== modified file 'include/mysql/psi/psi.h'
--- a/include/mysql/psi/psi.h	2011-11-08 15:56:29 +0000
+++ b/include/mysql/psi/psi.h	2012-01-09 08:27:58 +0000
@@ -57,66 +57,77 @@ struct TABLE_SHARE;
   This is an opaque structure.
 */
 struct PSI_mutex;
+typedef struct PSI_mutex PSI_mutex;
 
 /**
   Interface for an instrumented rwlock.
   This is an opaque structure.
 */
 struct PSI_rwlock;
+typedef struct PSI_rwlock PSI_rwlock;
 
 /**
   Interface for an instrumented condition.
   This is an opaque structure.
 */
 struct PSI_cond;
+typedef struct PSI_cond PSI_cond;
 
 /**
   Interface for an instrumented table share.
   This is an opaque structure.
 */
 struct PSI_table_share;
+typedef struct PSI_table_share PSI_table_share;
 
 /**
   Interface for an instrumented table handle.
   This is an opaque structure.
 */
 struct PSI_table;
+typedef struct PSI_table PSI_table;
 
 /**
   Interface for an instrumented thread.
   This is an opaque structure.
 */
 struct PSI_thread;
+typedef struct PSI_thread PSI_thread;
 
 /**
   Interface for an instrumented file handle.
   This is an opaque structure.
 */
 struct PSI_file;
+typedef struct PSI_file PSI_file;
 
 /**
   Interface for an instrumented socket descriptor.
   This is an opaque structure.
 */
 struct PSI_socket;
+typedef struct PSI_socket PSI_socket;
 
 /**
   Interface for an instrumented table operation.
   This is an opaque structure.
 */
 struct PSI_table_locker;
+typedef struct PSI_table_locker PSI_table_locker;
 
 /**
   Interface for an instrumented statement.
   This is an opaque structure.
 */
 struct PSI_statement_locker;
+typedef struct PSI_statement_locker PSI_statement_locker;
 
 /**
   Interface for an instrumented idle operation.
   This is an opaque structure.
 */
 struct PSI_idle_locker;
+typedef struct PSI_idle_locker PSI_idle_locker;
 
 /** Entry point for the performance schema interface. */
 struct PSI_bootstrap
@@ -136,6 +147,7 @@ struct PSI_bootstrap
   */
   void* (*get_interface)(int version);
 };
+typedef struct PSI_bootstrap PSI_bootstrap;
 
 #ifdef HAVE_PSI_INTERFACE
 
@@ -283,25 +295,35 @@ struct PSI_bootstrap
   This is an opaque structure.
 */
 struct PSI_mutex_locker;
+typedef struct PSI_mutex_locker PSI_mutex_locker;
 
 /**
   Interface for an instrumented rwlock operation.
   This is an opaque structure.
 */
-
 struct PSI_rwlock_locker;
+typedef struct PSI_rwlock_locker PSI_rwlock_locker;
+
 /**
   Interface for an instrumented condition operation.
   This is an opaque structure.
 */
-
 struct PSI_cond_locker;
+typedef struct PSI_cond_locker PSI_cond_locker;
 
 /**
   Interface for an instrumented file operation.
   This is an opaque structure.
 */
 struct PSI_file_locker;
+typedef struct PSI_file_locker PSI_file_locker;
+
+/**
+  Interface for an instrumented socket operation.
+  This is an opaque structure.
+*/
+struct PSI_socket_locker;
+typedef struct PSI_socket_locker PSI_socket_locker;
 
 /** Operation performed on an instrumented mutex. */
 enum PSI_mutex_operation
@@ -311,6 +333,7 @@ enum PSI_mutex_operation
   /** Lock attempt. */
   PSI_MUTEX_TRYLOCK= 1
 };
+typedef enum PSI_mutex_operation PSI_mutex_operation;
 
 /** Operation performed on an instrumented rwlock. */
 enum PSI_rwlock_operation
@@ -324,6 +347,7 @@ enum PSI_rwlock_operation
   /** Write lock attempt. */
   PSI_RWLOCK_TRYWRITELOCK= 3
 };
+typedef enum PSI_rwlock_operation PSI_rwlock_operation;
 
 /** Operation performed on an instrumented condition. */
 enum PSI_cond_operation
@@ -333,6 +357,7 @@ enum PSI_cond_operation
   /** Wait, with timeout. */
   PSI_COND_TIMEDWAIT= 1
 };
+typedef enum PSI_cond_operation PSI_cond_operation;
 
 /** Operation performed on an instrumented file. */
 enum PSI_file_operation
@@ -378,6 +403,7 @@ enum PSI_file_operation
   /** File sync, as in @c fsync() or @c my_sync(). */
   PSI_FILE_SYNC= 16
 };
+typedef enum PSI_file_operation PSI_file_operation;
 
 /** IO operation performed on an instrumented table. */
 enum PSI_table_io_operation
@@ -391,6 +417,7 @@ enum PSI_table_io_operation
   /** Row delete. */
   PSI_TABLE_DELETE_ROW= 3
 };
+typedef enum PSI_table_io_operation PSI_table_io_operation;
 
 /** Lock operation performed on an instrumented table. */
 enum PSI_table_lock_operation
@@ -400,6 +427,7 @@ enum PSI_table_lock_operation
   /** Table lock, in the storage engine layer. */
   PSI_TABLE_EXTERNAL_LOCK= 1
 };
+typedef enum PSI_table_lock_operation PSI_table_lock_operation;
 
 /** State of an instrumented socket. */
 enum PSI_socket_state
@@ -409,6 +437,7 @@ enum PSI_socket_state
   /** Active, executing a command. */
   PSI_SOCKET_STATE_ACTIVE= 2
 };
+typedef enum PSI_socket_state PSI_socket_state;
 
 /** Operation performed on an instrumented socket. */
 enum PSI_socket_operation
@@ -444,6 +473,7 @@ enum PSI_socket_operation
   /** Socket select, as in @c select() and @c poll(). */
   PSI_SOCKET_SELECT= 14
 };
+typedef enum PSI_socket_operation PSI_socket_operation;
 
 /**
   Instrumented mutex key.
@@ -736,13 +766,13 @@ struct PSI_idle_locker_state_v1
 };
 
 /**
-  State data storage for @c get_thread_mutex_locker_v1_t.
+  State data storage for @c start_mutex_wait_v1_t.
   This structure provide temporary storage to a mutex locker.
   The content of this structure is considered opaque,
   the fields are only hints of what an implementation
   of the psi interface can use.
   This memory is provided by the instrumented code for performance reasons.
-  @sa get_thread_mutex_locker_v1_t
+  @sa start_mutex_wait_v1_t
 */
 struct PSI_mutex_locker_state_v1
 {
@@ -763,13 +793,14 @@ struct PSI_mutex_locker_state_v1
 };
 
 /**
-  State data storage for @c get_thread_rwlock_locker_v1_t.
+  State data storage for @c start_rwlock_rdwait_v1_t, @c start_rwlock_wrwait_v1_t.
   This structure provide temporary storage to a rwlock locker.
   The content of this structure is considered opaque,
   the fields are only hints of what an implementation
   of the psi interface can use.
   This memory is provided by the instrumented code for performance reasons.
-  @sa get_thread_rwlock_locker_v1_t
+  @sa start_rwlock_rdwait_v1_t
+  @sa start_rwlock_wrwait_v1_t
 */
 struct PSI_rwlock_locker_state_v1
 {
@@ -790,13 +821,13 @@ struct PSI_rwlock_locker_state_v1
 };
 
 /**
-  State data storage for @c get_thread_cond_locker_v1_t.
+  State data storage for @c start_cond_wait_v1_t.
   This structure provide temporary storage to a condition locker.
   The content of this structure is considered opaque,
   the fields are only hints of what an implementation
   of the psi interface can use.
   This memory is provided by the instrumented code for performance reasons.
-  @sa get_thread_cond_locker_v1_t
+  @sa start_cond_wait_v1_t
 */
 struct PSI_cond_locker_state_v1
 {
@@ -850,15 +881,15 @@ struct PSI_file_locker_state_v1
 };
 
 /**
-  State data storage for @c get_thread_table_io_locker_v1_t,
-  @c get_thread_table_lock_locker_v1_t.
+  State data storage for @c start_table_io_wait_v1_t,
+  @c start_table_lock_wait_v1_t.
   This structure provide temporary storage to a table locker.
   The content of this structure is considered opaque,
   the fields are only hints of what an implementation
   of the psi interface can use.
   This memory is provided by the instrumented code for performance reasons.
-  @sa get_thread_table_io_locker_v1_t
-  @sa get_thread_table_lock_locker_v1_t
+  @sa start_table_io_wait_v1_t
+  @sa start_table_lock_wait_v1_t
 */
 struct PSI_table_locker_state_v1
 {
@@ -947,13 +978,13 @@ struct PSI_statement_locker_state_v1
 };
 
 /**
-  State data storage for @c get_thread_socket_locker_v1_t.
+  State data storage for @c start_socket_wait_v1_t.
   This structure provide temporary storage to a socket locker.
   The content of this structure is considered opaque,
   the fields are only hints of what an implementation
   of the psi interface can use.
   This memory is provided by the instrumented code for performance reasons.
-  @sa get_thread_socket_locker_v1_t
+  @sa start_socket_wait_v1_t
 */
 struct PSI_socket_locker_state_v1
 {
@@ -1130,13 +1161,14 @@ typedef void (*release_table_share_v1_t)
 
 /**
   Drop a table share.
+  @param temporary True for temporary tables
   @param schema_name the table schema name
   @param schema_name_length the table schema name length
   @param table_name the table name
   @param table_name_length the table name length
 */
 typedef void (*drop_table_share_v1_t)
-  (const char *schema_name, int schema_name_length,
+  (my_bool temporary, const char *schema_name, int schema_name_length,
    const char *table_name, int table_name_length);
 
 /**
@@ -1162,8 +1194,8 @@ typedef void (*unbind_table_v1_t)
   is reused for a thread.
   @param table the table to unbind
 */
-typedef void (*rebind_table_v1_t)
-  (struct PSI_table *table);
+typedef PSI_table* (*rebind_table_v1_t)
+  (PSI_table_share *share, const void *identity, PSI_table *table);
 
 /**
   Close an instrumentation table handle.
@@ -1290,64 +1322,6 @@ typedef void (*delete_current_thread_v1_
 typedef void (*delete_thread_v1_t)(struct PSI_thread *thread);
 
 /**
-  Get a mutex instrumentation locker.
-  @param state data storage for the locker
-  @param mutex the instrumented mutex to lock
-  @return a mutex locker, or NULL
-*/
-typedef struct PSI_mutex_locker* (*get_thread_mutex_locker_v1_t)
-  (struct PSI_mutex_locker_state_v1 *state,
-   struct PSI_mutex *mutex,
-   enum PSI_mutex_operation op);
-
-/**
-  Get a rwlock instrumentation locker.
-  @param state data storage for the locker
-  @param rwlock the instrumented rwlock to lock
-  @return a rwlock locker, or NULL
-*/
-typedef struct PSI_rwlock_locker* (*get_thread_rwlock_locker_v1_t)
-  (struct PSI_rwlock_locker_state_v1 *state,
-   struct PSI_rwlock *rwlock,
-   enum PSI_rwlock_operation op);
-
-/**
-  Get a cond instrumentation locker.
-  @param state data storage for the locker
-  @param cond the instrumented condition to wait on
-  @param mutex the instrumented mutex associated with the condition
-  @return a condition locker, or NULL
-*/
-typedef struct PSI_cond_locker* (*get_thread_cond_locker_v1_t)
-  (struct PSI_cond_locker_state_v1 *state,
-   struct PSI_cond *cond, struct PSI_mutex *mutex,
-   enum PSI_cond_operation op);
-
-/**
-  Get a table instrumentation io locker.
-  @param state data storage for the locker
-  @param table the instrumented table to lock
-  @param op the operation to be performed
-  @param index the index used if any, or MAX_KEY
-  @return a table locker, or NULL
-*/
-typedef struct PSI_table_locker* (*get_thread_table_io_locker_v1_t)
-  (struct PSI_table_locker_state_v1 *state,
-   struct PSI_table *table, enum PSI_table_io_operation op, uint index);
-
-/**
-  Get a table instrumentation lock locker.
-  @param state data storage for the locker
-  @param table the instrumented table to lock
-  @param op the operation to be performed
-  @param flags Per operation flags
-  @return a table locker, or NULL
-*/
-typedef struct PSI_table_locker* (*get_thread_table_lock_locker_v1_t)
-  (struct PSI_table_locker_state_v1 *state,
-   struct PSI_table *table, enum PSI_table_lock_operation op, ulong flags);
-
-/**
   Get a file instrumentation locker, for opening or creating a file.
   @param state data storage for the locker
   @param key the file instrumentation key
@@ -1384,17 +1358,6 @@ typedef struct PSI_file_locker* (*get_th
    File file, enum PSI_file_operation op);
 
 /**
-  Get a socket instrumentation locker.
-  @param state data storage for the locker
-  @param socket the socket to access
-  @param op the operation to perform
-  @return a socket locker, or NULL
-*/
-typedef struct PSI_socket_locker* (*get_thread_socket_locker_v1_t)
-  (struct PSI_socket_locker_state_v1 *state,
-   struct PSI_socket *socket, enum PSI_socket_operation op);
-
-/**
   Record a mutex instrumentation unlock event.
   @param mutex the mutex instrumentation
 */
@@ -1430,10 +1393,18 @@ typedef void (*end_idle_wait_v1_t)
 
 /**
   Record a mutex instrumentation wait start event.
-  @param locker a thread locker for the running thread
+  @param state data storage for the locker
+  @param mutex the instrumented mutex to lock
+  @param op the operation to perform
+  @param file the source file name
+  @param line the source line number
+  @return a mutex locker, or NULL
 */
-typedef void (*start_mutex_wait_v1_t)
-  (struct PSI_mutex_locker *locker, const char *src_file, uint src_line);
+typedef struct PSI_mutex_locker* (*start_mutex_wait_v1_t)
+  (struct PSI_mutex_locker_state_v1 *state,
+   struct PSI_mutex *mutex,
+   enum PSI_mutex_operation op,
+   const char *src_file, uint src_line);
 
 /**
   Record a mutex instrumentation wait end event.
@@ -1448,8 +1419,11 @@ typedef void (*end_mutex_wait_v1_t)
   @param locker a thread locker for the running thread
   @param must must block: 1 for lock, 0 for trylock
 */
-typedef void (*start_rwlock_rdwait_v1_t)
-  (struct PSI_rwlock_locker *locker, const char *src_file, uint src_line);
+typedef struct PSI_rwlock_locker* (*start_rwlock_rdwait_v1_t)
+  (struct PSI_rwlock_locker_state_v1 *state,
+   struct PSI_rwlock *rwlock,
+   enum PSI_rwlock_operation op,
+   const char *src_file, uint src_line);
 
 /**
   Record a rwlock instrumentation read wait end event.
@@ -1464,8 +1438,11 @@ typedef void (*end_rwlock_rdwait_v1_t)
   @param locker a thread locker for the running thread
   @param must must block: 1 for lock, 0 for trylock
 */
-typedef void (*start_rwlock_wrwait_v1_t)
-  (struct PSI_rwlock_locker *locker, const char *src_file, uint src_line);
+typedef struct PSI_rwlock_locker* (*start_rwlock_wrwait_v1_t)
+  (struct PSI_rwlock_locker_state_v1 *state,
+   struct PSI_rwlock *rwlock,
+   enum PSI_rwlock_operation op,
+   const char *src_file, uint src_line);
 
 /**
   Record a rwlock instrumentation write wait end event.
@@ -1480,8 +1457,12 @@ typedef void (*end_rwlock_wrwait_v1_t)
   @param locker a thread locker for the running thread
   @param must must block: 1 for wait, 0 for timedwait
 */
-typedef void (*start_cond_wait_v1_t)
-  (struct PSI_cond_locker *locker, const char *src_file, uint src_line);
+typedef struct PSI_cond_locker* (*start_cond_wait_v1_t)
+  (struct PSI_cond_locker_state_v1 *state,
+   struct PSI_cond *cond,
+   struct PSI_mutex *mutex,
+   enum PSI_cond_operation op,
+   const char *src_file, uint src_line);
 
 /**
   Record a condition instrumentation wait end event.
@@ -1497,8 +1478,12 @@ typedef void (*end_cond_wait_v1_t)
   @param file the source file name
   @param line the source line number
 */
-typedef void (*start_table_io_wait_v1_t)
-  (struct PSI_table_locker *locker, const char *src_file, uint src_line);
+typedef struct PSI_table_locker* (*start_table_io_wait_v1_t)
+  (struct PSI_table_locker_state_v1 *state,
+   struct PSI_table *table,
+   enum PSI_table_io_operation op,
+   uint index,
+   const char *src_file, uint src_line);
 
 /**
   Record a table instrumentation io wait end event.
@@ -1512,8 +1497,12 @@ typedef void (*end_table_io_wait_v1_t)(s
   @param file the source file name
   @param line the source line number
 */
-typedef void (*start_table_lock_wait_v1_t)
-  (struct PSI_table_locker *locker, const char *src_file, uint src_line);
+typedef struct PSI_table_locker* (*start_table_lock_wait_v1_t)
+  (struct PSI_table_locker_state_v1 *state,
+   struct PSI_table *table,
+   enum PSI_table_lock_operation op,
+   ulong flags,
+   const char *src_file, uint src_line);
 
 /**
   Record a table instrumentation lock wait end event.
@@ -1774,8 +1763,11 @@ typedef void (*end_statement_v1_t)
   @param src_file the source file name
   @param src_line the source line number
 */
-typedef void (*start_socket_wait_v1_t)
-  (struct PSI_socket_locker *locker, size_t count,
+typedef struct PSI_socket_locker* (*start_socket_wait_v1_t)
+  (struct PSI_socket_locker_state_v1 *state,
+   struct PSI_socket *socket,
+   enum PSI_socket_operation op,
+   size_t count,
    const char *src_file, uint src_line);
 
 /**
@@ -1900,24 +1892,12 @@ struct PSI_v1
   delete_current_thread_v1_t delete_current_thread;
   /** @sa delete_thread_v1_t. */
   delete_thread_v1_t delete_thread;
-  /** @sa get_thread_mutex_locker_v1_t. */
-  get_thread_mutex_locker_v1_t get_thread_mutex_locker;
-  /** @sa get_thread_rwlock_locker_v1_t. */
-  get_thread_rwlock_locker_v1_t get_thread_rwlock_locker;
-  /** @sa get_thread_cond_locker_v1_t. */
-  get_thread_cond_locker_v1_t get_thread_cond_locker;
-  /** @sa get_thread_table_io_locker_v1_t. */
-  get_thread_table_io_locker_v1_t get_thread_table_io_locker;
-  /** @sa get_thread_table_lock_locker_v1_t. */
-  get_thread_table_lock_locker_v1_t get_thread_table_lock_locker;
   /** @sa get_thread_file_name_locker_v1_t. */
   get_thread_file_name_locker_v1_t get_thread_file_name_locker;
   /** @sa get_thread_file_stream_locker_v1_t. */
   get_thread_file_stream_locker_v1_t get_thread_file_stream_locker;
   /** @sa get_thread_file_descriptor_locker_v1_t. */
   get_thread_file_descriptor_locker_v1_t get_thread_file_descriptor_locker;
-  /** @sa get_thread_socket_locker_v1_t. */
-  get_thread_socket_locker_v1_t get_thread_socket_locker;
   /** @sa unlock_mutex_v1_t. */
   unlock_mutex_v1_t unlock_mutex;
   /** @sa unlock_rwlock_v1_t. */

=== modified file 'include/mysql/psi/psi_abi_v0.h.pp'
--- a/include/mysql/psi/psi_abi_v0.h.pp	2011-11-02 23:29:01 +0000
+++ b/include/mysql/psi/psi_abi_v0.h.pp	2012-01-06 09:03:53 +0000
@@ -2,20 +2,32 @@
 C_MODE_START
 struct TABLE_SHARE;
 struct PSI_mutex;
+typedef struct PSI_mutex PSI_mutex;
 struct PSI_rwlock;
+typedef struct PSI_rwlock PSI_rwlock;
 struct PSI_cond;
+typedef struct PSI_cond PSI_cond;
 struct PSI_table_share;
+typedef struct PSI_table_share PSI_table_share;
 struct PSI_table;
+typedef struct PSI_table PSI_table;
 struct PSI_thread;
+typedef struct PSI_thread PSI_thread;
 struct PSI_file;
+typedef struct PSI_file PSI_file;
 struct PSI_socket;
+typedef struct PSI_socket PSI_socket;
 struct PSI_table_locker;
+typedef struct PSI_table_locker PSI_table_locker;
 struct PSI_statement_locker;
+typedef struct PSI_statement_locker PSI_statement_locker;
 struct PSI_idle_locker;
+typedef struct PSI_idle_locker PSI_idle_locker;
 struct PSI_bootstrap
 {
   void* (*get_interface)(int version);
 };
+typedef struct PSI_bootstrap PSI_bootstrap;
 struct PSI_none
 {
   int opaque;

=== modified file 'include/mysql/psi/psi_abi_v1.h.pp'
--- a/include/mysql/psi/psi_abi_v1.h.pp	2011-11-02 23:29:01 +0000
+++ b/include/mysql/psi/psi_abi_v1.h.pp	2012-01-06 09:03:53 +0000
@@ -2,29 +2,48 @@
 C_MODE_START
 struct TABLE_SHARE;
 struct PSI_mutex;
+typedef struct PSI_mutex PSI_mutex;
 struct PSI_rwlock;
+typedef struct PSI_rwlock PSI_rwlock;
 struct PSI_cond;
+typedef struct PSI_cond PSI_cond;
 struct PSI_table_share;
+typedef struct PSI_table_share PSI_table_share;
 struct PSI_table;
+typedef struct PSI_table PSI_table;
 struct PSI_thread;
+typedef struct PSI_thread PSI_thread;
 struct PSI_file;
+typedef struct PSI_file PSI_file;
 struct PSI_socket;
+typedef struct PSI_socket PSI_socket;
 struct PSI_table_locker;
+typedef struct PSI_table_locker PSI_table_locker;
 struct PSI_statement_locker;
+typedef struct PSI_statement_locker PSI_statement_locker;
 struct PSI_idle_locker;
+typedef struct PSI_idle_locker PSI_idle_locker;
 struct PSI_bootstrap
 {
   void* (*get_interface)(int version);
 };
+typedef struct PSI_bootstrap PSI_bootstrap;
 struct PSI_mutex_locker;
+typedef struct PSI_mutex_locker PSI_mutex_locker;
 struct PSI_rwlock_locker;
+typedef struct PSI_rwlock_locker PSI_rwlock_locker;
 struct PSI_cond_locker;
+typedef struct PSI_cond_locker PSI_cond_locker;
 struct PSI_file_locker;
+typedef struct PSI_file_locker PSI_file_locker;
+struct PSI_socket_locker;
+typedef struct PSI_socket_locker PSI_socket_locker;
 enum PSI_mutex_operation
 {
   PSI_MUTEX_LOCK= 0,
   PSI_MUTEX_TRYLOCK= 1
 };
+typedef enum PSI_mutex_operation PSI_mutex_operation;
 enum PSI_rwlock_operation
 {
   PSI_RWLOCK_READLOCK= 0,
@@ -32,11 +51,13 @@ enum PSI_rwlock_operation
   PSI_RWLOCK_TRYREADLOCK= 2,
   PSI_RWLOCK_TRYWRITELOCK= 3
 };
+typedef enum PSI_rwlock_operation PSI_rwlock_operation;
 enum PSI_cond_operation
 {
   PSI_COND_WAIT= 0,
   PSI_COND_TIMEDWAIT= 1
 };
+typedef enum PSI_cond_operation PSI_cond_operation;
 enum PSI_file_operation
 {
   PSI_FILE_CREATE= 0,
@@ -57,6 +78,7 @@ enum PSI_file_operation
   PSI_FILE_RENAME= 15,
   PSI_FILE_SYNC= 16
 };
+typedef enum PSI_file_operation PSI_file_operation;
 enum PSI_table_io_operation
 {
   PSI_TABLE_FETCH_ROW= 0,
@@ -64,16 +86,19 @@ enum PSI_table_io_operation
   PSI_TABLE_UPDATE_ROW= 2,
   PSI_TABLE_DELETE_ROW= 3
 };
+typedef enum PSI_table_io_operation PSI_table_io_operation;
 enum PSI_table_lock_operation
 {
   PSI_TABLE_LOCK= 0,
   PSI_TABLE_EXTERNAL_LOCK= 1
 };
+typedef enum PSI_table_lock_operation PSI_table_lock_operation;
 enum PSI_socket_state
 {
   PSI_SOCKET_STATE_IDLE= 1,
   PSI_SOCKET_STATE_ACTIVE= 2
 };
+typedef enum PSI_socket_state PSI_socket_state;
 enum PSI_socket_operation
 {
   PSI_SOCKET_CREATE= 0,
@@ -92,6 +117,7 @@ enum PSI_socket_operation
   PSI_SOCKET_SHUTDOWN= 13,
   PSI_SOCKET_SELECT= 14
 };
+typedef enum PSI_socket_operation PSI_socket_operation;
 typedef unsigned int PSI_mutex_key;
 typedef unsigned int PSI_rwlock_key;
 typedef unsigned int PSI_cond_key;
@@ -281,14 +307,14 @@ typedef struct PSI_table_share* (*get_ta
   (my_bool temporary, struct TABLE_SHARE *share);
 typedef void (*release_table_share_v1_t)(struct PSI_table_share *share);
 typedef void (*drop_table_share_v1_t)
-  (const char *schema_name, int schema_name_length,
+  (my_bool temporary, const char *schema_name, int schema_name_length,
    const char *table_name, int table_name_length);
 typedef struct PSI_table* (*open_table_v1_t)
   (struct PSI_table_share *share, const void *identity);
 typedef void (*unbind_table_v1_t)
   (struct PSI_table *table);
-typedef void (*rebind_table_v1_t)
-  (struct PSI_table *table);
+typedef PSI_table* (*rebind_table_v1_t)
+  (PSI_table_share *share, const void *identity, PSI_table *table);
 typedef void (*close_table_v1_t)(struct PSI_table *table);
 typedef void (*create_file_v1_t)(PSI_file_key key, const char *name,
                                  File file);
@@ -312,24 +338,6 @@ typedef void (*set_thread_info_v1_t)(con
 typedef void (*set_thread_v1_t)(struct PSI_thread *thread);
 typedef void (*delete_current_thread_v1_t)(void);
 typedef void (*delete_thread_v1_t)(struct PSI_thread *thread);
-typedef struct PSI_mutex_locker* (*get_thread_mutex_locker_v1_t)
-  (struct PSI_mutex_locker_state_v1 *state,
-   struct PSI_mutex *mutex,
-   enum PSI_mutex_operation op);
-typedef struct PSI_rwlock_locker* (*get_thread_rwlock_locker_v1_t)
-  (struct PSI_rwlock_locker_state_v1 *state,
-   struct PSI_rwlock *rwlock,
-   enum PSI_rwlock_operation op);
-typedef struct PSI_cond_locker* (*get_thread_cond_locker_v1_t)
-  (struct PSI_cond_locker_state_v1 *state,
-   struct PSI_cond *cond, struct PSI_mutex *mutex,
-   enum PSI_cond_operation op);
-typedef struct PSI_table_locker* (*get_thread_table_io_locker_v1_t)
-  (struct PSI_table_locker_state_v1 *state,
-   struct PSI_table *table, enum PSI_table_io_operation op, uint index);
-typedef struct PSI_table_locker* (*get_thread_table_lock_locker_v1_t)
-  (struct PSI_table_locker_state_v1 *state,
-   struct PSI_table *table, enum PSI_table_lock_operation op, ulong flags);
 typedef struct PSI_file_locker* (*get_thread_file_name_locker_v1_t)
   (struct PSI_file_locker_state_v1 *state,
    PSI_file_key key, enum PSI_file_operation op, const char *name,
@@ -340,9 +348,6 @@ typedef struct PSI_file_locker* (*get_th
 typedef struct PSI_file_locker* (*get_thread_file_descriptor_locker_v1_t)
   (struct PSI_file_locker_state_v1 *state,
    File file, enum PSI_file_operation op);
-typedef struct PSI_socket_locker* (*get_thread_socket_locker_v1_t)
-  (struct PSI_socket_locker_state_v1 *state,
-   struct PSI_socket *socket, enum PSI_socket_operation op);
 typedef void (*unlock_mutex_v1_t)
   (struct PSI_mutex *mutex);
 typedef void (*unlock_rwlock_v1_t)
@@ -355,27 +360,48 @@ typedef struct PSI_idle_locker* (*start_
   (struct PSI_idle_locker_state_v1 *state, const char *src_file, uint src_line);
 typedef void (*end_idle_wait_v1_t)
   (struct PSI_idle_locker *locker);
-typedef void (*start_mutex_wait_v1_t)
-  (struct PSI_mutex_locker *locker, const char *src_file, uint src_line);
+typedef struct PSI_mutex_locker* (*start_mutex_wait_v1_t)
+  (struct PSI_mutex_locker_state_v1 *state,
+   struct PSI_mutex *mutex,
+   enum PSI_mutex_operation op,
+   const char *src_file, uint src_line);
 typedef void (*end_mutex_wait_v1_t)
   (struct PSI_mutex_locker *locker, int rc);
-typedef void (*start_rwlock_rdwait_v1_t)
-  (struct PSI_rwlock_locker *locker, const char *src_file, uint src_line);
+typedef struct PSI_rwlock_locker* (*start_rwlock_rdwait_v1_t)
+  (struct PSI_rwlock_locker_state_v1 *state,
+   struct PSI_rwlock *rwlock,
+   enum PSI_rwlock_operation op,
+   const char *src_file, uint src_line);
 typedef void (*end_rwlock_rdwait_v1_t)
   (struct PSI_rwlock_locker *locker, int rc);
-typedef void (*start_rwlock_wrwait_v1_t)
-  (struct PSI_rwlock_locker *locker, const char *src_file, uint src_line);
+typedef struct PSI_rwlock_locker* (*start_rwlock_wrwait_v1_t)
+  (struct PSI_rwlock_locker_state_v1 *state,
+   struct PSI_rwlock *rwlock,
+   enum PSI_rwlock_operation op,
+   const char *src_file, uint src_line);
 typedef void (*end_rwlock_wrwait_v1_t)
   (struct PSI_rwlock_locker *locker, int rc);
-typedef void (*start_cond_wait_v1_t)
-  (struct PSI_cond_locker *locker, const char *src_file, uint src_line);
+typedef struct PSI_cond_locker* (*start_cond_wait_v1_t)
+  (struct PSI_cond_locker_state_v1 *state,
+   struct PSI_cond *cond,
+   struct PSI_mutex *mutex,
+   enum PSI_cond_operation op,
+   const char *src_file, uint src_line);
 typedef void (*end_cond_wait_v1_t)
   (struct PSI_cond_locker *locker, int rc);
-typedef void (*start_table_io_wait_v1_t)
-  (struct PSI_table_locker *locker, const char *src_file, uint src_line);
+typedef struct PSI_table_locker* (*start_table_io_wait_v1_t)
+  (struct PSI_table_locker_state_v1 *state,
+   struct PSI_table *table,
+   enum PSI_table_io_operation op,
+   uint index,
+   const char *src_file, uint src_line);
 typedef void (*end_table_io_wait_v1_t)(struct PSI_table_locker *locker);
-typedef void (*start_table_lock_wait_v1_t)
-  (struct PSI_table_locker *locker, const char *src_file, uint src_line);
+typedef struct PSI_table_locker* (*start_table_lock_wait_v1_t)
+  (struct PSI_table_locker_state_v1 *state,
+   struct PSI_table *table,
+   enum PSI_table_lock_operation op,
+   ulong flags,
+   const char *src_file, uint src_line);
 typedef void (*end_table_lock_wait_v1_t)(struct PSI_table_locker *locker);
 typedef struct PSI_file* (*start_file_open_wait_v1_t)
   (struct PSI_file_locker *locker, const char *src_file, uint src_line);
@@ -437,8 +463,11 @@ typedef void (*set_statement_no_good_ind
   (struct PSI_statement_locker *locker);
 typedef void (*end_statement_v1_t)
   (struct PSI_statement_locker *locker, void *stmt_da);
-typedef void (*start_socket_wait_v1_t)
-  (struct PSI_socket_locker *locker, size_t count,
+typedef struct PSI_socket_locker* (*start_socket_wait_v1_t)
+  (struct PSI_socket_locker_state_v1 *state,
+   struct PSI_socket *socket,
+   enum PSI_socket_operation op,
+   size_t count,
    const char *src_file, uint src_line);
 typedef void (*end_socket_wait_v1_t)
   (struct PSI_socket_locker *locker, size_t count);
@@ -489,15 +518,9 @@ struct PSI_v1
   set_thread_v1_t set_thread;
   delete_current_thread_v1_t delete_current_thread;
   delete_thread_v1_t delete_thread;
-  get_thread_mutex_locker_v1_t get_thread_mutex_locker;
-  get_thread_rwlock_locker_v1_t get_thread_rwlock_locker;
-  get_thread_cond_locker_v1_t get_thread_cond_locker;
-  get_thread_table_io_locker_v1_t get_thread_table_io_locker;
-  get_thread_table_lock_locker_v1_t get_thread_table_lock_locker;
   get_thread_file_name_locker_v1_t get_thread_file_name_locker;
   get_thread_file_stream_locker_v1_t get_thread_file_stream_locker;
   get_thread_file_descriptor_locker_v1_t get_thread_file_descriptor_locker;
-  get_thread_socket_locker_v1_t get_thread_socket_locker;
   unlock_mutex_v1_t unlock_mutex;
   unlock_rwlock_v1_t unlock_rwlock;
   signal_cond_v1_t signal_cond;

=== modified file 'include/mysql/psi/psi_abi_v2.h.pp'
--- a/include/mysql/psi/psi_abi_v2.h.pp	2011-11-02 23:29:01 +0000
+++ b/include/mysql/psi/psi_abi_v2.h.pp	2012-01-06 09:03:53 +0000
@@ -2,29 +2,48 @@
 C_MODE_START
 struct TABLE_SHARE;
 struct PSI_mutex;
+typedef struct PSI_mutex PSI_mutex;
 struct PSI_rwlock;
+typedef struct PSI_rwlock PSI_rwlock;
 struct PSI_cond;
+typedef struct PSI_cond PSI_cond;
 struct PSI_table_share;
+typedef struct PSI_table_share PSI_table_share;
 struct PSI_table;
+typedef struct PSI_table PSI_table;
 struct PSI_thread;
+typedef struct PSI_thread PSI_thread;
 struct PSI_file;
+typedef struct PSI_file PSI_file;
 struct PSI_socket;
+typedef struct PSI_socket PSI_socket;
 struct PSI_table_locker;
+typedef struct PSI_table_locker PSI_table_locker;
 struct PSI_statement_locker;
+typedef struct PSI_statement_locker PSI_statement_locker;
 struct PSI_idle_locker;
+typedef struct PSI_idle_locker PSI_idle_locker;
 struct PSI_bootstrap
 {
   void* (*get_interface)(int version);
 };
+typedef struct PSI_bootstrap PSI_bootstrap;
 struct PSI_mutex_locker;
+typedef struct PSI_mutex_locker PSI_mutex_locker;
 struct PSI_rwlock_locker;
+typedef struct PSI_rwlock_locker PSI_rwlock_locker;
 struct PSI_cond_locker;
+typedef struct PSI_cond_locker PSI_cond_locker;
 struct PSI_file_locker;
+typedef struct PSI_file_locker PSI_file_locker;
+struct PSI_socket_locker;
+typedef struct PSI_socket_locker PSI_socket_locker;
 enum PSI_mutex_operation
 {
   PSI_MUTEX_LOCK= 0,
   PSI_MUTEX_TRYLOCK= 1
 };
+typedef enum PSI_mutex_operation PSI_mutex_operation;
 enum PSI_rwlock_operation
 {
   PSI_RWLOCK_READLOCK= 0,
@@ -32,11 +51,13 @@ enum PSI_rwlock_operation
   PSI_RWLOCK_TRYREADLOCK= 2,
   PSI_RWLOCK_TRYWRITELOCK= 3
 };
+typedef enum PSI_rwlock_operation PSI_rwlock_operation;
 enum PSI_cond_operation
 {
   PSI_COND_WAIT= 0,
   PSI_COND_TIMEDWAIT= 1
 };
+typedef enum PSI_cond_operation PSI_cond_operation;
 enum PSI_file_operation
 {
   PSI_FILE_CREATE= 0,
@@ -57,6 +78,7 @@ enum PSI_file_operation
   PSI_FILE_RENAME= 15,
   PSI_FILE_SYNC= 16
 };
+typedef enum PSI_file_operation PSI_file_operation;
 enum PSI_table_io_operation
 {
   PSI_TABLE_FETCH_ROW= 0,
@@ -64,16 +86,19 @@ enum PSI_table_io_operation
   PSI_TABLE_UPDATE_ROW= 2,
   PSI_TABLE_DELETE_ROW= 3
 };
+typedef enum PSI_table_io_operation PSI_table_io_operation;
 enum PSI_table_lock_operation
 {
   PSI_TABLE_LOCK= 0,
   PSI_TABLE_EXTERNAL_LOCK= 1
 };
+typedef enum PSI_table_lock_operation PSI_table_lock_operation;
 enum PSI_socket_state
 {
   PSI_SOCKET_STATE_IDLE= 1,
   PSI_SOCKET_STATE_ACTIVE= 2
 };
+typedef enum PSI_socket_state PSI_socket_state;
 enum PSI_socket_operation
 {
   PSI_SOCKET_CREATE= 0,
@@ -92,6 +117,7 @@ enum PSI_socket_operation
   PSI_SOCKET_SHUTDOWN= 13,
   PSI_SOCKET_SELECT= 14
 };
+typedef enum PSI_socket_operation PSI_socket_operation;
 typedef unsigned int PSI_mutex_key;
 typedef unsigned int PSI_rwlock_key;
 typedef unsigned int PSI_cond_key;

=== modified file 'mysql-test/include/show_slave_status.inc'
--- a/mysql-test/include/show_slave_status.inc	2010-12-20 14:57:35 +0000
+++ b/mysql-test/include/show_slave_status.inc	2012-01-04 15:48:00 +0000
@@ -55,6 +55,11 @@
 #     comma-separated list. Example:
 #
 #       --let $status_items= Master_Log_File, Relay_Master_Log_File
+#
+#   $slave_io_error_replace
+#     If set, one or more regex patterns for replacing variable
+#     text in the error message. Syntax as --replace-regex
+#
 
 
 --let $_show_slave_status_items= $status_items
@@ -70,6 +75,7 @@ while ($_show_slave_status_items)
   --let $_show_slave_status_items= `SELECT LTRIM(SUBSTRING('$_show_slave_status_items', LENGTH('$_show_slave_status_name') + 2))`
 
   --let $_show_slave_status_value= query_get_value(SHOW SLAVE STATUS, $_show_slave_status_name, 1)
+  --replace_regex $slave_io_error_replace
   --let $_show_slave_status_value= `SELECT REPLACE("$_show_slave_status_value", '$MYSQL_TEST_DIR', 'MYSQL_TEST_DIR')`
   --echo $_show_slave_status_name = '$_show_slave_status_value'
 }

=== modified file 'mysql-test/r/myisampack.result'
--- a/mysql-test/r/myisampack.result	2011-11-28 07:42:18 +0000
+++ b/mysql-test/r/myisampack.result	2012-01-09 07:26:17 +0000
@@ -150,3 +150,10 @@ CHECK TABLE t1;
 Table	Op	Msg_type	Msg_text
 test.t1	check	status	OK
 DROP TABLE t1;
+#
+# BUG#11751736: DROP DATABASE STATEMENT SHOULD REMOVE .OLD SUFFIX FROM 
+# DATABASE DIRECTORY 
+#
+CREATE DATABASE db1;
+CREATE TABLE db1.t1(c1 INT) ENGINE=MyISAM;
+DROP DATABASE db1;

=== modified file 'mysql-test/suite/binlog/r/binlog_stm_unsafe_warning.result'
--- a/mysql-test/suite/binlog/r/binlog_stm_unsafe_warning.result	2010-08-10 11:58:46 +0000
+++ b/mysql-test/suite/binlog/r/binlog_stm_unsafe_warning.result	2012-01-06 10:28:00 +0000
@@ -54,13 +54,13 @@ USE test;
 #
 SET @old_log_warnings = @@log_warnings;
 DROP TABLE IF EXISTS t1;
-CREATE TABLE t1 (a VARCHAR(36), b VARCHAR(10));
+CREATE TABLE t1 (a VARCHAR(36), b VARCHAR(15));
 SET GLOBAL LOG_WARNINGS = 0;
-INSERT INTO t1 VALUES(UUID(), 'Bug#46265');
+INSERT INTO t1 VALUES(UUID(), 'timestamp');
 Warnings:
 Note	1592	Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. Statement is unsafe because it uses a system function that may return a different value on the slave.
 SET GLOBAL LOG_WARNINGS = 1;
-INSERT INTO t1 VALUES(UUID(), 'Bug#46265');
+INSERT INTO t1 VALUES(UUID(), 'timestamp');
 Warnings:
 Note	1592	Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. Statement is unsafe because it uses a system function that may return a different value on the slave.
 DROP TABLE t1;

=== modified file 'mysql-test/suite/binlog/t/binlog_stm_unsafe_warning.test'
--- a/mysql-test/suite/binlog/t/binlog_stm_unsafe_warning.test	2010-11-17 10:23:22 +0000
+++ b/mysql-test/suite/binlog/t/binlog_stm_unsafe_warning.test	2012-01-06 10:28:00 +0000
@@ -102,16 +102,24 @@ eval USE $old_db;
 --echo # Bug#46265: Can not disable warning about unsafe statements for binary logging
 --echo #
 
+let BINLOG_COUNTER1= `select CONVERT(NOW(),UNSIGNED) as timestmap from dual`;
+
 SET @old_log_warnings = @@log_warnings;
 
 --disable_warnings
 DROP TABLE IF EXISTS t1;
 --enable_warnings
-CREATE TABLE t1 (a VARCHAR(36), b VARCHAR(10));
+CREATE TABLE t1 (a VARCHAR(36), b VARCHAR(15));
+
 SET GLOBAL LOG_WARNINGS = 0;
-INSERT INTO t1 VALUES(UUID(), 'Bug#46265');
+# Replacing the result file content here.
+# Instead of writing $BINLOG_COUNTER1 value to result file, 
+# writing a fixed string timestamp to it.
+--replace_result $BINLOG_COUNTER1 timestamp
+eval INSERT INTO t1 VALUES(UUID(), '$BINLOG_COUNTER1');
 SET GLOBAL LOG_WARNINGS = 1;
-INSERT INTO t1 VALUES(UUID(), 'Bug#46265');
+--replace_result $BINLOG_COUNTER1 timestamp
+eval INSERT INTO t1 VALUES(UUID(), '$BINLOG_COUNTER1');
 DROP TABLE t1;
 
 SET GLOBAL log_warnings = @old_log_warnings;
@@ -133,13 +141,14 @@ perl;
   use strict;
   my $log_error= $ENV{'LOG_ERROR'} or die "LOG_ERROR not set";
   open(FILE, "$log_error") or die("Unable to open $log_error: $!\n");
-  my $count = () = grep(/Bug#46265/g,<FILE>);
+  my $binlog_counter= $ENV{'BINLOG_COUNTER1'} or die "BINLOG_COUNTER1 not set";
+  my $count = () = grep(/$binlog_counter/g,<FILE>); 
+  # Grep the timestamp value from the error file.
   print "Occurrences: $count\n";
   close(FILE);
 EOF
 
 # bug#50192: diplaying the unsafe warning comes out to the user warning stack
-
 -- disable_warnings
 DROP TABLE IF EXISTS t1, t2;
 -- enable_warnings

=== modified file 'mysql-test/suite/engines/funcs/r/tc_rename_error.result'
--- a/mysql-test/suite/engines/funcs/r/tc_rename_error.result	2010-03-18 06:42:07 +0000
+++ b/mysql-test/suite/engines/funcs/r/tc_rename_error.result	2012-01-06 11:49:46 +0000
@@ -15,7 +15,7 @@ ERROR 42S01: Table 't1' already exists
 RENAME TABLE t3 TO t1;
 ERROR 42S01: Table 't1' already exists
 RENAME TABLE t3 TO doesnotexist.t1;
-ERROR HY000: Can't find file: './test/t3.frm' (errno: 2)
+ERROR HY000: Can't find file: './test/t3.frm' (errno: 2 - No such file or directory)
 SHOW TABLES;
 Tables_in_test
 t1

=== modified file 'mysql-test/suite/perfschema/r/dml_handler.result'
--- a/mysql-test/suite/perfschema/r/dml_handler.result	2011-08-11 03:11:58 +0000
+++ b/mysql-test/suite/perfschema/r/dml_handler.result	2012-01-04 18:29:43 +0000
@@ -153,3 +153,4 @@ ERROR HY000: Table storage engine for 'c
 SELECT TABLE_NAME INTO @table_name FROM table_list WHERE id=1;
 HANDLER performance_schema.accounts OPEN;
 ERROR HY000: Table storage engine for 'accounts' doesn't have this option
+DROP TEMPORARY TABLE table_list;

=== modified file 'mysql-test/suite/perfschema/r/innodb_table_io.result'
--- a/mysql-test/suite/perfschema/r/innodb_table_io.result	2011-08-11 03:11:58 +0000
+++ b/mysql-test/suite/perfschema/r/innodb_table_io.result	2012-01-04 18:29:43 +0000
@@ -107,9 +107,7 @@ wait/io/table/sql/handler	handler.cc:	TA
 wait/io/table/sql/handler	handler.cc:	TABLE	test	no_index_tab	fetch	NULL
 wait/io/table/sql/handler	handler.cc:	TABLE	test	marker	insert	NULL
 wait/io/table/sql/handler	handler.cc:	TABLE	test	no_index_tab	fetch	NULL
-wait/io/table/sql/handler	handler.cc:	TEMPORARY TABLE	test	#sql-XXXX	insert	NULL
 wait/io/table/sql/handler	handler.cc:	TABLE	test	no_index_tab	fetch	NULL
-wait/io/table/sql/handler	handler.cc:	TEMPORARY TABLE	test	#sql-XXXX	insert	NULL
 wait/io/table/sql/handler	handler.cc:	TABLE	test	no_index_tab	fetch	NULL
 wait/io/table/sql/handler	handler.cc:	TABLE	test	marker	insert	NULL
 wait/io/table/sql/handler	handler.cc:	TABLE	test	no_index_tab	fetch	NULL

=== modified file 'mysql-test/suite/perfschema/r/misc.result'
--- a/mysql-test/suite/perfschema/r/misc.result	2011-04-20 17:56:53 +0000
+++ b/mysql-test/suite/perfschema/r/misc.result	2012-01-06 15:54:45 +0000
@@ -1,3 +1,39 @@
+SELECT object_schema, object_name FROM performance_schema.objects_summary_global_by_type
+WHERE object_schema='test';
+object_schema	object_name
+CREATE TABLE test.t_before(a INT);
+INSERT INTO test.t_before VALUES (1);
+SELECT object_schema, object_name FROM performance_schema.objects_summary_global_by_type
+WHERE object_schema='test';
+object_schema	object_name
+test	t_before
+RENAME TABLE test.t_before TO test.t_after;
+SELECT COUNT(*) FROM test.t_after;
+COUNT(*)
+1
+SELECT object_schema, object_name FROM performance_schema.objects_summary_global_by_type
+WHERE object_schema='test';
+object_schema	object_name
+test	t_after
+DROP TABLE test.t_after;
+SELECT object_schema, object_name FROM performance_schema.objects_summary_global_by_type
+WHERE object_schema='test';
+object_schema	object_name
+CREATE TABLE test.t1(a INT);
+INSERT INTO test.t1 VALUES (1);
+CREATE VIEW test.v1 AS SELECT * FROM test.t1;
+SELECT COUNT(*) FROM test.v1;
+COUNT(*)
+1
+SELECT object_schema, object_name FROM performance_schema.objects_summary_global_by_type
+WHERE object_schema='test';
+object_schema	object_name
+test	t1
+DROP VIEW test.v1;
+DROP TABLE test.t1;
+SELECT object_schema, object_name FROM performance_schema.objects_summary_global_by_type
+WHERE object_schema='test';
+object_schema	object_name
 SELECT EVENT_ID FROM performance_schema.events_waits_current
 WHERE THREAD_ID IN
 (SELECT THREAD_ID FROM performance_schema.threads)
@@ -7,10 +43,19 @@ WHERE NAME LIKE "wait/synch/%")
 LIMIT 1;
 create table test.t1(a int) engine=performance_schema;
 ERROR HY000: Can't create table 'test.t1' (errno: 131)
+SELECT object_schema, object_name FROM performance_schema.objects_summary_global_by_type
+WHERE object_schema='test';
+object_schema	object_name
 create table test.t1 like performance_schema.events_waits_current;
 ERROR HY000: Can't create table 'test.t1' (errno: 131)
+SELECT object_schema, object_name FROM performance_schema.objects_summary_global_by_type
+WHERE object_schema='test';
+object_schema	object_name
 create table performance_schema.t1(a int);
 ERROR 42000: CREATE command denied to user 'root'@'localhost' for table 't1'
+SELECT object_schema, object_name FROM performance_schema.objects_summary_global_by_type
+WHERE object_schema='test';
+object_schema	object_name
 drop table if exists test.ghost;
 create table test.ghost (a int, b int);
 alter table test.ghost add index index_a(a);

=== modified file 'mysql-test/suite/perfschema/r/temp_table_io.result'
--- a/mysql-test/suite/perfschema/r/temp_table_io.result	2011-08-11 03:11:58 +0000
+++ b/mysql-test/suite/perfschema/r/temp_table_io.result	2012-01-04 18:29:43 +0000
@@ -73,42 +73,15 @@ event_name	short_source	object_type	obje
 wait/io/table/sql/handler	handler.cc:	TABLE	test	marker	insert	NULL
 wait/io/table/sql/handler	handler.cc:	TABLE	test	marker	insert	NULL
 wait/io/table/sql/handler	handler.cc:	TABLE	test	marker	insert	NULL
-wait/io/table/sql/handler	handler.cc:	TEMPORARY TABLE	test	no_index_tab	insert	NULL
 wait/io/table/sql/handler	handler.cc:	TABLE	test	marker	insert	NULL
-wait/io/table/sql/handler	handler.cc:	TEMPORARY TABLE	test	no_index_tab	insert	NULL
 wait/io/table/sql/handler	handler.cc:	TABLE	test	marker	insert	NULL
-wait/io/table/sql/handler	handler.cc:	TEMPORARY TABLE	test	no_index_tab	insert	NULL
 wait/io/table/sql/handler	handler.cc:	TABLE	test	marker	insert	NULL
-wait/io/table/sql/handler	handler.cc:	TEMPORARY TABLE	test	no_index_tab	fetch	NULL
-wait/io/table/sql/handler	handler.cc:	TEMPORARY TABLE	test	no_index_tab	fetch	NULL
-wait/io/table/sql/handler	handler.cc:	TEMPORARY TABLE	test	no_index_tab	fetch	NULL
-wait/io/table/sql/handler	handler.cc:	TEMPORARY TABLE	test	no_index_tab	fetch	NULL
-wait/io/table/sql/handler	handler.cc:	TABLE	test	marker	insert	NULL
-wait/io/table/sql/handler	handler.cc:	TEMPORARY TABLE	test	no_index_tab	fetch	NULL
-wait/io/table/sql/handler	handler.cc:	TEMPORARY TABLE	test	no_index_tab	update	NULL
-wait/io/table/sql/handler	handler.cc:	TEMPORARY TABLE	test	no_index_tab	fetch	NULL
-wait/io/table/sql/handler	handler.cc:	TEMPORARY TABLE	test	no_index_tab	update	NULL
-wait/io/table/sql/handler	handler.cc:	TEMPORARY TABLE	test	no_index_tab	fetch	NULL
-wait/io/table/sql/handler	handler.cc:	TEMPORARY TABLE	test	no_index_tab	update	NULL
-wait/io/table/sql/handler	handler.cc:	TEMPORARY TABLE	test	no_index_tab	fetch	NULL
-wait/io/table/sql/handler	handler.cc:	TABLE	test	marker	insert	NULL
-wait/io/table/sql/handler	handler.cc:	TEMPORARY TABLE	test	no_index_tab	fetch	NULL
-wait/io/table/sql/handler	handler.cc:	TEMPORARY TABLE	test	no_index_tab	fetch	NULL
-wait/io/table/sql/handler	handler.cc:	TABLE	test	marker	insert	NULL
-wait/io/table/sql/handler	handler.cc:	TEMPORARY TABLE	test	no_index_tab	fetch	NULL
-wait/io/table/sql/handler	handler.cc:	TEMPORARY TABLE	test	no_index_tab	fetch	NULL
-wait/io/table/sql/handler	handler.cc:	TEMPORARY TABLE	test	no_index_tab	fetch	NULL
-wait/io/table/sql/handler	handler.cc:	TEMPORARY TABLE	test	no_index_tab	delete	NULL
-wait/io/table/sql/handler	handler.cc:	TEMPORARY TABLE	test	no_index_tab	fetch	NULL
-wait/io/table/sql/handler	handler.cc:	TABLE	test	marker	insert	NULL
-wait/io/table/sql/handler	handler.cc:	TEMPORARY TABLE	test	no_index_tab	fetch	NULL
-wait/io/table/sql/handler	handler.cc:	TEMPORARY TABLE	test	no_index_tab	fetch	NULL
-wait/io/table/sql/handler	handler.cc:	TEMPORARY TABLE	test	no_index_tab	fetch	NULL
-wait/io/table/sql/handler	handler.cc:	TABLE	test	marker	insert	NULL
-wait/io/table/sql/handler	handler.cc:	TABLE	test	marker	insert	NULL
-wait/io/table/sql/handler	handler.cc:	TEMPORARY TABLE	test	no_index_tab	fetch	NULL
-wait/io/table/sql/handler	handler.cc:	TEMPORARY TABLE	test	no_index_tab	fetch	NULL
-wait/io/table/sql/handler	handler.cc:	TEMPORARY TABLE	test	no_index_tab	fetch	NULL
+wait/io/table/sql/handler	handler.cc:	TABLE	test	marker	insert	NULL
+wait/io/table/sql/handler	handler.cc:	TABLE	test	marker	insert	NULL
+wait/io/table/sql/handler	handler.cc:	TABLE	test	marker	insert	NULL
+wait/io/table/sql/handler	handler.cc:	TABLE	test	marker	insert	NULL
+wait/io/table/sql/handler	handler.cc:	TABLE	test	marker	insert	NULL
+wait/io/table/sql/handler	handler.cc:	TABLE	test	marker	insert	NULL
 wait/io/table/sql/handler	handler.cc:	TABLE	test	marker	insert	NULL
 wait/io/table/sql/handler	handler.cc:	TABLE	test	marker	insert	NULL
 show status like 'performance_schema_%';

=== modified file 'mysql-test/suite/perfschema/t/dml_handler.test'
--- a/mysql-test/suite/perfschema/t/dml_handler.test	2011-10-19 21:49:22 +0000
+++ b/mysql-test/suite/perfschema/t/dml_handler.test	2012-01-04 18:29:43 +0000
@@ -15,7 +15,7 @@
 --echo
 --echo # Create a temporary table of performance schema table names
 --echo
-
+ 
 CREATE TEMPORARY TABLE table_list (id INT AUTO_INCREMENT, PRIMARY KEY (id)) AS
   SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
   WHERE TABLE_SCHEMA='performance_schema';
@@ -38,3 +38,5 @@ while ($count > 0)
    dec $count;
 }
 
+DROP TEMPORARY TABLE table_list;
+

=== modified file 'mysql-test/suite/perfschema/t/misc.test'
--- a/mysql-test/suite/perfschema/t/misc.test	2011-10-19 21:49:22 +0000
+++ b/mysql-test/suite/perfschema/t/misc.test	2012-01-06 15:54:45 +0000
@@ -5,6 +5,60 @@
 --source include/have_perfschema.inc
 
 #
+# Bug#12790483 OBJECTS_SUMMARY_GLOBAL_BY_TYPE AND RENAME TABLE
+#
+# Rename table leaves old tables names behind in
+# performance_schema.objects_summary_global_by_type
+#
+SELECT object_schema, object_name FROM performance_schema.objects_summary_global_by_type
+  WHERE object_schema='test';
+
+CREATE TABLE test.t_before(a INT);
+INSERT INTO test.t_before VALUES (1);
+
+# The new table should appear in OBJECTS_SUMMARY_GLOBAL_BY_TYPE.
+
+SELECT object_schema, object_name FROM performance_schema.objects_summary_global_by_type
+  WHERE object_schema='test';
+
+RENAME TABLE test.t_before TO test.t_after;
+
+# The renamed table should appear in OBJECTS_SUMMARY_GLOBAL_BY_TYPE, but only
+# after it is accessed.
+
+SELECT COUNT(*) FROM test.t_after;
+
+SELECT object_schema, object_name FROM performance_schema.objects_summary_global_by_type
+  WHERE object_schema='test';
+
+DROP TABLE test.t_after;
+
+# The renamed table should not appear in OBJECTS_SUMMARY_GLOBAL_BY_TYPE.
+
+SELECT object_schema, object_name FROM performance_schema.objects_summary_global_by_type
+  WHERE object_schema='test';
+
+#
+# Verify table views are ignored by the table io instrumentation.
+#
+
+CREATE TABLE test.t1(a INT);
+INSERT INTO test.t1 VALUES (1);
+CREATE VIEW test.v1 AS SELECT * FROM test.t1;
+SELECT COUNT(*) FROM test.v1;
+
+# Verify that a PFS table share was not created for the view.
+SELECT object_schema, object_name FROM performance_schema.objects_summary_global_by_type
+  WHERE object_schema='test';
+
+DROP VIEW test.v1;
+DROP TABLE test.t1;
+
+SELECT object_schema, object_name FROM performance_schema.objects_summary_global_by_type
+  WHERE object_schema='test';
+
+
+#
 # Bug#45496 Performance schema: assertion fails in
 # ha_perfschema::rnd_init:223
 #
@@ -26,6 +80,11 @@ LIMIT 1;
 --error ER_CANT_CREATE_TABLE
 create table test.t1(a int) engine=performance_schema;
 
+# The table should not appear in OBJECTS_SUMMARY_GLOBAL_BY_TYPE
+
+SELECT object_schema, object_name FROM performance_schema.objects_summary_global_by_type
+  WHERE object_schema='test';
+
 #
 # Bug#44897 Performance Schema: can create a ghost table in another database
 #
@@ -33,6 +92,11 @@ create table test.t1(a int) engine=perfo
 --error ER_CANT_CREATE_TABLE
 create table test.t1 like performance_schema.events_waits_current;
 
+# The table should not appear in OBJECTS_SUMMARY_GLOBAL_BY_TYPE
+
+SELECT object_schema, object_name FROM performance_schema.objects_summary_global_by_type
+  WHERE object_schema='test';
+
 #
 # Bug#44898 PerformanceSchema: can create a table in db performance_schema, cannot insert
 #
@@ -40,6 +104,11 @@ create table test.t1 like performance_sc
 --error ER_TABLEACCESS_DENIED_ERROR
 create table performance_schema.t1(a int);
 
+# The table should not appear in OBJECTS_SUMMARY_GLOBAL_BY_TYPE
+
+SELECT object_schema, object_name FROM performance_schema.objects_summary_global_by_type
+  WHERE object_schema='test';
+
 #
 # Bug#51447 performance schema evil twin files
 #

=== modified file 'mysql-test/suite/rpl/r/rpl_log_pos.result'
--- a/mysql-test/suite/rpl/r/rpl_log_pos.result	2011-11-19 08:08:03 +0000
+++ b/mysql-test/suite/rpl/r/rpl_log_pos.result	2012-01-04 15:48:00 +0000
@@ -12,6 +12,7 @@ change master to master_log_pos=MASTER_L
 Read_Master_Log_Pos = '75'
 start slave;
 include/wait_for_slave_io_error.inc [errno=1236]
+Last_IO_Error = 'Got fatal error 1236 from master when reading data from binary log: 'log event entry exceeded max_allowed_packet; Increase max_allowed_packet on master; the last event was read from 'master-bin.000001' at XXX, the last byte read was read from 'master-bin.000001' at XXX.''
 include/stop_slave_sql.inc
 show master status;
 File	Position	Binlog_Do_DB	Binlog_Ignore_DB

=== modified file 'mysql-test/suite/rpl/r/rpl_manual_change_index_file.result'
--- a/mysql-test/suite/rpl/r/rpl_manual_change_index_file.result	2011-11-19 08:08:03 +0000
+++ b/mysql-test/suite/rpl/r/rpl_manual_change_index_file.result	2012-01-04 15:48:00 +0000
@@ -8,6 +8,7 @@ CREATE TABLE t1(c1 INT);
 FLUSH LOGS;
 call mtr.add_suppression('Got fatal error 1236 from master when reading data from binary log: .*could not find next log');
 include/wait_for_slave_io_error.inc [errno=1236]
+Last_IO_Error = 'Got fatal error 1236 from master when reading data from binary log: 'could not find next log; the last event was read from 'master-bin.000002' at XXX, the last byte read was read from 'master-bin.000002' at XXX.''
 CREATE TABLE t2(c1 INT);
 FLUSH LOGS;
 CREATE TABLE t3(c1 INT);

=== modified file 'mysql-test/suite/rpl/t/rpl_log_pos.test'
--- a/mysql-test/suite/rpl/t/rpl_log_pos.test	2011-10-28 21:22:19 +0000
+++ b/mysql-test/suite/rpl/t/rpl_log_pos.test	2012-01-04 15:48:00 +0000
@@ -22,12 +22,9 @@ let $status_items= Read_Master_Log_Pos;
 source include/show_slave_status.inc;
 start slave;
 let $slave_io_errno= 1236;
-#
-# Win and Unix path is printed differently: BUG#13055685. So
-# show_slave_io_error is made 0 until the bug fixes provide necessary
-# facilities
-#
-let $show_slave_io_error= 0;
+--let $show_slave_io_error= 1
+# Mask line numbers, and whether master-bin is preceded by "./" or "."
+--let $slave_io_error_replace= / at [0-9]*/ at XXX/ /\.\/*master-bin/master-bin/
 source include/wait_for_slave_io_error.inc;
 source include/stop_slave_sql.inc;
 

=== modified file 'mysql-test/suite/rpl/t/rpl_manual_change_index_file.test'
--- a/mysql-test/suite/rpl/t/rpl_manual_change_index_file.test	2011-10-28 21:22:19 +0000
+++ b/mysql-test/suite/rpl/t/rpl_manual_change_index_file.test	2012-01-04 15:48:00 +0000
@@ -61,12 +61,9 @@ call mtr.add_suppression('Got fatal erro
 connection slave;
 # 1236 = ER_MASTER_FATAL_ERROR_READING_BINLOG
 --let $slave_io_errno= 1236
-#
-# Win and Unix path is printed differently: BUG#13055685. So
-# show_slave_io_error is made 0 until the bug fixes provide necessary
-# facilities
-#
---let $show_slave_io_error= 0
+--let $show_slave_io_error= 1
+# Mask line numbers, and whether master-bin is preceded by "./" or "."
+--let $slave_io_error_replace= / at [0-9]*/ at XXX/ /\.\/*master-bin/master-bin/
 --source include/wait_for_slave_io_error.inc
 
 connection master;

=== modified file 'mysql-test/t/myisampack.test'
--- a/mysql-test/t/myisampack.test	2011-09-16 12:21:05 +0000
+++ b/mysql-test/t/myisampack.test	2012-01-09 07:26:17 +0000
@@ -265,3 +265,15 @@ FLUSH TABLE t1;
 --exec $MYISAMCHK -soq $MYSQLD_DATADIR/test/t1
 CHECK TABLE t1;
 DROP TABLE t1;
+
+--echo #
+--echo # BUG#11751736: DROP DATABASE STATEMENT SHOULD REMOVE .OLD SUFFIX FROM 
+--echo # DATABASE DIRECTORY 
+--echo #
+CREATE DATABASE db1;
+CREATE TABLE db1.t1(c1 INT) ENGINE=MyISAM;
+## Added -f to force pack db in any case regardless the size of database 
+## being packed
+let $MYSQLD_DATADIR = `SELECT @@datadir`;
+--exec $MYISAMPACK -b -f $MYSQLD_DATADIR/db1/t1
+DROP DATABASE db1;

=== modified file 'mysys/psi_noop.c'
--- a/mysys/psi_noop.c	2011-10-11 04:27:52 +0000
+++ b/mysys/psi_noop.c	2012-01-06 09:03:53 +0000
@@ -25,23 +25,6 @@
 #include "my_sys.h"
 #include "mysql/psi/psi.h"
 
-typedef struct PSI_cond PSI_cond;
-typedef struct PSI_cond_locker PSI_cond_locker;
-typedef struct PSI_file PSI_file;
-typedef struct PSI_file_locker PSI_file_locker;
-typedef struct PSI_idle_locker PSI_idle_locker;
-typedef struct PSI_mutex PSI_mutex;
-typedef struct PSI_mutex_locker PSI_mutex_locker;
-typedef struct PSI_rwlock PSI_rwlock;
-typedef struct PSI_rwlock_locker PSI_rwlock_locker;
-typedef struct PSI_socket PSI_socket;
-typedef struct PSI_socket_locker PSI_socket_locker;
-typedef struct PSI_statement_locker PSI_statement_locker;
-typedef struct PSI_table PSI_table;
-typedef struct PSI_table_locker PSI_table_locker;
-typedef struct PSI_table_share PSI_table_share;
-typedef struct PSI_thread PSI_thread;
-
 C_MODE_START
 
 #define NNN __attribute__((unused))
@@ -158,8 +141,9 @@ static void release_table_share_noop(PSI
 }
 
 static void
-drop_table_share_noop(const char *schema_name NNN, int schema_name_length NNN,
-                      const char *table_name NNN, int table_name_length NNN)
+drop_table_share_noop(my_bool temporary NNN, const char *schema_name NNN,
+                      int schema_name_length NNN, const char *table_name NNN,
+                      int table_name_length NNN)
 {
   return;
 }
@@ -175,9 +159,12 @@ static void unbind_table_noop(PSI_table
   return;
 }
 
-static void rebind_table_noop(PSI_table *table NNN)
+static PSI_table*
+rebind_table_noop(PSI_table_share *share NNN,
+                  const void *identity NNN,
+                  PSI_table *table NNN)
 {
-  return;
+  return NULL;
 }
 
 static void close_table_noop(PSI_table *table NNN)
@@ -268,48 +255,6 @@ static void delete_thread_noop(PSI_threa
   return;
 }
 
-static PSI_mutex_locker*
-get_thread_mutex_locker_noop(PSI_mutex_locker_state *state NNN,
-                             PSI_mutex *mutex NNN,
-                             enum PSI_mutex_operation op NNN)
-{
-  return NULL;
-}
-
-static PSI_rwlock_locker*
-get_thread_rwlock_locker_noop(PSI_rwlock_locker_state *state NNN,
-                              PSI_rwlock *rwlock NNN,
-                              enum PSI_rwlock_operation op NNN)
-{
-  return NULL;
-}
-
-static PSI_cond_locker*
-get_thread_cond_locker_noop(PSI_cond_locker_state *state NNN,
-                            PSI_cond *cond NNN, PSI_mutex *mutex NNN,
-                            enum PSI_cond_operation op NNN)
-{
-  return NULL;
-}
-
-static PSI_table_locker*
-get_thread_table_io_locker_noop(PSI_table_locker_state *state NNN,
-                                PSI_table *table NNN,
-                                enum PSI_table_io_operation op NNN,
-                                uint index NNN)
-{
-  return NULL;
-}
-
-static PSI_table_locker*
-get_thread_table_lock_locker_noop(PSI_table_locker_state *state NNN,
-                                  PSI_table *table NNN,
-                                  enum PSI_table_lock_operation op NNN,
-                                  ulong op_flags NNN)
-{
-  return NULL;
-}
-
 static PSI_file_locker*
 get_thread_file_name_locker_noop(PSI_file_locker_state *state NNN,
                                  PSI_file_key key NNN,
@@ -336,14 +281,6 @@ get_thread_file_descriptor_locker_noop(P
   return NULL;
 }
 
-static PSI_socket_locker*
-get_thread_socket_locker_noop(PSI_socket_locker_state *state NNN,
-                              PSI_socket *socket NNN,
-                              enum PSI_socket_operation op NNN)
-{
-  return NULL;
-}
-
 static void unlock_mutex_noop(PSI_mutex *mutex NNN)
 {
   return;
@@ -376,10 +313,13 @@ static void end_idle_wait_noop(PSI_idle_
   return;
 }
 
-static void start_mutex_wait_noop(PSI_mutex_locker* locker NNN,
-                                  const char *src_file NNN, uint src_line NNN)
+static PSI_mutex_locker*
+start_mutex_wait_noop(PSI_mutex_locker_state *state NNN,
+                      PSI_mutex *mutex NNN,
+                      PSI_mutex_operation op NNN,
+                      const char *src_file NNN, uint src_line NNN)
 {
-  return;
+  return NULL;
 }
 
 static void end_mutex_wait_noop(PSI_mutex_locker* locker NNN, int rc NNN)
@@ -388,11 +328,13 @@ static void end_mutex_wait_noop(PSI_mute
 }
 
 
-static void start_rwlock_rdwait_noop(PSI_rwlock_locker* locker NNN,
-                                     const char *src_file NNN,
-                                     uint src_line NNN)
+static PSI_rwlock_locker*
+start_rwlock_rdwait_noop(struct PSI_rwlock_locker_state_v1 *state NNN,
+                         struct PSI_rwlock *rwlock NNN,
+                         enum PSI_rwlock_operation op NNN,
+                         const char *src_file NNN, uint src_line NNN)
 {
-  return;
+  return NULL;
 }
 
 static void end_rwlock_rdwait_noop(PSI_rwlock_locker* locker NNN, int rc NNN)
@@ -400,11 +342,13 @@ static void end_rwlock_rdwait_noop(PSI_r
   return;
 }
 
-static void start_rwlock_wrwait_noop(PSI_rwlock_locker* locker NNN,
-                                     const char *src_file NNN,
-                                     uint src_line NNN)
+static struct PSI_rwlock_locker*
+start_rwlock_wrwait_noop(struct PSI_rwlock_locker_state_v1 *state NNN,
+                         struct PSI_rwlock *rwlock NNN,
+                         enum PSI_rwlock_operation op NNN,
+                         const char *src_file NNN, uint src_line NNN)
 {
-  return;
+  return NULL;
 }
 
 static void end_rwlock_wrwait_noop(PSI_rwlock_locker* locker NNN, int rc NNN)
@@ -412,10 +356,14 @@ static void end_rwlock_wrwait_noop(PSI_r
   return;
 }
 
-static void start_cond_wait_noop(PSI_cond_locker* locker NNN,
-                                 const char *src_file NNN, uint src_line NNN)
+static struct PSI_cond_locker*
+start_cond_wait_noop(struct PSI_cond_locker_state_v1 *state NNN,
+                     struct PSI_cond *cond NNN,
+                     struct PSI_mutex *mutex NNN,
+                     enum PSI_cond_operation op NNN,
+                     const char *src_file NNN, uint src_line NNN)
 {
-  return;
+  return NULL;
 }
 
 static void end_cond_wait_noop(PSI_cond_locker* locker NNN, int rc NNN)
@@ -423,11 +371,14 @@ static void end_cond_wait_noop(PSI_cond_
   return;
 }
 
-static void start_table_io_wait_noop(PSI_table_locker* locker NNN,
-                                     const char *src_file NNN,
-                                     uint src_line NNN)
+static struct PSI_table_locker*
+start_table_io_wait_noop(struct PSI_table_locker_state_v1 *state NNN,
+                         struct PSI_table *table NNN,
+                         enum PSI_table_io_operation op NNN,
+                         uint index NNN,
+                         const char *src_file NNN, uint src_line NNN)
 {
-  return;
+  return NULL;
 }
 
 static void end_table_io_wait_noop(PSI_table_locker* locker NNN)
@@ -435,11 +386,14 @@ static void end_table_io_wait_noop(PSI_t
   return;
 }
 
-static void start_table_lock_wait_noop(PSI_table_locker* locker NNN,
-                                       const char *src_file NNN,
-                                       uint src_line NNN)
+static struct PSI_table_locker*
+start_table_lock_wait_noop(struct PSI_table_locker_state_v1 *state NNN,
+                           struct PSI_table *table NNN,
+                           enum PSI_table_lock_operation op NNN,
+                           ulong flags NNN,
+                           const char *src_file NNN, uint src_line NNN)
 {
-  return;
+  return NULL;
 }
 
 static void end_table_lock_wait_noop(PSI_table_locker* locker NNN)
@@ -617,12 +571,15 @@ static void end_statement_noop(PSI_state
   return;
 }
 
-static void start_socket_wait_noop(PSI_socket_locker *locker NNN,
-                                   size_t count NNN,
-                                   const char *src_socket NNN,
-                                   uint src_line NNN)
+static PSI_socket_locker*
+start_socket_wait_noop(PSI_socket_locker_state *state NNN,
+                       PSI_socket *socket NNN,
+                       PSI_socket_operation op NNN,
+                       size_t count NNN,
+                       const char *src_file NNN,
+                       uint src_line NNN)
 {
-  return;
+  return NULL;
 }
 
 static void end_socket_wait_noop(PSI_socket_locker *locker NNN,
@@ -690,15 +647,9 @@ static PSI PSI_noop=
   set_thread_noop,
   delete_current_thread_noop,
   delete_thread_noop,
-  get_thread_mutex_locker_noop,
-  get_thread_rwlock_locker_noop,
-  get_thread_cond_locker_noop,
-  get_thread_table_io_locker_noop,
-  get_thread_table_lock_locker_noop,
   get_thread_file_name_locker_noop,
   get_thread_file_stream_locker_noop,
   get_thread_file_descriptor_locker_noop,
-  get_thread_socket_locker_noop,
   unlock_mutex_noop,
   unlock_rwlock_noop,
   signal_cond_noop,

=== modified file 'sql/handler.cc'
--- a/sql/handler.cc	2012-01-05 10:12:47 +0000
+++ b/sql/handler.cc	2012-01-06 09:03:53 +0000
@@ -2119,7 +2119,11 @@ int ha_delete_table(THD *thd, handlerton
 
 #ifdef HAVE_PSI_TABLE_INTERFACE
   if (likely(error == 0))
-    PSI_CALL(drop_table_share)(db, strlen(db), alias, strlen(alias));
+  {
+    my_bool temp_table= (my_bool)is_prefix(alias, tmp_file_prefix);
+    PSI_CALL(drop_table_share)(temp_table, db, strlen(db),
+                               alias, strlen(alias));
+  }
 #endif
 
   DBUG_RETURN(error);
@@ -2173,25 +2177,24 @@ THD *handler::ha_thd(void) const
 
 void handler::unbind_psi()
 {
-#ifdef HAVE_PSI_INTERFACE
+#ifdef HAVE_PSI_TABLE_INTERFACE
   /*
     Notify the instrumentation that this table is not owned
     by this thread any more.
   */
-  if (likely(PSI_server != NULL))
-    PSI_server->unbind_table(m_psi);
+  PSI_CALL(unbind_table)(m_psi);
 #endif
 }
 
 void handler::rebind_psi()
 {
-#ifdef HAVE_PSI_INTERFACE
+#ifdef HAVE_PSI_TABLE_INTERFACE
   /*
     Notify the instrumentation that this table is now owned
     by this thread.
   */
-  if (likely(PSI_server != NULL))
-    PSI_server->rebind_table(m_psi);
+  PSI_table_share *share_psi= ha_table_share_psi(table_share);
+  m_psi= PSI_CALL(rebind_table)(share_psi, this, m_psi);
 #endif
 }
 
@@ -2280,12 +2283,9 @@ int handler::ha_rnd_next(uchar *buf)
   int result;
   DBUG_ASSERT(table_share->tmp_table != NO_TMP_TABLE ||
               m_lock_type != F_UNLCK);
-  MYSQL_TABLE_WAIT_VARIABLES(locker, state) /* no ';' */
 
-  MYSQL_START_TABLE_IO_WAIT(locker, &state, m_psi,
-                            PSI_TABLE_FETCH_ROW, MAX_KEY, 0);
-  result= rnd_next(buf);
-  MYSQL_END_TABLE_IO_WAIT(locker);
+  MYSQL_TABLE_IO_WAIT(m_psi, PSI_TABLE_FETCH_ROW, MAX_KEY, 0,
+    { result= rnd_next(buf); })
   return result;
 }
 
@@ -2294,12 +2294,9 @@ int handler::ha_rnd_pos(uchar *buf, ucha
   int result;
   DBUG_ASSERT(table_share->tmp_table != NO_TMP_TABLE ||
               m_lock_type != F_UNLCK);
-  MYSQL_TABLE_WAIT_VARIABLES(locker, state) /* no ';' */
 
-  MYSQL_START_TABLE_IO_WAIT(locker, &state, m_psi,
-                            PSI_TABLE_FETCH_ROW, MAX_KEY, 0);
-  result= rnd_pos(buf, pos);
-  MYSQL_END_TABLE_IO_WAIT(locker);
+  MYSQL_TABLE_IO_WAIT(m_psi, PSI_TABLE_FETCH_ROW, MAX_KEY, 0,
+    { result= rnd_pos(buf, pos); })
   return result;
 }
 
@@ -2310,12 +2307,9 @@ int handler::ha_index_read_map(uchar *bu
   int result;
   DBUG_ASSERT(table_share->tmp_table != NO_TMP_TABLE ||
               m_lock_type != F_UNLCK);
-  MYSQL_TABLE_WAIT_VARIABLES(locker, state) /* no ';' */
 
-  MYSQL_START_TABLE_IO_WAIT(locker, &state, m_psi,
-                            PSI_TABLE_FETCH_ROW, active_index, 0);
-  result= index_read_map(buf, key, keypart_map, find_flag);
-  MYSQL_END_TABLE_IO_WAIT(locker);
+  MYSQL_TABLE_IO_WAIT(m_psi, PSI_TABLE_FETCH_ROW, active_index, 0,
+    { result= index_read_map(buf, key, keypart_map, find_flag); })
   return result;
 }
 
@@ -2327,12 +2321,9 @@ int handler::ha_index_read_idx_map(uchar
   DBUG_ASSERT(table_share->tmp_table != NO_TMP_TABLE ||
               m_lock_type != F_UNLCK);
   DBUG_ASSERT(end_range == NULL);
-  MYSQL_TABLE_WAIT_VARIABLES(locker, state) /* no ';' */
 
-  MYSQL_START_TABLE_IO_WAIT(locker, &state, m_psi,
-                            PSI_TABLE_FETCH_ROW, index, 0);
-  result= index_read_idx_map(buf, index, key, keypart_map, find_flag);
-  MYSQL_END_TABLE_IO_WAIT(locker);
+  MYSQL_TABLE_IO_WAIT(m_psi, PSI_TABLE_FETCH_ROW, index, 0,
+    { result= index_read_idx_map(buf, index, key, keypart_map, find_flag); })
   return result;
 }
 
@@ -2341,12 +2332,9 @@ int handler::ha_index_next(uchar * buf)
   int result;
   DBUG_ASSERT(table_share->tmp_table != NO_TMP_TABLE ||
               m_lock_type != F_UNLCK);
-  MYSQL_TABLE_WAIT_VARIABLES(locker, state) /* no ';' */
 
-  MYSQL_START_TABLE_IO_WAIT(locker, &state, m_psi,
-                            PSI_TABLE_FETCH_ROW, active_index, 0);
-  result= index_next(buf);
-  MYSQL_END_TABLE_IO_WAIT(locker);
+  MYSQL_TABLE_IO_WAIT(m_psi, PSI_TABLE_FETCH_ROW, active_index, 0,
+    { result= index_next(buf); })
   return result;
 }
 
@@ -2355,12 +2343,9 @@ int handler::ha_index_prev(uchar * buf)
   int result;
   DBUG_ASSERT(table_share->tmp_table != NO_TMP_TABLE ||
               m_lock_type != F_UNLCK);
-  MYSQL_TABLE_WAIT_VARIABLES(locker, state) /* no ';' */
 
-  MYSQL_START_TABLE_IO_WAIT(locker, &state, m_psi,
-                            PSI_TABLE_FETCH_ROW, active_index, 0);
-  result= index_prev(buf);
-  MYSQL_END_TABLE_IO_WAIT(locker);
+  MYSQL_TABLE_IO_WAIT(m_psi, PSI_TABLE_FETCH_ROW, active_index, 0,
+    { result= index_prev(buf); })
   return result;
 }
 
@@ -2369,12 +2354,9 @@ int handler::ha_index_first(uchar * buf)
   int result;
   DBUG_ASSERT(table_share->tmp_table != NO_TMP_TABLE ||
               m_lock_type != F_UNLCK);
-  MYSQL_TABLE_WAIT_VARIABLES(locker, state) /* no ';' */
 
-  MYSQL_START_TABLE_IO_WAIT(locker, &state, m_psi,
-                            PSI_TABLE_FETCH_ROW, active_index, 0);
-  result= index_first(buf);
-  MYSQL_END_TABLE_IO_WAIT(locker);
+  MYSQL_TABLE_IO_WAIT(m_psi, PSI_TABLE_FETCH_ROW, active_index, 0,
+    { result= index_first(buf); })
   return result;
 }
 
@@ -2383,12 +2365,9 @@ int handler::ha_index_last(uchar * buf)
   int result;
   DBUG_ASSERT(table_share->tmp_table != NO_TMP_TABLE ||
               m_lock_type != F_UNLCK);
-  MYSQL_TABLE_WAIT_VARIABLES(locker, state) /* no ';' */
 
-  MYSQL_START_TABLE_IO_WAIT(locker, &state, m_psi,
-                            PSI_TABLE_FETCH_ROW, active_index, 0);
-  result= index_last(buf);
-  MYSQL_END_TABLE_IO_WAIT(locker);
+  MYSQL_TABLE_IO_WAIT(m_psi, PSI_TABLE_FETCH_ROW, active_index, 0,
+    { result= index_last(buf); })
   return result;
 }
 
@@ -2397,12 +2376,9 @@ int handler::ha_index_next_same(uchar *b
   int result;
   DBUG_ASSERT(table_share->tmp_table != NO_TMP_TABLE ||
               m_lock_type != F_UNLCK);
-  MYSQL_TABLE_WAIT_VARIABLES(locker, state) /* no ';' */
 
-  MYSQL_START_TABLE_IO_WAIT(locker, &state, m_psi,
-                            PSI_TABLE_FETCH_ROW, active_index, 0);
-  result= index_next_same(buf, key, keylen);
-  MYSQL_END_TABLE_IO_WAIT(locker);
+  MYSQL_TABLE_IO_WAIT(m_psi, PSI_TABLE_FETCH_ROW, active_index, 0,
+    { result= index_next_same(buf, key, keylen); })
   return result;
 }
 
@@ -2412,12 +2388,9 @@ int handler::ha_index_read(uchar *buf, c
   int result;
   DBUG_ASSERT(table_share->tmp_table != NO_TMP_TABLE ||
               m_lock_type != F_UNLCK);
-  MYSQL_TABLE_WAIT_VARIABLES(locker, state) /* no ';' */
 
-  MYSQL_START_TABLE_IO_WAIT(locker, &state, m_psi,
-                            PSI_TABLE_FETCH_ROW, active_index, 0);
-  result= index_read(buf, key, key_len, find_flag);
-  MYSQL_END_TABLE_IO_WAIT(locker);
+  MYSQL_TABLE_IO_WAIT(m_psi, PSI_TABLE_FETCH_ROW, active_index, 0,
+    { result= index_read(buf, key, key_len, find_flag); })
   return result;
 }
 
@@ -2426,12 +2399,9 @@ int handler::ha_index_read_last(uchar *b
   int result;
   DBUG_ASSERT(table_share->tmp_table != NO_TMP_TABLE ||
               m_lock_type != F_UNLCK);
-  MYSQL_TABLE_WAIT_VARIABLES(locker, state) /* no ';' */
 
-  MYSQL_START_TABLE_IO_WAIT(locker, &state, m_psi,
-                            PSI_TABLE_FETCH_ROW, active_index, 0);
-  result= index_read_last(buf, key, key_len);
-  MYSQL_END_TABLE_IO_WAIT(locker);
+  MYSQL_TABLE_IO_WAIT(m_psi, PSI_TABLE_FETCH_ROW, active_index, 0,
+    { result= index_read_last(buf, key, key_len); })
   return result;
 }
 
@@ -3961,7 +3931,7 @@ void handler::get_dynamic_partition_info
 int ha_create_table(THD *thd, const char *path,
                     const char *db, const char *table_name,
                     HA_CREATE_INFO *create_info,
-		    bool update_create_info)
+                    bool update_create_info)
 {
   int error= 1;
   TABLE table;
@@ -3969,16 +3939,17 @@ int ha_create_table(THD *thd, const char
   const char *name;
   TABLE_SHARE share;
   DBUG_ENTER("ha_create_table");
+#ifdef HAVE_PSI_TABLE_INTERFACE
+  my_bool temp_table= (my_bool)is_prefix(table_name, tmp_file_prefix) ||
+               (create_info->options & HA_LEX_CREATE_TMP_TABLE ? TRUE : FALSE);
+#endif
   
   init_tmp_table_share(thd, &share, db, 0, table_name, path);
   if (open_table_def(thd, &share, 0))
     goto err;
 
 #ifdef HAVE_PSI_TABLE_INTERFACE
-  {
-    my_bool temp= (create_info->options & HA_LEX_CREATE_TMP_TABLE ? TRUE : FALSE);
-    share.m_psi= PSI_CALL(get_table_share)(temp, &share);
-  }
+  share.m_psi= PSI_CALL(get_table_share)(temp_table, &share);
 #endif
 
   if (open_table_from_share(thd, &share, "", 0, (uint) READ_ALL, 0, &table,
@@ -3996,6 +3967,10 @@ int ha_create_table(THD *thd, const char
   {
     strxmov(name_buff, db, ".", table_name, NullS);
     my_error(ER_CANT_CREATE_TABLE, MYF(ME_BELL+ME_WAITTANG), name_buff, error);
+#ifdef HAVE_PSI_TABLE_INTERFACE
+    PSI_CALL(drop_table_share)(temp_table, db, strlen(db), table_name,
+                               strlen(table_name));
+#endif
   }
 err:
   free_table_share(&share);
@@ -5943,8 +5918,7 @@ static int binlog_log_row(TABLE* table,
 
 int handler::ha_external_lock(THD *thd, int lock_type)
 {
-  MYSQL_TABLE_WAIT_VARIABLES(locker, state) /* no ';' */
-
+  int error;
   DBUG_ENTER("handler::ha_external_lock");
   /*
     Whether this is lock or unlock, this should be true, and is to verify that
@@ -5980,16 +5954,14 @@ int handler::ha_external_lock(THD *thd,
   }
 
   ha_statistic_increment(&SSV::ha_external_lock_count);
-  MYSQL_START_TABLE_LOCK_WAIT(locker, &state, m_psi,
-                              PSI_TABLE_EXTERNAL_LOCK, lock_type);
+
+  MYSQL_TABLE_LOCK_WAIT(m_psi, PSI_TABLE_EXTERNAL_LOCK, lock_type,
+    { error= external_lock(thd, lock_type); })
 
   /*
     We cache the table flags if the locking succeeded. Otherwise, we
     keep them as they were when they were fetched in ha_open().
   */
-  int error= external_lock(thd, lock_type);
-
-  MYSQL_END_TABLE_LOCK_WAIT(locker);
 
   if (error == 0)
   {
@@ -6059,18 +6031,15 @@ int handler::ha_write_row(uchar *buf)
   Log_func *log_func= Write_rows_log_event::binlog_row_logging_function;
   DBUG_ASSERT(table_share->tmp_table != NO_TMP_TABLE ||
               m_lock_type == F_WRLCK);
-  MYSQL_TABLE_WAIT_VARIABLES(locker, state) /* no ';' */
 
   DBUG_ENTER("handler::ha_write_row");
 
   MYSQL_INSERT_ROW_START(table_share->db.str, table_share->table_name.str);
   mark_trx_read_write();
-  MYSQL_START_TABLE_IO_WAIT(locker, &state, m_psi,
-                            PSI_TABLE_WRITE_ROW, MAX_KEY, 0);
 
-  error= write_row(buf);
+  MYSQL_TABLE_IO_WAIT(m_psi, PSI_TABLE_WRITE_ROW, MAX_KEY, 0,
+    { error= write_row(buf); })
 
-  MYSQL_END_TABLE_IO_WAIT(locker);
   MYSQL_INSERT_ROW_DONE(error);
   if (unlikely(error))
     DBUG_RETURN(error);
@@ -6087,7 +6056,6 @@ int handler::ha_update_row(const uchar *
   DBUG_ASSERT(table_share->tmp_table != NO_TMP_TABLE ||
               m_lock_type == F_WRLCK);
   Log_func *log_func= Update_rows_log_event::binlog_row_logging_function;
-  MYSQL_TABLE_WAIT_VARIABLES(locker, state) /* no ';' */
 
   /*
     Some storage engines require that the new record is in record[0]
@@ -6098,12 +6066,9 @@ int handler::ha_update_row(const uchar *
   MYSQL_UPDATE_ROW_START(table_share->db.str, table_share->table_name.str);
   mark_trx_read_write();
 
-  MYSQL_START_TABLE_IO_WAIT(locker, &state, m_psi,
-                            PSI_TABLE_UPDATE_ROW, active_index, 0);
+  MYSQL_TABLE_IO_WAIT(m_psi, PSI_TABLE_UPDATE_ROW, active_index, 0,
+    { error= update_row(old_data, new_data);})
 
-  error= update_row(old_data, new_data);
-
-  MYSQL_END_TABLE_IO_WAIT(locker);
   MYSQL_UPDATE_ROW_DONE(error);
   if (unlikely(error))
     return error;
@@ -6118,17 +6083,13 @@ int handler::ha_delete_row(const uchar *
   DBUG_ASSERT(table_share->tmp_table != NO_TMP_TABLE ||
               m_lock_type == F_WRLCK);
   Log_func *log_func= Delete_rows_log_event::binlog_row_logging_function;
-  MYSQL_TABLE_WAIT_VARIABLES(locker, state) /* no ';' */
 
   MYSQL_DELETE_ROW_START(table_share->db.str, table_share->table_name.str);
   mark_trx_read_write();
 
-  MYSQL_START_TABLE_IO_WAIT(locker, &state, m_psi,
-                            PSI_TABLE_DELETE_ROW, active_index, 0);
-
-  error= delete_row(buf);
+  MYSQL_TABLE_IO_WAIT(m_psi, PSI_TABLE_DELETE_ROW, active_index, 0,
+    { error= delete_row(buf);})
 
-  MYSQL_END_TABLE_IO_WAIT(locker);
   MYSQL_DELETE_ROW_DONE(error);
   if (unlikely(error))
     return error;

=== modified file 'sql/sql_db.cc'
--- a/sql/sql_db.cc	2011-11-28 07:13:03 +0000
+++ b/sql/sql_db.cc	2012-01-09 07:26:17 +0000
@@ -1,5 +1,5 @@
 /*
-   Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
+   Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
 
    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
@@ -45,7 +45,7 @@
 
 #define MAX_DROP_TABLE_Q_LEN      1024
 
-const char *del_exts[]= {".frm", ".BAK", ".TMD",".opt", NullS};
+const char *del_exts[]= {".frm", ".BAK", ".TMD", ".opt", ".OLD", NullS};
 static TYPELIB deletable_extentions=
 {array_elements(del_exts)-1,"del_exts", del_exts, NULL};
 

=== modified file 'sql/sql_table.cc'
--- a/sql/sql_table.cc	2012-01-05 12:12:18 +0000
+++ b/sql/sql_table.cc	2012-01-05 17:57:53 +0000
@@ -54,6 +54,7 @@
 #include "transaction.h"
 #include "datadict.h"  // dd_frm_type()
 #include "sql_resolver.h"              // setup_order, fix_inner_refs
+#include <mysql/psi/mysql_table.h>
 
 #ifdef __WIN__
 #include <io.h>
@@ -2395,9 +2396,9 @@ int mysql_rm_table_no_locks(THD *thd, TA
         tbl_name.append('.');
         tbl_name.append(String(table->table_name,system_charset_info));
 
-	push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE,
-			    ER_BAD_TABLE_ERROR, ER(ER_BAD_TABLE_ERROR),
-			    tbl_name.c_ptr());
+        push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE,
+                            ER_BAD_TABLE_ERROR, ER(ER_BAD_TABLE_ERROR),
+                            tbl_name.c_ptr());
       }
       else
       {
@@ -2423,21 +2424,21 @@ int mysql_rm_table_no_locks(THD *thd, TA
 
       /* No error if non existent table and 'IF EXIST' clause or view */
       if ((error == ENOENT || error == HA_ERR_NO_SUCH_TABLE) && 
-	  (if_exists || table_type == NULL))
+          (if_exists || table_type == NULL))
       {
-	error= 0;
+        error= 0;
         thd->clear_error();
       }
       if (error == HA_ERR_ROW_IS_REFERENCED)
       {
-	/* the table is referenced by a foreign key constraint */
-	foreign_key_error= 1;
+        /* the table is referenced by a foreign key constraint */
+        foreign_key_error= 1;
       }
       if (!error || error == ENOENT || error == HA_ERR_NO_SUCH_TABLE)
       {
         int new_error;
-	/* Delete the table definition file */
-	strmov(end,reg_ext);
+        /* Delete the table definition file */
+        strmov(end,reg_ext);
         if (!(new_error= mysql_file_delete(key_file_frm, path, MYF(MY_WME))))
         {
           non_tmp_table_deleted= TRUE;
@@ -2451,7 +2452,7 @@ int mysql_rm_table_no_locks(THD *thd, TA
     if (error)
     {
       if (wrong_tables.length())
-	wrong_tables.append(',');
+        wrong_tables.append(',');
 
       wrong_tables.append(String(db,system_charset_info));
       wrong_tables.append('.');
@@ -2464,6 +2465,11 @@ int mysql_rm_table_no_locks(THD *thd, TA
                     my_printf_error(ER_BAD_TABLE_ERROR,
                                     ER(ER_BAD_TABLE_ERROR), MYF(0),
                                     table->table_name););
+#ifdef HAVE_PSI_TABLE_INTERFACE
+    if (drop_temporary && likely(error == 0))
+      PSI_CALL(drop_table_share)(true, table->db, table->db_length,
+                                 table->table_name, table->table_name_length);
+#endif
   }
   DEBUG_SYNC(thd, "rm_table_no_locks_before_binlog");
   thd->thread_specific_used|= (trans_tmp_table_deleted ||
@@ -4725,6 +4731,21 @@ mysql_rename_table(handlerton *base, con
     my_error(ER_ERROR_ON_RENAME, MYF(0), from, to,
              error, my_strerror(errbuf, sizeof(errbuf), error));
   }
+
+#ifdef HAVE_PSI_TABLE_INTERFACE
+  /*
+    Remove the old table share from the pfs table share array. The new table
+    share will be created when the renamed table is first accessed.
+   */
+  if (likely(error == 0))
+  {
+    my_bool temp_table= (my_bool)is_prefix(old_name, tmp_file_prefix);
+    PSI_CALL(drop_table_share)(temp_table, old_db, strlen(old_db),
+                               old_name, strlen(old_name));
+  }
+#endif
+
+
   DBUG_RETURN(error != 0);
 }
 

=== modified file 'storage/innobase/include/os0sync.ic'
--- a/storage/innobase/include/os0sync.ic	2011-11-09 02:40:33 +0000
+++ b/storage/innobase/include/os0sync.ic	2012-01-06 09:03:53 +0000
@@ -85,7 +85,8 @@ pfs_os_fast_mutex_free(
 	os_fast_mutex_t*	fast_mutex)  /*!< in/out: mutex */
 {
 #ifdef HAVE_PSI_MUTEX_INTERFACE
-	PSI_CALL(destroy_mutex)(fast_mutex->pfs_psi);
+	if (fast_mutex->pfs_psi != NULL)
+		PSI_CALL(destroy_mutex)(fast_mutex->pfs_psi);
 #endif
 	fast_mutex->pfs_psi = NULL;
 
@@ -106,20 +107,26 @@ pfs_os_fast_mutex_lock(
 	ulint			line)		/*!< in: line where locked */
 {
 #ifdef HAVE_PSI_MUTEX_INTERFACE
-	struct PSI_mutex_locker*        locker;
-	PSI_mutex_locker_state          state;
+	if (fast_mutex->pfs_psi != NULL)
+	{
+		PSI_mutex_locker* 	locker;
+		PSI_mutex_locker_state	state;
+
+		locker = PSI_CALL(start_mutex_wait)(&state, fast_mutex->pfs_psi,
+			PSI_MUTEX_LOCK, file_name, line);
 
-	locker = PSI_CALL(get_thread_mutex_locker)(
-		&state, fast_mutex->pfs_psi, PSI_MUTEX_LOCK);
-	if (locker != NULL) {
-		PSI_CALL(start_mutex_wait)(locker, file_name, line);
 		os_fast_mutex_lock_func(&fast_mutex->mutex);
-		PSI_CALL(end_mutex_wait)(locker, 0);
-		return;
+
+		if (locker != NULL)
+			PSI_CALL(end_mutex_wait)(locker, 0);
 	}
+	else
 #endif
+	{
+		os_fast_mutex_lock_func(&fast_mutex->mutex);
+	}
 
-	os_fast_mutex_lock_func(&fast_mutex->mutex);
+	return;
 }
 /**********************************************************//**
 NOTE! Please use the corresponding macro os_fast_mutex_unlock, not directly
@@ -133,7 +140,8 @@ pfs_os_fast_mutex_unlock(
 	os_fast_mutex_t*	fast_mutex)	/*!< in/out: mutex to release */
 {
 #ifdef HAVE_PSI_MUTEX_INTERFACE
-	PSI_CALL(unlock_mutex)(fast_mutex->pfs_psi);
+	if (fast_mutex->pfs_psi != NULL)
+		PSI_CALL(unlock_mutex)(fast_mutex->pfs_psi);
 #endif
 
 	os_fast_mutex_unlock_func(&fast_mutex->mutex);

=== modified file 'storage/innobase/include/sync0rw.ic'
--- a/storage/innobase/include/sync0rw.ic	2011-12-27 12:20:05 +0000
+++ b/storage/innobase/include/sync0rw.ic	2012-01-06 09:03:53 +0000
@@ -617,21 +617,24 @@ pfs_rw_lock_x_lock_func(
 	const char*	file_name,/*!< in: file name where lock requested */
 	ulint		line)	/*!< in: line where requested */
 {
-	struct PSI_rwlock_locker*	locker;
-	PSI_rwlock_locker_state		state;
+	if (lock->pfs_psi != NULL)
+	{
+		PSI_rwlock_locker*	locker;
+		PSI_rwlock_locker_state	state;
+
+		/* Record the entry of rw x lock request in performance schema */
+		locker = PSI_CALL(start_rwlock_wrwait)(
+			&state, lock->pfs_psi, PSI_RWLOCK_WRITELOCK, file_name, line);
 
-	/* Record the entry of rw x lock request in performance schema */
-	locker = PSI_CALL(get_thread_rwlock_locker)(
-		&state, lock->pfs_psi, PSI_RWLOCK_WRITELOCK);
+		rw_lock_x_lock_func(lock, pass, file_name, line);
 
-	if (locker != NULL) {
-		PSI_CALL(start_rwlock_wrwait)(locker, file_name, line);
+		if (locker != NULL)
+			PSI_CALL(end_rwlock_wrwait)(locker, 0);
+	}
+	else
+	{
 		rw_lock_x_lock_func(lock, pass, file_name, line);
-		PSI_CALL(end_rwlock_wrwait)(locker, 0);
-		return;
 	}
-
-	rw_lock_x_lock_func(lock, pass, file_name, line);
 }
 /******************************************************************//**
 Performance schema instrumented wrap function for
@@ -648,22 +651,27 @@ pfs_rw_lock_x_lock_func_nowait(
 				requested */
 	ulint		line)	/*!< in: line where requested */
 {
-	struct PSI_rwlock_locker*	locker;
-	PSI_rwlock_locker_state		state;
 	ibool	ret;
 
-	/* Record the entry of rw x lock request in performance schema */
-	locker = PSI_CALL(get_thread_rwlock_locker)(
-		&state, lock->pfs_psi, PSI_RWLOCK_WRITELOCK);
+	if (lock->pfs_psi != NULL)
+	{
+		PSI_rwlock_locker*	locker;
+		PSI_rwlock_locker_state		state;
+
+		/* Record the entry of rw x lock request in performance schema */
+		locker = PSI_CALL(start_rwlock_wrwait)(
+			&state, lock->pfs_psi, PSI_RWLOCK_WRITELOCK, file_name, line);
 
-	if (locker != NULL) {
-		PSI_CALL(start_rwlock_wrwait)(locker, file_name, line);
 		ret = rw_lock_x_lock_func_nowait(lock, file_name, line);
-		PSI_CALL(end_rwlock_wrwait)(locker, 0);
-		return(ret);
+
+		if (locker != NULL)
+			PSI_CALL(end_rwlock_wrwait)(locker, ret);
+	}
+	else
+	{
+		ret = rw_lock_x_lock_func_nowait(lock, file_name, line);
 	}
 
-	ret = rw_lock_x_lock_func_nowait(lock, file_name, line);
 	return(ret);
 }
 /******************************************************************//**
@@ -676,8 +684,11 @@ pfs_rw_lock_free_func(
 /*==================*/
 	rw_lock_t*	lock)	/*!< in: pointer to rw-lock */
 {
-	PSI_CALL(destroy_rwlock)(lock->pfs_psi);
-	lock->pfs_psi = NULL;
+	if (lock->pfs_psi != NULL)
+	{
+		PSI_CALL(destroy_rwlock)(lock->pfs_psi);
+		lock->pfs_psi = NULL;
+	}
 
 	rw_lock_free_func(lock);
 }
@@ -697,20 +708,26 @@ pfs_rw_lock_s_lock_func(
 				requested */
 	ulint		line)	/*!< in: line where requested */
 {
-	struct PSI_rwlock_locker*	locker;
-	PSI_rwlock_locker_state		state;
+	if (lock->pfs_psi != NULL)
+	{
+		PSI_rwlock_locker*	locker;
+		PSI_rwlock_locker_state	state;
+
+		/* Instrumented to inform we are aquiring a shared rwlock */
+		locker = PSI_CALL(start_rwlock_rdwait)(
+			&state, lock->pfs_psi, PSI_RWLOCK_READLOCK, file_name, line);
 
-	/* Instrumented to inform we are aquiring a shared rwlock */
-	locker = PSI_CALL(get_thread_rwlock_locker)(
-		&state, lock->pfs_psi, PSI_RWLOCK_READLOCK);
-	if (locker != NULL) {
-		PSI_CALL(start_rwlock_rdwait)(locker, file_name, line);
 		rw_lock_s_lock_func(lock, pass, file_name, line);
-		PSI_CALL(end_rwlock_rdwait)(locker, 0);
-		return;
+
+		if (locker != NULL)
+			PSI_CALL(end_rwlock_rdwait)(locker, 0);
+	}
+	else
+	{
+		rw_lock_s_lock_func(lock, pass, file_name, line);
 	}
 
-	rw_lock_s_lock_func(lock, pass, file_name, line);
+	return;
 }
 /******************************************************************//**
 Performance schema instrumented wrap function for rw_lock_s_lock_func()
@@ -728,21 +745,27 @@ pfs_rw_lock_s_lock_low(
 	const char*	file_name, /*!< in: file name where lock requested */
 	ulint		line)	/*!< in: line where requested */
 {
-	struct PSI_rwlock_locker*	locker;
-	PSI_rwlock_locker_state		state;
 	ibool	ret;
 
-	/* Instrumented to inform we are aquiring a shared rwlock */
-	locker = PSI_CALL(get_thread_rwlock_locker)(
-		&state, lock->pfs_psi, PSI_RWLOCK_READLOCK);
-	if (locker != NULL) {
-		PSI_CALL(start_rwlock_rdwait)(locker, file_name, line);
+	if (lock->pfs_psi != NULL)
+	{
+		PSI_rwlock_locker*	locker;
+		PSI_rwlock_locker_state	state;
+
+		/* Instrumented to inform we are aquiring a shared rwlock */
+		locker = PSI_CALL(start_rwlock_rdwait)(
+			&state, lock->pfs_psi, PSI_RWLOCK_READLOCK, file_name, line);
+
+		ret = rw_lock_s_lock_low(lock, pass, file_name, line);
+
+		if (locker != NULL)
+			PSI_CALL(end_rwlock_rdwait)(locker, ret);
+	}
+	else
+	{
 		ret = rw_lock_s_lock_low(lock, pass, file_name, line);
-		PSI_CALL(end_rwlock_rdwait)(locker, 0);
-		return(ret);
 	}
 
-	ret = rw_lock_s_lock_low(lock, pass, file_name, line);
 	return(ret);
 }
 
@@ -762,7 +785,8 @@ pfs_rw_lock_x_unlock_func(
 	rw_lock_t*	lock)	/*!< in/out: rw-lock */
 {
 	/* Inform performance schema we are unlocking the lock */
-	PSI_CALL(unlock_rwlock)(lock->pfs_psi);
+	if (lock->pfs_psi != NULL)
+		PSI_CALL(unlock_rwlock)(lock->pfs_psi);
 
 	rw_lock_x_unlock_func(
 #ifdef UNIV_SYNC_DEBUG
@@ -787,7 +811,8 @@ pfs_rw_lock_s_unlock_func(
 	rw_lock_t*	lock)	/*!< in/out: rw-lock */
 {
 	/* Inform performance schema we are unlocking the lock */
-	PSI_CALL(unlock_rwlock)(lock->pfs_psi);
+	if (lock->pfs_psi != NULL)
+		PSI_CALL(unlock_rwlock)(lock->pfs_psi);
 
 	rw_lock_s_unlock_func(
 #ifdef UNIV_SYNC_DEBUG

=== modified file 'storage/innobase/include/sync0sync.ic'
--- a/storage/innobase/include/sync0sync.ic	2011-11-30 10:27:10 +0000
+++ b/storage/innobase/include/sync0sync.ic	2012-01-06 09:03:53 +0000
@@ -236,19 +236,23 @@ pfs_mutex_enter_func(
 	const char*	file_name,	/*!< in: file name where locked */
 	ulint		line)		/*!< in: line where locked */
 {
-	struct PSI_mutex_locker*	locker;
-	PSI_mutex_locker_state		state;
+	if (mutex->pfs_psi != NULL)
+	{
+		PSI_mutex_locker*	locker;
+		PSI_mutex_locker_state	state;
+
+		locker = PSI_CALL(start_mutex_wait)(&state, mutex->pfs_psi,
+			PSI_MUTEX_LOCK, file_name, line);
 
-	locker = PSI_CALL(get_thread_mutex_locker)(
-		&state, mutex->pfs_psi, PSI_MUTEX_LOCK);
-	if (locker != NULL) {
-		PSI_CALL(start_mutex_wait)(locker, file_name, line);
 		mutex_enter_func(mutex, file_name, line);
-		PSI_CALL(end_mutex_wait)(locker, 0);
-		return;
-	}
 
-	mutex_enter_func(mutex, file_name, line);
+		if (locker != NULL)
+			PSI_CALL(end_mutex_wait)(locker, 0);
+	}
+	else
+	{
+		mutex_enter_func(mutex, file_name, line);
+	}
 }
 /********************************************************************//**
 NOTE! Please use the corresponding macro mutex_enter_nowait(), not directly
@@ -266,19 +270,24 @@ pfs_mutex_enter_nowait_func(
 	ulint		line)		/*!< in: line where requested */
 {
 	ulint	ret;
-	struct PSI_mutex_locker*	locker;
-	PSI_mutex_locker_state		state;
 
-	locker = PSI_CALL(get_thread_mutex_locker)(
-			&state, mutex->pfs_psi, PSI_MUTEX_TRYLOCK);
-	if (locker != NULL) {
-		PSI_CALL(start_mutex_wait)(locker, file_name, line);
+	if (mutex->pfs_psi != NULL)
+	{
+		PSI_mutex_locker*	locker;
+		PSI_mutex_locker_state		state;
+
+		locker = PSI_CALL(start_mutex_wait)(&state, mutex->pfs_psi,
+			PSI_MUTEX_TRYLOCK, file_name, line);
+
 		ret = mutex_enter_nowait_func(mutex, file_name, line);
-		PSI_CALL(end_mutex_wait)(locker, (int) ret);
-		return(ret);
-	}
 
-	ret = mutex_enter_nowait_func(mutex, file_name, line);
+		if (locker != NULL)
+			PSI_CALL(end_mutex_wait)(locker, (int) ret);
+	}
+	else
+	{
+		ret = mutex_enter_nowait_func(mutex, file_name, line);
+	}
 
 	return(ret);
 }
@@ -293,7 +302,8 @@ pfs_mutex_exit_func(
 /*================*/
 	mutex_t*	mutex)	/*!< in: pointer to mutex */
 {
-	PSI_CALL(unlock_mutex)(mutex->pfs_psi);
+	if (mutex->pfs_psi != NULL)
+		PSI_CALL(unlock_mutex)(mutex->pfs_psi);
 
 	mutex_exit_func(mutex);
 }
@@ -342,8 +352,11 @@ pfs_mutex_free_func(
 /*================*/
 	mutex_t*	mutex)	/*!< in: mutex */
 {
-	PSI_CALL(destroy_mutex)(mutex->pfs_psi);
-	mutex->pfs_psi = NULL;
+	if (mutex->pfs_psi != NULL)
+	{
+		PSI_CALL(destroy_mutex)(mutex->pfs_psi);
+		mutex->pfs_psi = NULL;
+	}
 
 	mutex_free_func(mutex);
 }

=== modified file 'storage/perfschema/pfs.cc'
--- a/storage/perfschema/pfs.cc	2011-12-19 08:07:59 +0000
+++ b/storage/perfschema/pfs.cc	2012-01-09 08:27:58 +0000
@@ -364,26 +364,14 @@
 
   For a given instrumentation point in the API, the basic coding pattern
   used is:
-  - (a) If the performance schema is not initialized, do nothing
-  - (b) If the object acted upon is not instrumented, do nothing
-  - (c) otherwise, notify the performance schema of the operation
+  - (a) notify the performance schema of the operation
   about to be performed.
+  - (b) execute the instrumented code.
+  - (c) notify the performance schema that the operation
+  is completed.
 
-  The implementation of the instrumentation interface can:
-  - decide that it is not interested by the event, and return NULL.
-  In this context, 'interested' means whether the instrumentation for
-  this object + event is turned on in the performance schema configuration
-  (the SETUP_ tables).
-  - decide that this event is to be instrumented.
-  In this case, the instrumentation returns an opaque pointer,
-  that acts as a listener.
-
-  If a listener is returned, the instrumentation point then:
-  - (d) invokes the "start" event method
-  - (e) executes the instrumented code.
-  - (f) invokes the "end" event method.
-
-  If no listener is returned, only the instrumented code (e) is invoked.
+  An opaque "locker" pointer is returned by (a), that is given to (c).
+  This pointer helps the implementation to keep context, for performances.
 
   The following code fragment is annotated to show how in detail this pattern
   in implemented, when the instrumentation is compiled in:
@@ -393,25 +381,18 @@ static inline int mysql_mutex_lock(
   mysql_mutex_t *that, myf flags, const char *src_file, uint src_line)
 {
   int result;
+  struct PSI_mutex_locker_state state;
   struct PSI_mutex_locker *locker= NULL;
 
-  ...... (a) .......... (b)
-  if (PSI_server && that->m_psi)
-
-  .......................... (c)
-    if ((locker= PSI_server->get_thread_mutex_locker(that->m_psi,
-                                                     PSI_MUTEX_LOCK)))
-
-  ............... (d)
-      PSI_server->start_mutex_wait(locker, src_file, src_line);
+  ............... (a)
+  locker= PSI_server->start_mutex_wait(&state, that->p_psi,
+                                       PSI_MUTEX_LOCK, locker, src_file, src_line);
 
-  ........ (e)
+  ............... (b)
   result= pthread_mutex_lock(&that->m_mutex);
 
-  if (locker)
-
-  ............. (f)
-    PSI_server->end_mutex_wait(locker, result);
+  ............... (c)
+  PSI_server->end_mutex_wait(locker, result);
 
   return result;
 }
@@ -425,7 +406,7 @@ static inline int mysql_mutex_lock(...)
 {
   int result;
 
-  ........ (e)
+  ............... (b)
   result= pthread_mutex_lock(&that->m_mutex);
 
   return result;
@@ -754,7 +735,7 @@ static inline int mysql_mutex_lock(...)
   grand parents directly.
 
   Implemented as:
-  - [1] @c get_thread_mutex_locker_v1(), @c start_mutex_wait_v1(), @c end_mutex_wait_v1()
+  - [1] @c start_mutex_wait_v1(), @c end_mutex_wait_v1()
   - [2] @c destroy_mutex_v1()
   - [3] @c aggregate_thread_waits()
   - [4] @c PFS_account::aggregate_waits()
@@ -802,8 +783,7 @@ static inline int mysql_mutex_lock(...)
 @endverbatim
 
   Implemented as:
-  - [1] @c get_thread_rwlock_locker_v1(), @c start_rwlock_rdwait_v1(),
-        @c end_rwlock_rdwait_v1(), ...
+  - [1] @c start_rwlock_rdwait_v1(), @c end_rwlock_rdwait_v1(), ...
   - [2] @c destroy_rwlock_v1()
   - [A] EVENTS_WAITS_SUMMARY_BY_THREAD_BY_EVENT_NAME,
         @c table_ews_by_thread_by_event_name::make_row()
@@ -831,7 +811,7 @@ static inline int mysql_mutex_lock(...)
 @endverbatim
 
   Implemented as:
-  - [1] @c get_thread_cond_locker_v1(), @c start_cond_wait_v1(), @c end_cond_wait_v1()
+  - [1] @c start_cond_wait_v1(), @c end_cond_wait_v1()
   - [2] @c destroy_cond_v1()
   - [A] EVENTS_WAITS_SUMMARY_BY_THREAD_BY_EVENT_NAME,
         @c table_ews_by_thread_by_event_name::make_row()
@@ -892,8 +872,7 @@ static inline int mysql_mutex_lock(...)
 @endverbatim
 
   Implemented as:
-  - [1] @c get_thread_socket_name_locker_v1(), @c start_socket_wait_v1(),
-        @c end_socket_wait_v1(), ...
+  - [1] @c start_socket_wait_v1(), @c end_socket_wait_v1().
   - [2] @c close_socket_v1()
   - [A] EVENTS_WAITS_SUMMARY_BY_THREAD_BY_EVENT_NAME,
         @c table_ews_by_thread_by_event_name::make_row()
@@ -925,7 +904,7 @@ static inline int mysql_mutex_lock(...)
 @endverbatim
 
   Implemented as:
-  - [1] @c get_thread_table_io_locker_v1(), @c start_table_io_wait_v1(), @c end_table_io_wait_v1()
+  - [1] @c start_table_io_wait_v1(), @c end_table_io_wait_v1()
   - [2] @c close_table_v1()
   - [A] EVENTS_WAITS_SUMMARY_BY_THREAD_BY_EVENT_NAME,
         @c table_ews_by_thread_by_event_name::make_row()
@@ -1442,8 +1421,7 @@ static void destroy_mutex_v1(PSI_mutex*
 {
   PFS_mutex *pfs= reinterpret_cast<PFS_mutex*> (mutex);
 
-  if (unlikely(pfs == NULL))
-    return;
+  DBUG_ASSERT(pfs != NULL);
 
   destroy_mutex(pfs);
 }
@@ -1466,8 +1444,7 @@ static void destroy_rwlock_v1(PSI_rwlock
 {
   PFS_rwlock *pfs= reinterpret_cast<PFS_rwlock*> (rwlock);
 
-  if (unlikely(pfs == NULL))
-    return;
+  DBUG_ASSERT(pfs != NULL);
 
   destroy_rwlock(pfs);
 }
@@ -1490,8 +1467,7 @@ static void destroy_cond_v1(PSI_cond* co
 {
   PFS_cond *pfs= reinterpret_cast<PFS_cond*> (cond);
 
-  if (unlikely(pfs == NULL))
-    return;
+  DBUG_ASSERT(pfs != NULL);
 
   destroy_cond(pfs);
 }
@@ -1503,6 +1479,9 @@ static void destroy_cond_v1(PSI_cond* co
 static PSI_table_share*
 get_table_share_v1(my_bool temporary, TABLE_SHARE *share)
 {
+  /* Ignore temporary tables and views. */
+  if (temporary || share->is_view)
+    return NULL;
   /* An instrumented thread is required, for LF_PINS. */
   PFS_thread *pfs_thread= my_pthread_getspecific_ptr(PFS_thread*, THR_PFS);
   if (unlikely(pfs_thread == NULL))
@@ -1531,14 +1510,18 @@ static void release_table_share_v1(PSI_t
   @sa PSI_v1::drop_table_share.
 */
 static void
-drop_table_share_v1(const char *schema_name, int schema_name_length,
+drop_table_share_v1(my_bool temporary,
+                    const char *schema_name, int schema_name_length,
                     const char *table_name, int table_name_length)
 {
+  /* Ignore temporary tables. */
+  if (temporary)
+    return;
   PFS_thread *pfs_thread= my_pthread_getspecific_ptr(PFS_thread*, THR_PFS);
   if (unlikely(pfs_thread == NULL))
     return;
   /* TODO: temporary tables */
-  drop_table_share(pfs_thread, false, schema_name, schema_name_length,
+  drop_table_share(pfs_thread, temporary, schema_name, schema_name_length,
                    table_name, table_name_length);
 }
 
@@ -1554,6 +1537,22 @@ open_table_v1(PSI_table_share *share, co
   if (unlikely(pfs_table_share == NULL))
     return NULL;
 
+  /* This object is not to be instrumented. */
+  if (! pfs_table_share->m_enabled)
+    return NULL;
+
+  /* This object is instrumented, but all table instruments are disabled. */
+  if (! global_table_io_class.m_enabled && ! global_table_lock_class.m_enabled)
+    return NULL;
+
+  /*
+    When the performance schema is off, do not instrument anything.
+    Table handles have short life cycle, instrumentation will happen
+    again if needed during the next open().
+  */
+  if (! flag_global_instrumentation)
+    return NULL;
+
   PFS_thread *thread= my_pthread_getspecific_ptr(PFS_thread*, THR_PFS);
   if (unlikely(thread == NULL))
     return NULL;
@@ -1580,15 +1579,68 @@ static void unbind_table_v1(PSI_table *t
   Implementation of the table instrumentation interface.
   @sa PSI_v1::rebind_table.
 */
-static void rebind_table_v1(PSI_table *table)
+static PSI_table *
+rebind_table_v1(PSI_table_share *share, const void *identity, PSI_table *table)
 {
   PFS_table *pfs= reinterpret_cast<PFS_table*> (table);
   if (likely(pfs != NULL))
   {
+    PFS_thread *thread;
     DBUG_ASSERT(pfs->m_thread_owner == NULL);
 
-    pfs->m_thread_owner= my_pthread_getspecific_ptr(PFS_thread*, THR_PFS);
+    /* The table handle was already instrumented, reuse it for this thread. */
+    thread= my_pthread_getspecific_ptr(PFS_thread*, THR_PFS);
+
+    if (unlikely(thread == NULL))
+    {
+      destroy_table(pfs);
+      return NULL;
+    }
+
+    if (unlikely(! pfs->m_share->m_enabled))
+    {
+      destroy_table(pfs);
+      return NULL;
+    }
+
+    if (unlikely(! global_table_io_class.m_enabled && ! global_table_lock_class.m_enabled))
+    {
+      destroy_table(pfs);
+      return NULL;
+    }
+
+    if (unlikely(! flag_global_instrumentation))
+    {
+      destroy_table(pfs);
+      return NULL;
+    }
+
+    pfs->m_thread_owner= thread;
+    return table;
   }
+
+  /* See open_table_v1() */
+
+  PFS_table_share *pfs_table_share= reinterpret_cast<PFS_table_share*> (share);
+
+  if (unlikely(pfs_table_share == NULL))
+    return NULL;
+
+  if (! pfs_table_share->m_enabled)
+    return NULL;
+
+  if (! global_table_io_class.m_enabled && ! global_table_lock_class.m_enabled)
+    return NULL;
+
+  if (! flag_global_instrumentation)
+    return NULL;
+
+  PFS_thread *thread= my_pthread_getspecific_ptr(PFS_thread*, THR_PFS);
+  if (unlikely(thread == NULL))
+    return NULL;
+
+  PFS_table *pfs_table= create_table(pfs_table_share, thread, identity);
+  return reinterpret_cast<PSI_table *> (pfs_table);
 }
 
 /**
@@ -1614,8 +1666,7 @@ static void destroy_socket_v1(PSI_socket
 {
   PFS_socket *pfs= reinterpret_cast<PFS_socket*> (socket);
 
-  if (unlikely(pfs == NULL))
-    return;
+  DBUG_ASSERT(pfs != NULL);
 
   destroy_socket(pfs);
 }
@@ -2036,26 +2087,26 @@ static void delete_thread_v1(PSI_thread
 
 /**
   Implementation of the mutex instrumentation interface.
-  @sa PSI_v1::get_thread_mutex_locker.
+  @sa PSI_v1::start_mutex_wait.
 */
 static PSI_mutex_locker*
-get_thread_mutex_locker_v1(PSI_mutex_locker_state *state,
-                           PSI_mutex *mutex, PSI_mutex_operation op)
+start_mutex_wait_v1(PSI_mutex_locker_state *state,
+                    PSI_mutex *mutex, PSI_mutex_operation op,
+                    const char *src_file, uint src_line)
 {
   PFS_mutex *pfs_mutex= reinterpret_cast<PFS_mutex*> (mutex);
   DBUG_ASSERT((int) op >= 0);
   DBUG_ASSERT((uint) op < array_elements(mutex_operation_map));
   DBUG_ASSERT(state != NULL);
 
-  if (unlikely(pfs_mutex == NULL))
-    return NULL;
-
+  DBUG_ASSERT(pfs_mutex != NULL);
   DBUG_ASSERT(pfs_mutex->m_class != NULL);
 
   if (! pfs_mutex->m_enabled)
     return NULL;
 
   register uint flags;
+  ulonglong timer_start= 0;
 
   if (flag_thread_instrumentation)
   {
@@ -2068,16 +2119,21 @@ get_thread_mutex_locker_v1(PSI_mutex_loc
     flags= STATE_FLAG_THREAD;
 
     if (pfs_mutex->m_timed)
+    {
+      timer_start= get_timer_raw_value_and_function(wait_timer, & state->m_timer);
+      state->m_timer_start= timer_start;
       flags|= STATE_FLAG_TIMED;
+    }
 
     if (flag_events_waits_current)
     {
-      if (unlikely(pfs_thread->m_events_waits_count >= WAIT_STACK_SIZE))
+      if (unlikely(pfs_thread->m_events_waits_current >=
+                   & pfs_thread->m_events_waits_stack[WAIT_STACK_SIZE]))
       {
         locker_lost++;
         return NULL;
       }
-      PFS_events_waits *wait= &pfs_thread->m_events_waits_stack[pfs_thread->m_events_waits_count];
+      PFS_events_waits *wait= pfs_thread->m_events_waits_current;
       state->m_wait= wait;
       flags|= STATE_FLAG_EVENT;
 
@@ -2088,21 +2144,25 @@ get_thread_mutex_locker_v1(PSI_mutex_loc
 
       wait->m_thread= pfs_thread;
       wait->m_class= pfs_mutex->m_class;
-      wait->m_timer_start= 0;
+      wait->m_timer_start= timer_start;
       wait->m_timer_end= 0;
       wait->m_object_instance_addr= pfs_mutex->m_identity;
       wait->m_event_id= pfs_thread->m_event_id++;
       wait->m_end_event_id= 0;
       wait->m_operation= mutex_operation_map[(int) op];
+      wait->m_source_file= src_file;
+      wait->m_source_line= src_line;
       wait->m_wait_class= WAIT_CLASS_MUTEX;
 
-      pfs_thread->m_events_waits_count++;
+      pfs_thread->m_events_waits_current++;
     }
   }
   else
   {
     if (pfs_mutex->m_timed)
     {
+      timer_start= get_timer_raw_value_and_function(wait_timer, & state->m_timer);
+      state->m_timer_start= timer_start;
       flags= STATE_FLAG_TIMED;
       state->m_thread= NULL;
     }
@@ -2124,26 +2184,27 @@ get_thread_mutex_locker_v1(PSI_mutex_loc
 
 /**
   Implementation of the rwlock instrumentation interface.
-  @sa PSI_v1::get_thread_rwlock_locker.
+  @sa PSI_v1::start_rwlock_rdwait
+  @sa PSI_v1::start_rwlock_wrwait
 */
 static PSI_rwlock_locker*
-get_thread_rwlock_locker_v1(PSI_rwlock_locker_state *state,
-                            PSI_rwlock *rwlock, PSI_rwlock_operation op)
+start_rwlock_wait_v1(PSI_rwlock_locker_state *state,
+                     PSI_rwlock *rwlock,
+                     PSI_rwlock_operation op,
+                     const char *src_file, uint src_line)
 {
   PFS_rwlock *pfs_rwlock= reinterpret_cast<PFS_rwlock*> (rwlock);
   DBUG_ASSERT(static_cast<int> (op) >= 0);
   DBUG_ASSERT(static_cast<uint> (op) < array_elements(rwlock_operation_map));
   DBUG_ASSERT(state != NULL);
-
-  if (unlikely(pfs_rwlock == NULL))
-    return NULL;
-
+  DBUG_ASSERT(pfs_rwlock != NULL);
   DBUG_ASSERT(pfs_rwlock->m_class != NULL);
 
   if (! pfs_rwlock->m_enabled)
     return NULL;
 
   register uint flags;
+  ulonglong timer_start= 0;
 
   if (flag_thread_instrumentation)
   {
@@ -2156,16 +2217,21 @@ get_thread_rwlock_locker_v1(PSI_rwlock_l
     flags= STATE_FLAG_THREAD;
 
     if (pfs_rwlock->m_timed)
+    {
+      timer_start= get_timer_raw_value_and_function(wait_timer, & state->m_timer);
+      state->m_timer_start= timer_start;
       flags|= STATE_FLAG_TIMED;
+    }
 
     if (flag_events_waits_current)
     {
-      if (unlikely(pfs_thread->m_events_waits_count >= WAIT_STACK_SIZE))
+      if (unlikely(pfs_thread->m_events_waits_current >=
+                   & pfs_thread->m_events_waits_stack[WAIT_STACK_SIZE]))
       {
         locker_lost++;
         return NULL;
       }
-      PFS_events_waits *wait= &pfs_thread->m_events_waits_stack[pfs_thread->m_events_waits_count];
+      PFS_events_waits *wait= pfs_thread->m_events_waits_current;
       state->m_wait= wait;
       flags|= STATE_FLAG_EVENT;
 
@@ -2176,21 +2242,25 @@ get_thread_rwlock_locker_v1(PSI_rwlock_l
 
       wait->m_thread= pfs_thread;
       wait->m_class= pfs_rwlock->m_class;
-      wait->m_timer_start= 0;
+      wait->m_timer_start= timer_start;
       wait->m_timer_end= 0;
       wait->m_object_instance_addr= pfs_rwlock->m_identity;
       wait->m_event_id= pfs_thread->m_event_id++;
       wait->m_end_event_id= 0;
       wait->m_operation= rwlock_operation_map[static_cast<int> (op)];
+      wait->m_source_file= src_file;
+      wait->m_source_line= src_line;
       wait->m_wait_class= WAIT_CLASS_RWLOCK;
 
-      pfs_thread->m_events_waits_count++;
+      pfs_thread->m_events_waits_current++;
     }
   }
   else
   {
     if (pfs_rwlock->m_timed)
     {
+      timer_start= get_timer_raw_value_and_function(wait_timer, & state->m_timer);
+      state->m_timer_start= timer_start;
       flags= STATE_FLAG_TIMED;
       state->m_thread= NULL;
     }
@@ -2212,12 +2282,13 @@ get_thread_rwlock_locker_v1(PSI_rwlock_l
 
 /**
   Implementation of the cond instrumentation interface.
-  @sa PSI_v1::get_thread_cond_locker.
+  @sa PSI_v1::start_cond_wait.
 */
 static PSI_cond_locker*
-get_thread_cond_locker_v1(PSI_cond_locker_state *state,
-                          PSI_cond *cond, PSI_mutex *mutex,
-                          PSI_cond_operation op)
+start_cond_wait_v1(PSI_cond_locker_state *state,
+                   PSI_cond *cond, PSI_mutex *mutex,
+                   PSI_cond_operation op,
+                   const char *src_file, uint src_line)
 {
   /*
     Note about the unused PSI_mutex *mutex parameter:
@@ -2234,21 +2305,14 @@ get_thread_cond_locker_v1(PSI_cond_locke
   DBUG_ASSERT(static_cast<int> (op) >= 0);
   DBUG_ASSERT(static_cast<uint> (op) < array_elements(cond_operation_map));
   DBUG_ASSERT(state != NULL);
-
-  if (unlikely(pfs_cond == NULL))
-    return NULL;
-
+  DBUG_ASSERT(pfs_cond != NULL);
   DBUG_ASSERT(pfs_cond->m_class != NULL);
 
   if (! pfs_cond->m_enabled)
     return NULL;
 
   register uint flags;
-
-  if (pfs_cond->m_timed)
-    state->m_flags= STATE_FLAG_TIMED;
-  else
-    state->m_flags= 0;
+  ulonglong timer_start= 0;
 
   if (flag_thread_instrumentation)
   {
@@ -2261,16 +2325,21 @@ get_thread_cond_locker_v1(PSI_cond_locke
     flags= STATE_FLAG_THREAD;
 
     if (pfs_cond->m_timed)
+    {
+      timer_start= get_timer_raw_value_and_function(wait_timer, & state->m_timer);
+      state->m_timer_start= timer_start;
       flags|= STATE_FLAG_TIMED;
+    }
 
     if (flag_events_waits_current)
     {
-      if (unlikely(pfs_thread->m_events_waits_count >= WAIT_STACK_SIZE))
+      if (unlikely(pfs_thread->m_events_waits_current >=
+                   & pfs_thread->m_events_waits_stack[WAIT_STACK_SIZE]))
       {
         locker_lost++;
         return NULL;
       }
-      PFS_events_waits *wait= &pfs_thread->m_events_waits_stack[pfs_thread->m_events_waits_count];
+      PFS_events_waits *wait= pfs_thread->m_events_waits_current;
       state->m_wait= wait;
       flags|= STATE_FLAG_EVENT;
 
@@ -2281,21 +2350,27 @@ get_thread_cond_locker_v1(PSI_cond_locke
 
       wait->m_thread= pfs_thread;
       wait->m_class= pfs_cond->m_class;
-      wait->m_timer_start= 0;
+      wait->m_timer_start= timer_start;
       wait->m_timer_end= 0;
       wait->m_object_instance_addr= pfs_cond->m_identity;
       wait->m_event_id= pfs_thread->m_event_id++;
       wait->m_end_event_id= 0;
       wait->m_operation= cond_operation_map[static_cast<int> (op)];
+      wait->m_source_file= src_file;
+      wait->m_source_line= src_line;
       wait->m_wait_class= WAIT_CLASS_COND;
 
-      pfs_thread->m_events_waits_count++;
+      pfs_thread->m_events_waits_current++;
     }
   }
   else
   {
     if (pfs_cond->m_timed)
+    {
+      timer_start= get_timer_raw_value_and_function(wait_timer, & state->m_timer);
+      state->m_timer_start= timer_start;
       flags= STATE_FLAG_TIMED;
+    }
     else
     {
       /*
@@ -2359,20 +2434,20 @@ static inline PFS_TL_LOCK_TYPE external_
 
 /**
   Implementation of the table instrumentation interface.
-  @sa PSI_v1::get_thread_table_io_locker.
+  @sa PSI_v1::start_table_io_wait_v1
 */
 static PSI_table_locker*
-get_thread_table_io_locker_v1(PSI_table_locker_state *state,
-                              PSI_table *table, PSI_table_io_operation op, uint index)
+start_table_io_wait_v1(PSI_table_locker_state *state,
+                       PSI_table *table,
+                       PSI_table_io_operation op,
+                       uint index,
+                       const char *src_file, uint src_line)
 {
   DBUG_ASSERT(static_cast<int> (op) >= 0);
   DBUG_ASSERT(static_cast<uint> (op) < array_elements(table_io_operation_map));
   DBUG_ASSERT(state != NULL);
   PFS_table *pfs_table= reinterpret_cast<PFS_table*> (table);
-
-  if (unlikely(pfs_table == NULL))
-    return NULL;
-
+  DBUG_ASSERT(pfs_table != NULL);
   DBUG_ASSERT(pfs_table->m_share != NULL);
 
   if (! pfs_table->m_io_enabled)
@@ -2386,6 +2461,7 @@ get_thread_table_io_locker_v1(PSI_table_
               my_pthread_getspecific_ptr(PFS_thread*, THR_PFS));
 
   register uint flags;
+  ulonglong timer_start= 0;
 
   if (flag_thread_instrumentation)
   {
@@ -2395,16 +2471,21 @@ get_thread_table_io_locker_v1(PSI_table_
     flags= STATE_FLAG_THREAD;
 
     if (pfs_table->m_io_timed)
+    {
+      timer_start= get_timer_raw_value_and_function(wait_timer, & state->m_timer);
+      state->m_timer_start= timer_start;
       flags|= STATE_FLAG_TIMED;
+    }
 
     if (flag_events_waits_current)
     {
-      if (unlikely(pfs_thread->m_events_waits_count >= WAIT_STACK_SIZE))
+      if (unlikely(pfs_thread->m_events_waits_current >=
+                   & pfs_thread->m_events_waits_stack[WAIT_STACK_SIZE]))
       {
         locker_lost++;
         return NULL;
       }
-      PFS_events_waits *wait= &pfs_thread->m_events_waits_stack[pfs_thread->m_events_waits_count];
+      PFS_events_waits *wait= pfs_thread->m_events_waits_current;
       state->m_wait= wait;
       flags|= STATE_FLAG_EVENT;
 
@@ -2416,7 +2497,7 @@ get_thread_table_io_locker_v1(PSI_table_
       PFS_table_share *share= pfs_table->m_share;
       wait->m_thread= pfs_thread;
       wait->m_class= &global_table_io_class;
-      wait->m_timer_start= 0;
+      wait->m_timer_start= timer_start;
       wait->m_timer_end= 0;
       wait->m_object_instance_addr= pfs_table->m_identity;
       wait->m_event_id= pfs_thread->m_event_id++;
@@ -2427,9 +2508,11 @@ get_thread_table_io_locker_v1(PSI_table_
       wait->m_weak_table_share= share;
       wait->m_weak_version= share->get_version();
       wait->m_index= index;
+      wait->m_source_file= src_file;
+      wait->m_source_line= src_line;
       wait->m_wait_class= WAIT_CLASS_TABLE;
 
-      pfs_thread->m_events_waits_count++;
+      pfs_thread->m_events_waits_current++;
     }
     /* TODO: consider a shortcut here */
   }
@@ -2437,6 +2520,8 @@ get_thread_table_io_locker_v1(PSI_table_
   {
     if (pfs_table->m_io_timed)
     {
+      timer_start= get_timer_raw_value_and_function(wait_timer, & state->m_timer);
+      state->m_timer_start= timer_start;
       flags= STATE_FLAG_TIMED;
     }
     else
@@ -2455,20 +2540,21 @@ get_thread_table_io_locker_v1(PSI_table_
 
 /**
   Implementation of the table instrumentation interface.
-  @sa PSI_v1::get_thread_table_lock_locker.
+  @sa PSI_v1::start_table_lock_wait.
 */
 static PSI_table_locker*
-get_thread_table_lock_locker_v1(PSI_table_locker_state *state,
-                                PSI_table *table, PSI_table_lock_operation op, ulong op_flags)
+start_table_lock_wait_v1(PSI_table_locker_state *state,
+                         PSI_table *table,
+                         PSI_table_lock_operation op,
+                         ulong op_flags,
+                         const char *src_file, uint src_line)
 {
   DBUG_ASSERT(state != NULL);
   DBUG_ASSERT((op == PSI_TABLE_LOCK) || (op == PSI_TABLE_EXTERNAL_LOCK));
 
   PFS_table *pfs_table= reinterpret_cast<PFS_table*> (table);
 
-  if (unlikely(pfs_table == NULL))
-    return NULL;
-
+  DBUG_ASSERT(pfs_table != NULL);
   DBUG_ASSERT(pfs_table->m_share != NULL);
 
   if (! pfs_table->m_lock_enabled)
@@ -2505,6 +2591,7 @@ get_thread_table_lock_locker_v1(PSI_tabl
   DBUG_ASSERT((uint) lock_type < array_elements(table_lock_operation_map));
 
   register uint flags;
+  ulonglong timer_start= 0;
 
   if (flag_thread_instrumentation)
   {
@@ -2514,16 +2601,21 @@ get_thread_table_lock_locker_v1(PSI_tabl
     flags= STATE_FLAG_THREAD;
 
     if (pfs_table->m_lock_timed)
+    {
+      timer_start= get_timer_raw_value_and_function(wait_timer, & state->m_timer);
+      state->m_timer_start= timer_start;
       flags|= STATE_FLAG_TIMED;
+    }
 
     if (flag_events_waits_current)
     {
-      if (unlikely(pfs_thread->m_events_waits_count >= WAIT_STACK_SIZE))
+      if (unlikely(pfs_thread->m_events_waits_current >=
+                   & pfs_thread->m_events_waits_stack[WAIT_STACK_SIZE]))
       {
         locker_lost++;
         return NULL;
       }
-      PFS_events_waits *wait= &pfs_thread->m_events_waits_stack[pfs_thread->m_events_waits_count];
+      PFS_events_waits *wait= pfs_thread->m_events_waits_current;
       state->m_wait= wait;
       flags|= STATE_FLAG_EVENT;
 
@@ -2535,7 +2627,7 @@ get_thread_table_lock_locker_v1(PSI_tabl
       PFS_table_share *share= pfs_table->m_share;
       wait->m_thread= pfs_thread;
       wait->m_class= &global_table_lock_class;
-      wait->m_timer_start= 0;
+      wait->m_timer_start= timer_start;
       wait->m_timer_end= 0;
       wait->m_object_instance_addr= pfs_table->m_identity;
       wait->m_event_id= pfs_thread->m_event_id++;
@@ -2546,9 +2638,11 @@ get_thread_table_lock_locker_v1(PSI_tabl
       wait->m_weak_table_share= share;
       wait->m_weak_version= share->get_version();
       wait->m_index= 0;
+      wait->m_source_file= src_file;
+      wait->m_source_line= src_line;
       wait->m_wait_class= WAIT_CLASS_TABLE;
 
-      pfs_thread->m_events_waits_count++;
+      pfs_thread->m_events_waits_current++;
     }
     /* TODO: consider a shortcut here */
   }
@@ -2556,6 +2650,8 @@ get_thread_table_lock_locker_v1(PSI_tabl
   {
     if (pfs_table->m_lock_timed)
     {
+      timer_start= get_timer_raw_value_and_function(wait_timer, & state->m_timer);
+      state->m_timer_start= timer_start;
       flags= STATE_FLAG_TIMED;
     }
     else
@@ -2616,12 +2712,13 @@ get_thread_file_name_locker_v1(PSI_file_
 
   if (flag_events_waits_current)
   {
-    if (unlikely(pfs_thread->m_events_waits_count >= WAIT_STACK_SIZE))
+    if (unlikely(pfs_thread->m_events_waits_current >=
+                 & pfs_thread->m_events_waits_stack[WAIT_STACK_SIZE]))
     {
       locker_lost++;
       return NULL;
     }
-    PFS_events_waits *wait= &pfs_thread->m_events_waits_stack[pfs_thread->m_events_waits_count];
+    PFS_events_waits *wait= pfs_thread->m_events_waits_current;
     state->m_wait= wait;
     flags|= STATE_FLAG_EVENT;
 
@@ -2642,7 +2739,7 @@ get_thread_file_name_locker_v1(PSI_file_
     wait->m_operation= file_operation_map[static_cast<int> (op)];
     wait->m_wait_class= WAIT_CLASS_FILE;
 
-    pfs_thread->m_events_waits_count++;
+    pfs_thread->m_events_waits_current++;
   }
 
   state->m_flags= flags;
@@ -2688,12 +2785,13 @@ get_thread_file_stream_locker_v1(PSI_fil
 
     if (flag_events_waits_current)
     {
-      if (unlikely(pfs_thread->m_events_waits_count >= WAIT_STACK_SIZE))
+      if (unlikely(pfs_thread->m_events_waits_current >=
+                   & pfs_thread->m_events_waits_stack[WAIT_STACK_SIZE]))
       {
         locker_lost++;
         return NULL;
       }
-      PFS_events_waits *wait= &pfs_thread->m_events_waits_stack[pfs_thread->m_events_waits_count];
+      PFS_events_waits *wait= pfs_thread->m_events_waits_current;
       state->m_wait= wait;
       flags|= STATE_FLAG_EVENT;
 
@@ -2714,7 +2812,7 @@ get_thread_file_stream_locker_v1(PSI_fil
       wait->m_operation= file_operation_map[static_cast<int> (op)];
       wait->m_wait_class= WAIT_CLASS_FILE;
 
-      pfs_thread->m_events_waits_count++;
+      pfs_thread->m_events_waits_current++;
     }
   }
   else
@@ -2789,12 +2887,13 @@ get_thread_file_descriptor_locker_v1(PSI
 
     if (flag_events_waits_current)
     {
-      if (unlikely(pfs_thread->m_events_waits_count >= WAIT_STACK_SIZE))
+      if (unlikely(pfs_thread->m_events_waits_current >=
+                   & pfs_thread->m_events_waits_stack[WAIT_STACK_SIZE]))
       {
         locker_lost++;
         return NULL;
       }
-      PFS_events_waits *wait= &pfs_thread->m_events_waits_stack[pfs_thread->m_events_waits_count];
+      PFS_events_waits *wait= pfs_thread->m_events_waits_current;
       state->m_wait= wait;
       flags|= STATE_FLAG_EVENT;
 
@@ -2815,7 +2914,7 @@ get_thread_file_descriptor_locker_v1(PSI
       wait->m_operation= file_operation_map[static_cast<int> (op)];
       wait->m_wait_class= WAIT_CLASS_FILE;
 
-      pfs_thread->m_events_waits_count++;
+      pfs_thread->m_events_waits_current++;
     }
   }
   else
@@ -2841,23 +2940,25 @@ get_thread_file_descriptor_locker_v1(PSI
 /** Socket locker */
 
 static PSI_socket_locker*
-get_thread_socket_locker_v1(PSI_socket_locker_state *state,
-                            PSI_socket *socket, PSI_socket_operation op)
+start_socket_wait_v1(PSI_socket_locker_state *state,
+                     PSI_socket *socket,
+                     PSI_socket_operation op,
+                     size_t count,
+                     const char *src_file, uint src_line)
 {
   DBUG_ASSERT(static_cast<int> (op) >= 0);
   DBUG_ASSERT(static_cast<uint> (op) < array_elements(socket_operation_map));
   DBUG_ASSERT(state != NULL);
   PFS_socket *pfs_socket= reinterpret_cast<PFS_socket*> (socket);
 
-  if (unlikely(pfs_socket == NULL))
-    return NULL;
-
+  DBUG_ASSERT(pfs_socket != NULL);
   DBUG_ASSERT(pfs_socket->m_class != NULL);
 
   if (!pfs_socket->m_enabled || pfs_socket->m_idle)
     return NULL;
 
   register uint flags= 0;
+  ulonglong timer_start= 0;
 
   if (flag_thread_instrumentation)
   {
@@ -2880,17 +2981,22 @@ get_thread_socket_locker_v1(PSI_socket_l
     state->m_thread= reinterpret_cast<PSI_thread *> (pfs_thread);
     flags= STATE_FLAG_THREAD;
 
-    if (pfs_socket->m_timed && !pfs_socket->m_idle)
+    if (pfs_socket->m_timed)
+    {
+      timer_start= get_timer_raw_value_and_function(wait_timer, & state->m_timer);
+      state->m_timer_start= timer_start;
       flags|= STATE_FLAG_TIMED;
+    }
 
     if (flag_events_waits_current)
     {
-      if (unlikely(pfs_thread->m_events_waits_count >= WAIT_STACK_SIZE))
+      if (unlikely(pfs_thread->m_events_waits_current >=
+                   & pfs_thread->m_events_waits_stack[WAIT_STACK_SIZE]))
       {
         locker_lost++;
         return NULL;
       }
-      PFS_events_waits *wait= &pfs_thread->m_events_waits_stack[pfs_thread->m_events_waits_count];
+      PFS_events_waits *wait= pfs_thread->m_events_waits_current;
       state->m_wait= wait;
       flags|= STATE_FLAG_EVENT;
 
@@ -2900,7 +3006,7 @@ get_thread_socket_locker_v1(PSI_socket_l
       wait->m_nesting_event_type= parent_event->m_event_type;
       wait->m_thread=       pfs_thread;
       wait->m_class=        pfs_socket->m_class;
-      wait->m_timer_start=  0;
+      wait->m_timer_start=  timer_start;
       wait->m_timer_end=    0;
       wait->m_object_instance_addr= pfs_socket->m_identity;
       wait->m_weak_socket=  pfs_socket;
@@ -2908,15 +3014,20 @@ get_thread_socket_locker_v1(PSI_socket_l
       wait->m_event_id=     pfs_thread->m_event_id++;
       wait->m_end_event_id= 0;
       wait->m_operation=    socket_operation_map[static_cast<int>(op)];
+      wait->m_source_file= src_file;
+      wait->m_source_line= src_line;
+      wait->m_number_of_bytes= count;
       wait->m_wait_class=   WAIT_CLASS_SOCKET;
 
-      pfs_thread->m_events_waits_count++;
+      pfs_thread->m_events_waits_current++;
     }
   }
   else
   {
     if (pfs_socket->m_timed)
     {
+      timer_start= get_timer_raw_value_and_function(wait_timer, & state->m_timer);
+      state->m_timer_start= timer_start;
       flags= STATE_FLAG_TIMED;
     }
     else
@@ -2960,8 +3071,7 @@ static void unlock_mutex_v1(PSI_mutex *m
 {
   PFS_mutex *pfs_mutex= reinterpret_cast<PFS_mutex*> (mutex);
 
-  if (unlikely(pfs_mutex == NULL))
-    return;
+  DBUG_ASSERT(pfs_mutex != NULL);
 
   /*
     Note that this code is still protected by the instrumented mutex,
@@ -3004,11 +3114,11 @@ static void unlock_mutex_v1(PSI_mutex *m
 static void unlock_rwlock_v1(PSI_rwlock *rwlock)
 {
   PFS_rwlock *pfs_rwlock= reinterpret_cast<PFS_rwlock*> (rwlock);
-
-  if (unlikely(pfs_rwlock == NULL))
-    return;
-
   DBUG_ASSERT(pfs_rwlock != NULL);
+  DBUG_ASSERT(pfs_rwlock == sanitize_rwlock(pfs_rwlock));
+  DBUG_ASSERT(pfs_rwlock->m_class != NULL);
+  DBUG_ASSERT(pfs_rwlock->m_lock.is_populated());
+
   bool last_writer= false;
   bool last_reader= false;
 
@@ -3021,7 +3131,7 @@ static void unlock_rwlock_v1(PSI_rwlock
   */
 
   /* Always update the instrumented state */
-  if (pfs_rwlock->m_writer)
+  if (pfs_rwlock->m_writer != NULL)
   {
     /* Nominal case, a writer is unlocking. */
     last_writer= true;
@@ -3092,8 +3202,7 @@ static void signal_cond_v1(PSI_cond* con
 {
   PFS_cond *pfs_cond= reinterpret_cast<PFS_cond*> (cond);
 
-  if (unlikely(pfs_cond == NULL))
-    return;
+  DBUG_ASSERT(pfs_cond != NULL);
 
   pfs_cond->m_cond_stat.m_signal_count++;
 }
@@ -3106,8 +3215,7 @@ static void broadcast_cond_v1(PSI_cond*
 {
   PFS_cond *pfs_cond= reinterpret_cast<PFS_cond*> (cond);
 
-  if (unlikely(pfs_cond == NULL))
-    return;
+  DBUG_ASSERT(pfs_cond != NULL);
 
   pfs_cond->m_cond_stat.m_broadcast_count++;
 }
@@ -3149,12 +3257,13 @@ start_idle_wait_v1(PSI_idle_locker_state
 
     if (flag_events_waits_current)
     {
-      if (unlikely(pfs_thread->m_events_waits_count >= WAIT_STACK_SIZE))
+      if (unlikely(pfs_thread->m_events_waits_current >=
+                   & pfs_thread->m_events_waits_stack[WAIT_STACK_SIZE]))
       {
         locker_lost++;
         return NULL;
       }
-      PFS_events_waits *wait= &pfs_thread->m_events_waits_stack[pfs_thread->m_events_waits_count];
+      PFS_events_waits *wait= pfs_thread->m_events_waits_current;
       state->m_wait= wait;
       flags|= STATE_FLAG_EVENT;
 
@@ -3178,7 +3287,7 @@ start_idle_wait_v1(PSI_idle_locker_state
       wait->m_source_line= src_line;
       wait->m_wait_class= WAIT_CLASS_IDLE;
 
-      pfs_thread->m_events_waits_count++;
+      pfs_thread->m_events_waits_current++;
     }
   }
   else
@@ -3243,49 +3352,20 @@ static void end_idle_wait_v1(PSI_idle_lo
         insert_events_waits_history(thread, wait);
       if (flag_events_waits_history_long)
         insert_events_waits_history_long(wait);
-      thread->m_events_waits_count--;
+      thread->m_events_waits_current--;
     }
   }
 }
 
 /**
   Implementation of the mutex instrumentation interface.
-  @sa PSI_v1::start_mutex_wait.
-*/
-static void start_mutex_wait_v1(PSI_mutex_locker* locker,
-                                const char *src_file, uint src_line)
-{
-  PSI_mutex_locker_state *state= reinterpret_cast<PSI_mutex_locker_state*> (locker);
-  DBUG_ASSERT(state != NULL);
-
-  register uint flags= state->m_flags;
-  ulonglong timer_start= 0;
-
-  if (flags & STATE_FLAG_TIMED)
-  {
-    timer_start= get_timer_raw_value_and_function(wait_timer, & state->m_timer);
-    state->m_timer_start= timer_start;
-  }
-
-  if (flags & STATE_FLAG_EVENT)
-  {
-    PFS_events_waits *wait= reinterpret_cast<PFS_events_waits*> (state->m_wait);
-    DBUG_ASSERT(wait != NULL);
-
-    wait->m_timer_start= timer_start;
-    wait->m_source_file= src_file;
-    wait->m_source_line= src_line;
-  }
-}
-
-/**
-  Implementation of the mutex instrumentation interface.
   @sa PSI_v1::end_mutex_wait.
 */
 static void end_mutex_wait_v1(PSI_mutex_locker* locker, int rc)
 {
   PSI_mutex_locker_state *state= reinterpret_cast<PSI_mutex_locker_state*> (locker);
   DBUG_ASSERT(state != NULL);
+
   ulonglong timer_end= 0;
   ulonglong wait_time= 0;
 
@@ -3342,51 +3422,25 @@ static void end_mutex_wait_v1(PSI_mutex_
         insert_events_waits_history(thread, wait);
       if (flag_events_waits_history_long)
         insert_events_waits_history_long(wait);
-      thread->m_events_waits_count--;
+      thread->m_events_waits_current--;
     }
   }
 }
 
 /**
   Implementation of the rwlock instrumentation interface.
-  @sa PSI_v1::start_rwlock_rdwait.
-*/
-static void start_rwlock_rdwait_v1(PSI_rwlock_locker* locker,
-                                   const char *src_file, uint src_line)
-{
-  ulonglong timer_start= 0;
-  PSI_rwlock_locker_state *state= reinterpret_cast<PSI_rwlock_locker_state*> (locker);
-  DBUG_ASSERT(state != NULL);
-
-  if (state->m_flags & STATE_FLAG_TIMED)
-  {
-    timer_start= get_timer_raw_value_and_function(wait_timer, & state->m_timer);
-    state->m_timer_start= timer_start;
-  }
-
-  if (state->m_flags & STATE_FLAG_EVENT)
-  {
-    PFS_events_waits *wait= reinterpret_cast<PFS_events_waits*> (state->m_wait);
-    DBUG_ASSERT(wait != NULL);
-
-    wait->m_timer_start= timer_start;
-    wait->m_source_file= src_file;
-    wait->m_source_line= src_line;
-  }
-}
-
-/**
-  Implementation of the rwlock instrumentation interface.
   @sa PSI_v1::end_rwlock_rdwait.
 */
 static void end_rwlock_rdwait_v1(PSI_rwlock_locker* locker, int rc)
 {
   PSI_rwlock_locker_state *state= reinterpret_cast<PSI_rwlock_locker_state*> (locker);
   DBUG_ASSERT(state != NULL);
+
   ulonglong timer_end= 0;
   ulonglong wait_time= 0;
 
   PFS_rwlock *rwlock= reinterpret_cast<PFS_rwlock *> (state->m_rwlock);
+  DBUG_ASSERT(rwlock != NULL);
 
   if (state->m_flags & STATE_FLAG_TIMED)
   {
@@ -3447,51 +3501,25 @@ static void end_rwlock_rdwait_v1(PSI_rwl
         insert_events_waits_history(thread, wait);
       if (flag_events_waits_history_long)
         insert_events_waits_history_long(wait);
-      thread->m_events_waits_count--;
+      thread->m_events_waits_current--;
     }
   }
 }
 
 /**
   Implementation of the rwlock instrumentation interface.
-  @sa PSI_v1::start_rwlock_wrwait.
-*/
-static void start_rwlock_wrwait_v1(PSI_rwlock_locker* locker,
-                                   const char *src_file, uint src_line)
-{
-  ulonglong timer_start= 0;
-  PSI_rwlock_locker_state *state= reinterpret_cast<PSI_rwlock_locker_state*> (locker);
-  DBUG_ASSERT(state != NULL);
-
-  if (state->m_flags & STATE_FLAG_TIMED)
-  {
-    timer_start= get_timer_raw_value_and_function(wait_timer, & state->m_timer);
-    state->m_timer_start= timer_start;
-  }
-
-  if (state->m_flags & STATE_FLAG_EVENT)
-  {
-    PFS_events_waits *wait= reinterpret_cast<PFS_events_waits*> (state->m_wait);
-    DBUG_ASSERT(wait != NULL);
-
-    wait->m_timer_start= timer_start;
-    wait->m_source_file= src_file;
-    wait->m_source_line= src_line;
-  }
-}
-
-/**
-  Implementation of the rwlock instrumentation interface.
   @sa PSI_v1::end_rwlock_wrwait.
 */
 static void end_rwlock_wrwait_v1(PSI_rwlock_locker* locker, int rc)
 {
   PSI_rwlock_locker_state *state= reinterpret_cast<PSI_rwlock_locker_state*> (locker);
   DBUG_ASSERT(state != NULL);
+
   ulonglong timer_end= 0;
   ulonglong wait_time= 0;
 
   PFS_rwlock *rwlock= reinterpret_cast<PFS_rwlock *> (state->m_rwlock);
+  DBUG_ASSERT(rwlock != NULL);
   PFS_thread *thread= reinterpret_cast<PFS_thread *> (state->m_thread);
 
   if (state->m_flags & STATE_FLAG_TIMED)
@@ -3545,47 +3573,20 @@ static void end_rwlock_wrwait_v1(PSI_rwl
         insert_events_waits_history(thread, wait);
       if (flag_events_waits_history_long)
         insert_events_waits_history_long(wait);
-      thread->m_events_waits_count--;
+      thread->m_events_waits_current--;
     }
   }
 }
 
 /**
   Implementation of the cond instrumentation interface.
-  @sa PSI_v1::start_cond_wait.
-*/
-static void start_cond_wait_v1(PSI_cond_locker* locker,
-                               const char *src_file, uint src_line)
-{
-  ulonglong timer_start= 0;
-  PSI_cond_locker_state *state= reinterpret_cast<PSI_cond_locker_state*> (locker);
-  DBUG_ASSERT(state != NULL);
-
-  if (state->m_flags & STATE_FLAG_TIMED)
-  {
-    timer_start= get_timer_raw_value_and_function(wait_timer, & state->m_timer);
-    state->m_timer_start= timer_start;
-  }
-
-  if (state->m_flags & STATE_FLAG_EVENT)
-  {
-    PFS_events_waits *wait= reinterpret_cast<PFS_events_waits*> (state->m_wait);
-    DBUG_ASSERT(wait != NULL);
-
-    wait->m_timer_start= timer_start;
-    wait->m_source_file= src_file;
-    wait->m_source_line= src_line;
-  }
-}
-
-/**
-  Implementation of the cond instrumentation interface.
   @sa PSI_v1::end_cond_wait.
 */
 static void end_cond_wait_v1(PSI_cond_locker* locker, int rc)
 {
   PSI_cond_locker_state *state= reinterpret_cast<PSI_cond_locker_state*> (locker);
   DBUG_ASSERT(state != NULL);
+
   ulonglong timer_end= 0;
   ulonglong wait_time= 0;
 
@@ -3636,49 +3637,20 @@ static void end_cond_wait_v1(PSI_cond_lo
         insert_events_waits_history(thread, wait);
       if (flag_events_waits_history_long)
         insert_events_waits_history_long(wait);
-      thread->m_events_waits_count--;
+      thread->m_events_waits_current--;
     }
   }
 }
 
 /**
   Implementation of the table instrumentation interface.
-  @sa PSI_v1::start_table_io_wait.
-*/
-static void start_table_io_wait_v1(PSI_table_locker* locker,
-                                   const char *src_file, uint src_line)
-{
-  ulonglong timer_start= 0;
-  PSI_table_locker_state *state= reinterpret_cast<PSI_table_locker_state*> (locker);
-  DBUG_ASSERT(state != NULL);
-
-  register uint flags= state->m_flags;
-
-  if (flags & STATE_FLAG_TIMED)
-  {
-    timer_start= get_timer_raw_value_and_function(wait_timer, & state->m_timer);
-    state->m_timer_start= timer_start;
-  }
-
-  if (flags & STATE_FLAG_EVENT)
-  {
-    PFS_events_waits *wait= reinterpret_cast<PFS_events_waits*> (state->m_wait);
-    DBUG_ASSERT(wait != NULL);
-
-    wait->m_timer_start= timer_start;
-    wait->m_source_file= src_file;
-    wait->m_source_line= src_line;
-  }
-}
-
-/**
-  Implementation of the table instrumentation interface.
   @sa PSI_v1::end_table_io_wait.
 */
 static void end_table_io_wait_v1(PSI_table_locker* locker)
 {
   PSI_table_locker_state *state= reinterpret_cast<PSI_table_locker_state*> (locker);
   DBUG_ASSERT(state != NULL);
+
   ulonglong timer_end= 0;
   ulonglong wait_time= 0;
 
@@ -3738,7 +3710,7 @@ static void end_table_io_wait_v1(PSI_tab
       insert_events_waits_history(thread, wait);
     if (flag_events_waits_history_long)
       insert_events_waits_history_long(wait);
-    thread->m_events_waits_count--;
+    thread->m_events_waits_current--;
   }
 
   table->m_has_io_stats= true;
@@ -3746,42 +3718,13 @@ static void end_table_io_wait_v1(PSI_tab
 
 /**
   Implementation of the table instrumentation interface.
-  @sa PSI_v1::start_table_lock_wait.
-*/
-static void start_table_lock_wait_v1(PSI_table_locker* locker,
-                                     const char *src_file, uint src_line)
-{
-  ulonglong timer_start= 0;
-  PSI_table_locker_state *state= reinterpret_cast<PSI_table_locker_state*> (locker);
-  DBUG_ASSERT(state != NULL);
-
-  register uint flags= state->m_flags;
-
-  if (flags & STATE_FLAG_TIMED)
-  {
-    timer_start= get_timer_raw_value_and_function(wait_timer, & state->m_timer);
-    state->m_timer_start= timer_start;
-  }
-
-  if (flags & STATE_FLAG_EVENT)
-  {
-    PFS_events_waits *wait= reinterpret_cast<PFS_events_waits*> (state->m_wait);
-    DBUG_ASSERT(wait != NULL);
-
-    wait->m_timer_start= timer_start;
-    wait->m_source_file= src_file;
-    wait->m_source_line= src_line;
-  }
-}
-
-/**
-  Implementation of the table instrumentation interface.
   @sa PSI_v1::end_table_lock_wait.
 */
 static void end_table_lock_wait_v1(PSI_table_locker* locker)
 {
   PSI_table_locker_state *state= reinterpret_cast<PSI_table_locker_state*> (locker);
   DBUG_ASSERT(state != NULL);
+
   ulonglong timer_end= 0;
   ulonglong wait_time= 0;
 
@@ -3818,7 +3761,7 @@ static void end_table_lock_wait_v1(PSI_t
       insert_events_waits_history(thread, wait);
     if (flag_events_waits_history_long)
       insert_events_waits_history_long(wait);
-    thread->m_events_waits_count--;
+    thread->m_events_waits_current--;
   }
 
   table->m_has_lock_stats= true;
@@ -4018,7 +3961,7 @@ static void end_file_wait_v1(PSI_file_lo
         insert_events_waits_history(thread, wait);
       if (flag_events_waits_history_long)
         insert_events_waits_history_long(wait);
-      thread->m_events_waits_count--;
+      thread->m_events_waits_current--;
     }
   }
 
@@ -4672,47 +4615,6 @@ static void end_statement_v1(PSI_stateme
   }
 }
 
-/** Socket operations */
-
-static void start_socket_wait_v1(PSI_socket_locker *locker,
-                                     size_t byte_count,
-                                     const char *src_file,
-                                     uint src_line);
-
-static void end_socket_wait_v1(PSI_socket_locker *locker, size_t byte_count);
-
-/**
-  Implementation of the socket instrumentation interface.
-  @sa PSI_v1::start_socket_wait.
-*/
-static void start_socket_wait_v1(PSI_socket_locker *locker,
-                                 size_t byte_count,
-                                 const char *src_file, uint src_line)
-{
-  PSI_socket_locker_state *state= reinterpret_cast<PSI_socket_locker_state*> (locker);
-  DBUG_ASSERT(state != NULL);
-
-  register uint flags= state->m_flags;
-  ulonglong timer_start= 0;
-
-  if (flags & STATE_FLAG_TIMED)
-  {
-    timer_start= get_timer_raw_value_and_function(wait_timer, &state->m_timer);
-    state->m_timer_start= timer_start;
-  }
-
-  if (flags & STATE_FLAG_EVENT)
-  {
-    PFS_events_waits *wait= reinterpret_cast<PFS_events_waits*> (state->m_wait);
-    DBUG_ASSERT(wait != NULL);
-
-    wait->m_timer_start= timer_start;
-    wait->m_source_file= src_file;
-    wait->m_source_line= src_line;
-    wait->m_number_of_bytes= byte_count;
-  }
-}
-
 /**
   Implementation of the socket instrumentation interface.
   @sa PSI_v1::end_socket_wait.
@@ -4721,6 +4623,7 @@ static void end_socket_wait_v1(PSI_socke
 {
   PSI_socket_locker_state *state= reinterpret_cast<PSI_socket_locker_state*> (locker);
   DBUG_ASSERT(state != NULL);
+
   PFS_socket *socket= reinterpret_cast<PFS_socket *>(state->m_socket);
   DBUG_ASSERT(socket != NULL);
 
@@ -4753,8 +4656,6 @@ static void end_socket_wait_v1(PSI_socke
     case PSI_SOCKET_STAT:
     case PSI_SOCKET_SHUTDOWN:
     case PSI_SOCKET_SELECT:
-      byte_stat= &socket->m_socket_stat.m_io_stat.m_misc;
-      break;
     case PSI_SOCKET_CLOSE:
       byte_stat= &socket->m_socket_stat.m_io_stat.m_misc;
       break;
@@ -4795,16 +4696,15 @@ static void end_socket_wait_v1(PSI_socke
       insert_events_waits_history(thread, wait);
     if (flag_events_waits_history_long)
       insert_events_waits_history_long(wait);
-    thread->m_events_waits_count--;
+    thread->m_events_waits_current--;
   }
 }
 
 static void set_socket_state_v1(PSI_socket *socket, PSI_socket_state state)
 {
   DBUG_ASSERT((state == PSI_SOCKET_STATE_IDLE) || (state == PSI_SOCKET_STATE_ACTIVE));
-  if (unlikely(socket == NULL))
-    return;
   PFS_socket *pfs= reinterpret_cast<PFS_socket*>(socket);
+  DBUG_ASSERT(pfs != NULL);
   DBUG_ASSERT(pfs->m_idle || (state == PSI_SOCKET_STATE_IDLE));
   DBUG_ASSERT(!pfs->m_idle || (state == PSI_SOCKET_STATE_ACTIVE));
   pfs->m_idle= (state == PSI_SOCKET_STATE_IDLE);
@@ -4818,10 +4718,8 @@ static void set_socket_info_v1(PSI_socke
                                const struct sockaddr *addr,
                                socklen_t addr_len)
 {
-  if (unlikely(socket == NULL))
-    return;
-
   PFS_socket *pfs= reinterpret_cast<PFS_socket*>(socket);
+  DBUG_ASSERT(pfs != NULL);
 
   /** Set socket descriptor */
   if (fd != NULL)
@@ -4846,9 +4744,8 @@ static void set_socket_info_v1(PSI_socke
 */
 static void set_socket_thread_owner_v1(PSI_socket *socket)
 {
-  if (unlikely(socket == NULL))
-    return;
   PFS_socket *pfs_socket= reinterpret_cast<PFS_socket*>(socket);
+  DBUG_ASSERT(pfs_socket != NULL);
   pfs_socket->m_thread_owner= my_pthread_getspecific_ptr(PFS_thread*, THR_PFS);
 }
 
@@ -4896,15 +4793,9 @@ PSI_v1 PFS_v1=
   set_thread_v1,
   delete_current_thread_v1,
   delete_thread_v1,
-  get_thread_mutex_locker_v1,
-  get_thread_rwlock_locker_v1,
-  get_thread_cond_locker_v1,
-  get_thread_table_io_locker_v1,
-  get_thread_table_lock_locker_v1,
   get_thread_file_name_locker_v1,
   get_thread_file_stream_locker_v1,
   get_thread_file_descriptor_locker_v1,
-  get_thread_socket_locker_v1,
   unlock_mutex_v1,
   unlock_rwlock_v1,
   signal_cond_v1,
@@ -4913,9 +4804,9 @@ PSI_v1 PFS_v1=
   end_idle_wait_v1,
   start_mutex_wait_v1,
   end_mutex_wait_v1,
-  start_rwlock_rdwait_v1,
+  start_rwlock_wait_v1, /* read */
   end_rwlock_rdwait_v1,
-  start_rwlock_wrwait_v1,
+  start_rwlock_wait_v1, /* write */
   end_rwlock_wrwait_v1,
   start_cond_wait_v1,
   end_cond_wait_v1,

=== modified file 'storage/perfschema/pfs_instr.cc'
--- a/storage/perfschema/pfs_instr.cc	2011-10-27 21:18:19 +0000
+++ b/storage/perfschema/pfs_instr.cc	2012-01-06 09:03:53 +0000
@@ -613,8 +613,7 @@ PFS_mutex* create_mutex(PFS_mutex_class
       in a given loop by a given thread, other threads will not attempt this
       slot.
     */
-    PFS_atomic::add_u32(& mutex_monotonic_index, 1);
-    index= mutex_monotonic_index % mutex_max;
+    index= PFS_atomic::add_u32(& mutex_monotonic_index, 1) % mutex_max;
     pfs= mutex_array + index;
 
     if (pfs->m_lock.is_free())
@@ -674,8 +673,7 @@ PFS_rwlock* create_rwlock(PFS_rwlock_cla
   while (++attempts <= rwlock_max)
   {
     /* See create_mutex() */
-    PFS_atomic::add_u32(& rwlock_monotonic_index, 1);
-    index= rwlock_monotonic_index % rwlock_max;
+    index= PFS_atomic::add_u32(& rwlock_monotonic_index, 1) % rwlock_max;
     pfs= rwlock_array + index;
 
     if (pfs->m_lock.is_free())
@@ -738,8 +736,7 @@ PFS_cond* create_cond(PFS_cond_class *kl
   while (++attempts <= cond_max)
   {
     /* See create_mutex() */
-    PFS_atomic::add_u32(& cond_monotonic_index, 1);
-    index= cond_monotonic_index % cond_max;
+    index= PFS_atomic::add_u32(& cond_monotonic_index, 1) % cond_max;
     pfs= cond_array + index;
 
     if (pfs->m_lock.is_free())
@@ -808,8 +805,7 @@ PFS_thread* create_thread(PFS_thread_cla
   while (++attempts <= thread_max)
   {
     /* See create_mutex() */
-    PFS_atomic::add_u32(& thread_monotonic_index, 1);
-    index= thread_monotonic_index % thread_max;
+    index= PFS_atomic::add_u32(& thread_monotonic_index, 1) % thread_max;
     pfs= thread_array + index;
 
     if (pfs->m_lock.is_free())
@@ -823,7 +819,7 @@ PFS_thread* create_thread(PFS_thread_cla
         pfs->m_event_id= 1;
         pfs->m_enabled= true;
         pfs->m_class= klass;
-        pfs->m_events_waits_count= WAIT_STACK_BOTTOM;
+        pfs->m_events_waits_current= & pfs->m_events_waits_stack[WAIT_STACK_BOTTOM];
         pfs->m_waits_history_full= false;
         pfs->m_waits_history_index= 0;
         pfs->m_stages_history_full= false;
@@ -1174,8 +1170,7 @@ search:
   while (++attempts <= file_max)
   {
     /* See create_mutex() */
-    PFS_atomic::add_u32(& file_monotonic_index, 1);
-    index= file_monotonic_index % file_max;
+    index= PFS_atomic::add_u32(& file_monotonic_index, 1) % file_max;
     pfs= file_array + index;
 
     if (pfs->m_lock.is_free())
@@ -1290,8 +1285,7 @@ PFS_table* create_table(PFS_table_share
   while (++attempts <= table_max)
   {
     /* See create_mutex() */
-    PFS_atomic::add_u32(& table_monotonic_index, 1);
-    index= table_monotonic_index % table_max;
+    index= PFS_atomic::add_u32(& table_monotonic_index, 1) % table_max;
     pfs= table_array + index;
 
     if (pfs->m_lock.is_free())
@@ -1309,7 +1303,7 @@ PFS_table* create_table(PFS_table_share
         pfs->m_has_io_stats= false;
         pfs->m_has_lock_stats= false;
         share->inc_refcount();
-        pfs->m_table_stat.reset();
+        pfs->m_table_stat.fast_reset();
         pfs->m_thread_owner= opening_thread;
         pfs->m_lock.dirty_to_allocated();
         return pfs;
@@ -1391,7 +1385,7 @@ void PFS_table::safe_aggregate(PFS_table
 
   /* Aggregate to TABLE_IO_SUMMARY, TABLE_LOCK_SUMMARY */
   table_share->m_table_stat.aggregate(table_stat);
-  table_stat->reset();
+  table_stat->fast_reset();
 }
 
 void PFS_table::safe_aggregate_io(PFS_table_stat *table_stat,
@@ -1418,7 +1412,7 @@ void PFS_table::safe_aggregate_io(PFS_ta
 
   /* Aggregate to TABLE_IO_SUMMARY */
   table_share->m_table_stat.aggregate_io(table_stat);
-  table_stat->reset();
+  table_stat->fast_reset_io();
 }
 
 void PFS_table::safe_aggregate_lock(PFS_table_stat *table_stat,
@@ -1445,7 +1439,7 @@ void PFS_table::safe_aggregate_lock(PFS_
 
   /* Aggregate to TABLE_LOCK_SUMMARY */
   table_share->m_table_stat.aggregate_lock(table_stat);
-  table_stat->reset();
+  table_stat->fast_reset_lock();
 }
 
 /**

=== modified file 'storage/perfschema/pfs_instr.h'
--- a/storage/perfschema/pfs_instr.h	2011-10-06 16:06:40 +0000
+++ b/storage/perfschema/pfs_instr.h	2012-01-06 09:03:53 +0000
@@ -377,8 +377,8 @@ struct PFS_thread : PFS_connection_slice
 
   /** Thread instrumentation flag. */
   bool m_enabled;
-  /** Size of @c m_events_waits_stack. */
-  uint m_events_waits_count;
+  /** Current wait event in the event stack. */
+  PFS_events_waits *m_events_waits_current;
   /** Event ID counter */
   ulonglong m_event_id;
   /** Internal lock. */

=== modified file 'storage/perfschema/pfs_instr_class.cc'
--- a/storage/perfschema/pfs_instr_class.cc	2011-11-17 21:44:20 +0000
+++ b/storage/perfschema/pfs_instr_class.cc	2012-01-06 09:03:53 +0000
@@ -1249,7 +1249,7 @@ search:
     {
       set_keys(pfs, share);
       /* FIXME: aggregate to table_share sink ? */
-      pfs->m_table_stat.reset();
+      pfs->m_table_stat.fast_reset();
     }
     lf_hash_search_unpin(pins);
     return pfs;
@@ -1291,7 +1291,7 @@ search:
         pfs->m_enabled= enabled;
         pfs->m_timed= timed;
         pfs->init_refcount();
-        pfs->m_table_stat.reset();
+        pfs->m_table_stat.fast_reset();
         set_keys(pfs, share);
 
         int res;
@@ -1332,7 +1332,7 @@ void PFS_table_share::aggregate_io(void)
   uint index= global_table_io_class.m_event_name_index;
   PFS_single_stat *table_io_total= & global_instr_class_waits_array[index];
   m_table_stat.sum_io(table_io_total);
-  m_table_stat.reset_io();
+  m_table_stat.fast_reset_io();
 }
 
 void PFS_table_share::aggregate_lock(void)
@@ -1340,7 +1340,7 @@ void PFS_table_share::aggregate_lock(voi
   uint index= global_table_lock_class.m_event_name_index;
   PFS_single_stat *table_lock_total= & global_instr_class_waits_array[index];
   m_table_stat.sum_lock(table_lock_total);
-  m_table_stat.reset_lock();
+  m_table_stat.fast_reset_lock();
 }
 
 void release_table_share(PFS_table_share *pfs)

=== modified file 'storage/perfschema/pfs_server.cc'
--- a/storage/perfschema/pfs_server.cc	2011-11-21 21:02:04 +0000
+++ b/storage/perfschema/pfs_server.cc	2012-01-06 09:03:53 +0000
@@ -39,6 +39,8 @@
 
 PFS_global_param pfs_param;
 
+PFS_table_stat PFS_table_stat::g_reset_template;
+
 C_MODE_START
 static void destroy_pfs_thread(void *key);
 C_MODE_END
@@ -50,6 +52,8 @@ initialize_performance_schema(const PFS_
 {
   pfs_initialized= false;
 
+  PFS_table_stat::g_reset_template.reset();
+
   if (! param->m_enabled)
   {
     /*

=== modified file 'storage/perfschema/pfs_stat.h'
--- a/storage/perfschema/pfs_stat.h	2011-09-02 20:03:36 +0000
+++ b/storage/perfschema/pfs_stat.h	2012-01-06 09:03:53 +0000
@@ -17,6 +17,8 @@
 #define PFS_STAT_H
 
 #include "sql_const.h"
+/* memcpy */
+#include "string.h"
 
 /**
   @file storage/perfschema/pfs_stat.h
@@ -449,6 +451,21 @@ struct PFS_table_stat
     reset_lock();
   }
 
+  inline void fast_reset_io(void)
+  {
+    memcpy(& m_index_stat, & g_reset_template.m_index_stat, sizeof(m_index_stat));
+  }
+
+  inline void fast_reset_lock(void)
+  {
+    memcpy(& m_lock_stat, & g_reset_template.m_lock_stat, sizeof(m_lock_stat));
+  }
+
+  inline void fast_reset(void)
+  {
+    memcpy(this, & g_reset_template, sizeof(*this));
+  }
+
   inline void aggregate_io(const PFS_table_stat *stat)
   {
     PFS_table_io_stat *to_stat= & m_index_stat[0];
@@ -487,6 +504,8 @@ struct PFS_table_stat
     sum_io(result);
     sum_lock(result);
   }
+
+  static struct PFS_table_stat g_reset_template;
 };
 
 /** Statistics for SOCKET IO. Used for both waits and byte counts. */

=== modified file 'storage/perfschema/table_events_waits.cc'
--- a/storage/perfschema/table_events_waits.cc	2011-08-26 08:42:40 +0000
+++ b/storage/perfschema/table_events_waits.cc	2012-01-06 09:03:53 +0000
@@ -761,9 +761,13 @@ int table_events_waits_current::rnd_next
     if (m_pos.m_index_2 >= 1)
       continue;
 #else
-    uint safe_events_waits_count= pfs_thread->m_events_waits_count - WAIT_STACK_BOTTOM;
+    /* m_events_waits_stack[0] is a dummy record */
+    PFS_events_waits *top_wait = &pfs_thread->m_events_waits_stack[WAIT_STACK_BOTTOM];
+    wait= &pfs_thread->m_events_waits_stack[m_pos.m_index_2 + WAIT_STACK_BOTTOM];
+
+    PFS_events_waits *safe_current = pfs_thread->m_events_waits_current;
 
-    if (safe_events_waits_count == 0)
+    if (safe_current == top_wait)
     {
       /* Display the last top level wait, when completed */
       if (m_pos.m_index_2 >= 1)
@@ -772,14 +776,11 @@ int table_events_waits_current::rnd_next
     else
     {
       /* Display all pending waits, when in progress */
-      if (m_pos.m_index_2 >= safe_events_waits_count)
+      if (wait >= safe_current)
         continue;
     }
 #endif
 
-    /* m_events_waits_stack[0] is a dummy record */
-    wait= &pfs_thread->m_events_waits_stack[m_pos.m_index_2 + WAIT_STACK_BOTTOM];
-
     if (wait->m_wait_class == NO_WAIT_CLASS)
     {
       /*
@@ -814,9 +815,13 @@ int table_events_waits_current::rnd_pos(
   if (m_pos.m_index_2 >= 1)
     return HA_ERR_RECORD_DELETED;
 #else
-  uint safe_events_waits_count= pfs_thread->m_events_waits_count - WAIT_STACK_BOTTOM;
+  /* m_events_waits_stack[0] is a dummy record */
+  PFS_events_waits *top_wait = &pfs_thread->m_events_waits_stack[WAIT_STACK_BOTTOM];
+  wait= &pfs_thread->m_events_waits_stack[m_pos.m_index_2 + WAIT_STACK_BOTTOM];
+
+  PFS_events_waits *safe_current = pfs_thread->m_events_waits_current;
 
-  if (safe_events_waits_count == 0)
+  if (safe_current == top_wait)
   {
     /* Display the last top level wait, when completed */
     if (m_pos.m_index_2 >= 1)
@@ -825,15 +830,13 @@ int table_events_waits_current::rnd_pos(
   else
   {
     /* Display all pending waits, when in progress */
-    if (m_pos.m_index_2 >= safe_events_waits_count)
+    if (wait >= safe_current)
       return HA_ERR_RECORD_DELETED;
   }
 #endif
 
   DBUG_ASSERT(m_pos.m_index_2 < WAIT_STACK_LOGICAL_SIZE);
 
-  wait= &pfs_thread->m_events_waits_stack[m_pos.m_index_2 + WAIT_STACK_BOTTOM];
-
   if (wait->m_wait_class == NO_WAIT_CLASS)
     return HA_ERR_RECORD_DELETED;
 

=== modified file 'storage/perfschema/unittest/pfs-t.cc'
--- a/storage/perfschema/unittest/pfs-t.cc	2011-08-11 03:11:58 +0000
+++ b/storage/perfschema/unittest/pfs-t.cc	2012-01-06 09:03:53 +0000
@@ -1152,11 +1152,11 @@ void test_locker_disabled()
   file_class_A->m_enabled= true;
   socket_class_A->m_enabled= true;
 
-  mutex_locker= psi->get_thread_mutex_locker(&mutex_state, mutex_A1, PSI_MUTEX_LOCK);
+  mutex_locker= psi->start_mutex_wait(&mutex_state, mutex_A1, PSI_MUTEX_LOCK, "foo.cc", 12);
   ok(mutex_locker == NULL, "no locker (T-1 disabled)");
-  rwlock_locker= psi->get_thread_rwlock_locker(&rwlock_state, rwlock_A1, PSI_RWLOCK_READLOCK);
+  rwlock_locker= psi->start_rwlock_rdwait(&rwlock_state, rwlock_A1, PSI_RWLOCK_READLOCK, "foo.cc", 12);
   ok(rwlock_locker == NULL, "no locker (T-1 disabled)");
-  cond_locker= psi->get_thread_cond_locker(&cond_state, cond_A1, mutex_A1, PSI_COND_WAIT);
+  cond_locker= psi->start_cond_wait(&cond_state, cond_A1, mutex_A1, PSI_COND_WAIT, "foo.cc", 12);
   ok(cond_locker == NULL, "no locker (T-1 disabled)");
   file_locker= psi->get_thread_file_name_locker(&file_state, file_key_A, PSI_FILE_OPEN, "xxx", NULL);
   ok(file_locker == NULL, "no locker (T-1 disabled)");
@@ -1164,7 +1164,7 @@ void test_locker_disabled()
   ok(file_locker == NULL, "no locker (T-1 disabled)");
   file_locker= psi->get_thread_file_descriptor_locker(&file_state, (File) 12, PSI_FILE_READ);
   ok(file_locker == NULL, "no locker (T-1 disabled)");
-  socket_locker= psi->get_thread_socket_locker(&socket_state, socket_A1, PSI_SOCKET_SEND);
+  socket_locker= psi->start_socket_wait(&socket_state, socket_A1, PSI_SOCKET_SEND, 12, "foo.cc", 12);
   ok(socket_locker == NULL, "no locker (T-1 disabled)");
 
   /* Pretend the global consumer is disabled */
@@ -1179,11 +1179,11 @@ void test_locker_disabled()
   socket_class_A->m_enabled= true;
   update_instruments_derived_flags();
 
-  mutex_locker= psi->get_thread_mutex_locker(&mutex_state, mutex_A1, PSI_MUTEX_LOCK);
+  mutex_locker= psi->start_mutex_wait(&mutex_state, mutex_A1, PSI_MUTEX_LOCK, "foo.cc", 12);
   ok(mutex_locker == NULL, "no locker (global disabled)");
-  rwlock_locker= psi->get_thread_rwlock_locker(&rwlock_state, rwlock_A1, PSI_RWLOCK_READLOCK);
+  rwlock_locker= psi->start_rwlock_rdwait(&rwlock_state, rwlock_A1, PSI_RWLOCK_READLOCK, "foo.cc", 12);
   ok(rwlock_locker == NULL, "no locker (global disabled)");
-  cond_locker= psi->get_thread_cond_locker(&cond_state, cond_A1, mutex_A1, PSI_COND_WAIT);
+  cond_locker= psi->start_cond_wait(&cond_state, cond_A1, mutex_A1, PSI_COND_WAIT, "foo.cc", 12);
   ok(cond_locker == NULL, "no locker (global disabled)");
   file_locker= psi->get_thread_file_name_locker(&file_state, file_key_A, PSI_FILE_OPEN, "xxx", NULL);
   ok(file_locker == NULL, "no locker (global disabled)");
@@ -1191,7 +1191,7 @@ void test_locker_disabled()
   ok(file_locker == NULL, "no locker (global disabled)");
   file_locker= psi->get_thread_file_descriptor_locker(&file_state, (File) 12, PSI_FILE_READ);
   ok(file_locker == NULL, "no locker (global disabled)");
-  socket_locker= psi->get_thread_socket_locker(&socket_state, socket_A1, PSI_SOCKET_SEND);
+  socket_locker= psi->start_socket_wait(&socket_state, socket_A1, PSI_SOCKET_SEND, 12, "foo.cc", 12);
   ok(socket_locker == NULL, "no locker (global disabled)");
 
   /* Pretend the mode is global, counted only */
@@ -1212,11 +1212,11 @@ void test_locker_disabled()
   socket_class_A->m_timed= false;
   update_instruments_derived_flags();
 
-  mutex_locker= psi->get_thread_mutex_locker(&mutex_state, mutex_A1, PSI_MUTEX_LOCK);
+  mutex_locker= psi->start_mutex_wait(&mutex_state, mutex_A1, PSI_MUTEX_LOCK, "foo.cc", 12);
   ok(mutex_locker == NULL, "no locker (global counted)");
-  rwlock_locker= psi->get_thread_rwlock_locker(&rwlock_state, rwlock_A1, PSI_RWLOCK_READLOCK);
+  rwlock_locker= psi->start_rwlock_rdwait(&rwlock_state, rwlock_A1, PSI_RWLOCK_READLOCK, "foo.cc", 12);
   ok(rwlock_locker == NULL, "no locker (global counted)");
-  cond_locker= psi->get_thread_cond_locker(&cond_state, cond_A1, mutex_A1, PSI_COND_WAIT);
+  cond_locker= psi->start_cond_wait(&cond_state, cond_A1, mutex_A1, PSI_COND_WAIT, "foo.cc", 12);
   ok(cond_locker == NULL, "no locker (global counted)");
   file_locker= psi->get_thread_file_name_locker(&file_state, file_key_A, PSI_FILE_OPEN, "xxx", NULL);
   ok(file_locker != NULL, "locker (global counted)");
@@ -1231,7 +1231,7 @@ void test_locker_disabled()
   psi->start_file_wait(file_locker, 10, __FILE__, __LINE__);
   psi->end_file_wait(file_locker, 10);
   /* The null locker shortcut applies only to socket ops with no byte count */
-  socket_locker= psi->get_thread_socket_locker(&socket_state, socket_A1, PSI_SOCKET_BIND);
+  socket_locker= psi->start_socket_wait(&socket_state, socket_A1, PSI_SOCKET_BIND, 0, "foo.cc", 12);
   ok(socket_locker == NULL, "no locker (global counted)");
 
   /* TODO */
@@ -1249,11 +1249,11 @@ void test_locker_disabled()
   socket_class_A->m_enabled= false;
   update_instruments_derived_flags();
 
-  mutex_locker= psi->get_thread_mutex_locker(&mutex_state, mutex_A1, PSI_MUTEX_LOCK);
+  mutex_locker= psi->start_mutex_wait(&mutex_state, mutex_A1, PSI_MUTEX_LOCK, "foo.cc", 12);
   ok(mutex_locker == NULL, "no locker");
-  rwlock_locker= psi->get_thread_rwlock_locker(&rwlock_state, rwlock_A1, PSI_RWLOCK_READLOCK);
+  rwlock_locker= psi->start_rwlock_rdwait(&rwlock_state, rwlock_A1, PSI_RWLOCK_READLOCK, "foo.cc", 12);
   ok(rwlock_locker == NULL, "no locker");
-  cond_locker= psi->get_thread_cond_locker(&cond_state, cond_A1, mutex_A1, PSI_COND_WAIT);
+  cond_locker= psi->start_cond_wait(&cond_state, cond_A1, mutex_A1, PSI_COND_WAIT, "foo.cc", 12);
   ok(cond_locker == NULL, "no locker");
   file_locker= psi->get_thread_file_name_locker(&file_state, file_key_A, PSI_FILE_OPEN, "xxx", NULL);
   ok(file_locker == NULL, "no locker");
@@ -1261,7 +1261,7 @@ void test_locker_disabled()
   ok(file_locker == NULL, "no locker");
   file_locker= psi->get_thread_file_descriptor_locker(&file_state, (File) 12, PSI_FILE_READ);
   ok(file_locker == NULL, "no locker");
-  socket_locker= psi->get_thread_socket_locker(&socket_state, socket_A1, PSI_SOCKET_SEND);
+  socket_locker= psi->start_socket_wait(&socket_state, socket_A1, PSI_SOCKET_SEND, 12, "foo.cc", 12);
   ok(socket_locker == NULL, "no locker");
 
   /* Pretend everything is enabled and timed */
@@ -1283,17 +1283,14 @@ void test_locker_disabled()
   socket_class_A->m_timed= true;
   update_instruments_derived_flags();
 
-  mutex_locker= psi->get_thread_mutex_locker(&mutex_state, mutex_A1, PSI_MUTEX_LOCK);
+  mutex_locker= psi->start_mutex_wait(&mutex_state, mutex_A1, PSI_MUTEX_LOCK, __FILE__, __LINE__);
   ok(mutex_locker != NULL, "locker");
-  psi->start_mutex_wait(mutex_locker, __FILE__, __LINE__);
   psi->end_mutex_wait(mutex_locker, 0);
-  rwlock_locker= psi->get_thread_rwlock_locker(&rwlock_state, rwlock_A1, PSI_RWLOCK_READLOCK);
+  rwlock_locker= psi->start_rwlock_rdwait(&rwlock_state, rwlock_A1, PSI_RWLOCK_READLOCK, __FILE__, __LINE__);
   ok(rwlock_locker != NULL, "locker");
-  psi->start_rwlock_rdwait(rwlock_locker, __FILE__, __LINE__);
   psi->end_rwlock_rdwait(rwlock_locker, 0);
-  cond_locker= psi->get_thread_cond_locker(&cond_state, cond_A1, mutex_A1, PSI_COND_WAIT);
+  cond_locker= psi->start_cond_wait(&cond_state, cond_A1, mutex_A1, PSI_COND_WAIT, __FILE__, __LINE__);
   ok(cond_locker != NULL, "locker");
-  psi->start_cond_wait(cond_locker, __FILE__, __LINE__);
   psi->end_cond_wait(cond_locker, 0);
   file_locker= psi->get_thread_file_name_locker(&file_state, file_key_A, PSI_FILE_OPEN, "xxx", NULL);
   ok(file_locker != NULL, "locker");
@@ -1307,9 +1304,8 @@ void test_locker_disabled()
   ok(file_locker != NULL, "locker");
   psi->start_file_wait(file_locker, 10, __FILE__, __LINE__);
   psi->end_file_wait(file_locker, 10);
-  socket_locker= psi->get_thread_socket_locker(&socket_state, socket_A1, PSI_SOCKET_SEND);
+  socket_locker= psi->start_socket_wait(&socket_state, socket_A1, PSI_SOCKET_SEND, 12, "foo.cc", 12);
   ok(socket_locker != NULL, "locker");
-  psi->start_socket_wait(socket_locker, 10, __FILE__, __LINE__);
   psi->end_socket_wait(socket_locker, 10);
 
   /* Pretend the socket does not have a thread owner */
@@ -1319,7 +1315,7 @@ void test_locker_disabled()
   socket_A1= psi->init_socket(socket_key_A, NULL);
   ok(socket_A1 != NULL, "instrumented");
   /* Socket thread owner has not been set */
-  socket_locker= psi->get_thread_socket_locker(&socket_state, socket_A1, PSI_SOCKET_SEND);
+  socket_locker= psi->start_socket_wait(&socket_state, socket_A1, PSI_SOCKET_SEND, 12, "foo.cc", 12);
   ok(socket_locker == NULL, "no locker (no thread owner)");
   
   /* Pretend the running thread is not instrumented */
@@ -1334,11 +1330,11 @@ void test_locker_disabled()
   socket_class_A->m_enabled= true;
   update_instruments_derived_flags();
 
-  mutex_locker= psi->get_thread_mutex_locker(&mutex_state, mutex_A1, PSI_MUTEX_LOCK);
+  mutex_locker= psi->start_mutex_wait(&mutex_state, mutex_A1, PSI_MUTEX_LOCK, "foo.cc", 12);
   ok(mutex_locker == NULL, "no locker");
-  rwlock_locker= psi->get_thread_rwlock_locker(&rwlock_state, rwlock_A1, PSI_RWLOCK_READLOCK);
+  rwlock_locker= psi->start_rwlock_rdwait(&rwlock_state, rwlock_A1, PSI_RWLOCK_READLOCK, "foo.cc", 12);
   ok(rwlock_locker == NULL, "no locker");
-  cond_locker= psi->get_thread_cond_locker(&cond_state, cond_A1, mutex_A1, PSI_COND_WAIT);
+  cond_locker= psi->start_cond_wait(&cond_state, cond_A1, mutex_A1, PSI_COND_WAIT, "foo.cc", 12);
   ok(cond_locker == NULL, "no locker");
   file_locker= psi->get_thread_file_name_locker(&file_state, file_key_A, PSI_FILE_OPEN, "xxx", NULL);
   ok(file_locker == NULL, "no locker");
@@ -1346,7 +1342,7 @@ void test_locker_disabled()
   ok(file_locker == NULL, "no locker");
   file_locker= psi->get_thread_file_descriptor_locker(&file_state, (File) 12, PSI_FILE_READ);
   ok(file_locker == NULL, "no locker");
-  socket_locker= psi->get_thread_socket_locker(&socket_state, socket_A1, PSI_SOCKET_SEND);
+  socket_locker= psi->start_socket_wait(&socket_state, socket_A1, PSI_SOCKET_SEND, 12, "foo.cc", 12);
   ok(socket_locker == NULL, "no locker");
 
   shutdown_performance_schema();

No bundle (reason: useless for push emails).
Thread
bzr push into mysql-trunk-marc branch (marc.alff:3584 to 3585) Marc Alff9 Jan