List:Commits« Previous MessageNext Message »
From:Marc Alff Date:January 6 2012 9:04am
Subject:bzr push into mysql-trunk branch (marc.alff:3708 to 3709)
View as plain text  
 3709 Marc Alff	2012-01-06
      Bug 12346211 - PERF IMPACT OF PERFORMANCE-SCHEMA WITH DISABLED INSTRUMENTS/CONSUMERS
      
      Manual port of mysql-trunk-pfs-tuning --> mysql-trunk.
      
      This fix contains all the performance optimizations implemented so far,
      for the performance schema instrumentation.
      - simplified the instrumentation interface (merged the get_locker and start_wait APIs)
      - performed the "if (that->m_psi != NULL)" test in the upper layers, to shorten code paths
      - revised the table io and table lock instrumentation to be less intrusive,
        when using the open table cache (unbind, rebind)
      - misc cleanup

    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
      mysys/psi_noop.c
      sql/handler.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
 3708 Bjorn Munch	2012-01-06 [merge]
      null upmerge

=== modified file 'include/mysql/psi/mysql_socket.h'
--- a/include/mysql/psi/mysql_socket.h	2011-11-08 04:28:05 +0000
+++ b/include/mysql/psi/mysql_socket.h	2012-01-06 09:03:53 +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	2012-01-04 18:29:43 +0000
+++ b/include/mysql/psi/psi.h	2012-01-06 09:03:53 +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
 {
@@ -1163,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.
@@ -1291,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
@@ -1385,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
 */
@@ -1431,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.
@@ -1449,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.
@@ -1465,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.
@@ -1481,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.
@@ -1498,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.
@@ -1513,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.
@@ -1775,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);
 
 /**
@@ -1901,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	2012-01-04 18:29:43 +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;
@@ -287,8 +313,8 @@ typedef struct PSI_table* (*open_table_v
   (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 'mysys/psi_noop.c'
--- a/mysys/psi_noop.c	2012-01-05 18:57:16 +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))
@@ -176,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)
@@ -269,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,
@@ -337,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;
@@ -377,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)
@@ -389,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)
@@ -401,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)
@@ -413,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)
@@ -424,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)
@@ -436,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)
@@ -618,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,
@@ -691,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 17:57:53 +0000
+++ b/sql/handler.cc	2012-01-06 09:03:53 +0000
@@ -2177,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
 }
 
@@ -2284,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;
 }
 
@@ -2298,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;
 }
 
@@ -2314,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;
 }
 
@@ -2331,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;
 }
 
@@ -2345,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;
 }
 
@@ -2359,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;
 }
 
@@ -2373,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;
 }
 
@@ -2387,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;
 }
 
@@ -2401,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;
 }
 
@@ -2416,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;
 }
 
@@ -2430,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;
 }
 
@@ -5952,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
@@ -5989,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)
   {
@@ -6068,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);
@@ -6096,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]
@@ -6107,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;
@@ -6127,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 '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	2012-01-04 18:29:43 +0000
+++ b/storage/perfschema/pfs.cc	2012-01-06 09:03:53 +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);
 }
@@ -1561,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;
@@ -1587,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);
 }
 
 /**
@@ -1621,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);
 }
@@ -2043,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)
   {
@@ -2075,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;
 
@@ -2095,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;
     }
@@ -2131,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)
   {
@@ -2163,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;
 
@@ -2183,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;
     }
@@ -2219,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:
@@ -2241,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)
   {
@@ -2268,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;
 
@@ -2288,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
     {
       /*
@@ -2366,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)
@@ -2393,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)
   {
@@ -2402,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;
 
@@ -2423,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++;
@@ -2434,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 */
   }
@@ -2444,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
@@ -2462,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)
@@ -2512,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)
   {
@@ -2521,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;
 
@@ -2542,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++;
@@ -2553,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 */
   }
@@ -2563,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
@@ -2623,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;
 
@@ -2649,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;
@@ -2695,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;
 
@@ -2721,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
@@ -2796,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;
 
@@ -2822,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
@@ -2848,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)
   {
@@ -2887,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;
 
@@ -2907,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;
@@ -2915,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
@@ -2967,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,
@@ -3011,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;
 
@@ -3028,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;
@@ -3099,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++;
 }
@@ -3113,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++;
 }
@@ -3156,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;
 
@@ -3185,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
@@ -3250,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;
 
@@ -3349,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)
   {
@@ -3454,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)
@@ -3552,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;
 
@@ -3643,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;
 
@@ -3745,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;
@@ -3753,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;
 
@@ -3825,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;
@@ -4025,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--;
     }
   }
 
@@ -4679,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.
@@ -4728,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);
 
@@ -4760,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;
@@ -4802,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);
@@ -4825,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)
@@ -4853,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);
 }
 
@@ -4903,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,
@@ -4920,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 branch (marc.alff:3708 to 3709) Marc Alff9 Jan