MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
mysql_thread.h
Go to the documentation of this file.
1 /* Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.
2 
3  This program is free software; you can redistribute it and/or modify
4  it under the terms of the GNU General Public License as published by
5  the Free Software Foundation; version 2 of the License.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  GNU General Public License for more details.
11 
12  You should have received a copy of the GNU General Public License
13  along with this program; if not, write to the Free Software Foundation,
14  51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
15 
16 #ifndef MYSQL_THREAD_H
17 #define MYSQL_THREAD_H
18 
36 /*
37  Note: there are several orthogonal dimensions here.
38 
39  Dimension 1: Instrumentation
40  HAVE_PSI_INTERFACE is defined when the instrumentation is compiled in.
41  This may happen both in debug or production builds.
42 
43  Dimension 2: Debug
44  SAFE_MUTEX is defined when debug is compiled in.
45  This may happen both with and without instrumentation.
46 
47  Dimension 3: Platform
48  Mutexes are implemented with one of:
49  - the pthread library
50  - fast mutexes
51  - window apis
52  This is implemented by various macro definitions in my_pthread.h
53 
54  This causes complexity with '#ifdef'-ery that can't be avoided.
55 */
56 
57 #include "mysql/psi/psi.h"
58 
70 {
72 #ifdef SAFE_MUTEX
74 #elif defined(MY_PTHREAD_FASTMUTEX)
75  my_pthread_fastmutex_t m_mutex;
76 #else
77  pthread_mutex_t m_mutex;
78 #endif
79 
84  struct PSI_mutex *m_psi;
85 };
86 
98 
104 {
112  struct PSI_rwlock *m_psi;
113 };
114 
120 {
128  struct PSI_rwlock *m_psi;
129 };
130 
143 
155 
161 {
163  pthread_cond_t m_cond;
169  struct PSI_cond *m_psi;
170 };
171 
183 
184 /*
185  Consider the following code:
186  static inline void foo() { bar(); }
187  when foo() is never called.
188 
189  With gcc, foo() is a local static function, so the dependencies
190  are optimized away at compile time, and there is no dependency on bar().
191  With other compilers (HP, Sun Studio), the function foo() implementation
192  is compiled, and bar() needs to be present to link.
193 
194  Due to the existing header dependencies in MySQL code, this header file
195  is sometime used when it is not needed, which in turn cause link failures
196  on some platforms.
197  The proper fix would be to cut these extra dependencies in the calling code.
198  DISABLE_MYSQL_THREAD_H is a work around to limit dependencies.
199  DISABLE_MYSQL_PRLOCK_H is similar, and is used to disable specifically
200  the prlock wrappers.
201 */
202 #ifndef DISABLE_MYSQL_THREAD_H
203 
210 #define mysql_mutex_assert_owner(M) \
211  safe_mutex_assert_owner(&(M)->m_mutex)
212 
219 #define mysql_mutex_assert_not_owner(M) \
220  safe_mutex_assert_not_owner(&(M)->m_mutex)
221 
224 #define mysql_prlock_assert_write_owner(M) \
225  rw_pr_lock_assert_write_owner(&(M)->m_prlock)
226 
227 #define mysql_prlock_assert_not_write_owner(M) \
228  rw_pr_lock_assert_not_write_owner(&(M)->m_prlock)
229 
234 #define mysql_mutex_register(P1, P2, P3) \
235  inline_mysql_mutex_register(P1, P2, P3)
236 
246 #ifdef HAVE_PSI_MUTEX_INTERFACE
247  #ifdef SAFE_MUTEX
248  #define mysql_mutex_init(K, M, A) \
249  inline_mysql_mutex_init(K, M, A, __FILE__, __LINE__)
250  #else
251  #define mysql_mutex_init(K, M, A) \
252  inline_mysql_mutex_init(K, M, A)
253  #endif
254 #else
255  #ifdef SAFE_MUTEX
256  #define mysql_mutex_init(K, M, A) \
257  inline_mysql_mutex_init(M, A, __FILE__, __LINE__)
258  #else
259  #define mysql_mutex_init(K, M, A) \
260  inline_mysql_mutex_init(M, A)
261  #endif
262 #endif
263 
270 #ifdef SAFE_MUTEX
271  #define mysql_mutex_destroy(M) \
272  inline_mysql_mutex_destroy(M, __FILE__, __LINE__)
273 #else
274  #define mysql_mutex_destroy(M) \
275  inline_mysql_mutex_destroy(M)
276 #endif
277 
285 #if defined(SAFE_MUTEX) || defined (HAVE_PSI_MUTEX_INTERFACE)
286  #define mysql_mutex_lock(M) \
287  inline_mysql_mutex_lock(M, __FILE__, __LINE__)
288 #else
289  #define mysql_mutex_lock(M) \
290  inline_mysql_mutex_lock(M)
291 #endif
292 
300 #if defined(SAFE_MUTEX) || defined (HAVE_PSI_MUTEX_INTERFACE)
301  #define mysql_mutex_trylock(M) \
302  inline_mysql_mutex_trylock(M, __FILE__, __LINE__)
303 #else
304  #define mysql_mutex_trylock(M) \
305  inline_mysql_mutex_trylock(M)
306 #endif
307 
313 #ifdef SAFE_MUTEX
314  #define mysql_mutex_unlock(M) \
315  inline_mysql_mutex_unlock(M, __FILE__, __LINE__)
316 #else
317  #define mysql_mutex_unlock(M) \
318  inline_mysql_mutex_unlock(M)
319 #endif
320 
325 #define mysql_rwlock_register(P1, P2, P3) \
326  inline_mysql_rwlock_register(P1, P2, P3)
327 
336 #ifdef HAVE_PSI_RWLOCK_INTERFACE
337  #define mysql_rwlock_init(K, RW) inline_mysql_rwlock_init(K, RW)
338 #else
339  #define mysql_rwlock_init(K, RW) inline_mysql_rwlock_init(RW)
340 #endif
341 
349 #ifdef HAVE_PSI_RWLOCK_INTERFACE
350  #define mysql_prlock_init(K, RW) inline_mysql_prlock_init(K, RW)
351 #else
352  #define mysql_prlock_init(K, RW) inline_mysql_prlock_init(RW)
353 #endif
354 
361 #define mysql_rwlock_destroy(RW) inline_mysql_rwlock_destroy(RW)
362 
369 #define mysql_prlock_destroy(RW) inline_mysql_prlock_destroy(RW)
370 
377 #ifdef HAVE_PSI_RWLOCK_INTERFACE
378  #define mysql_rwlock_rdlock(RW) \
379  inline_mysql_rwlock_rdlock(RW, __FILE__, __LINE__)
380 #else
381  #define mysql_rwlock_rdlock(RW) \
382  inline_mysql_rwlock_rdlock(RW)
383 #endif
384 
391 #ifdef HAVE_PSI_RWLOCK_INTERFACE
392  #define mysql_prlock_rdlock(RW) \
393  inline_mysql_prlock_rdlock(RW, __FILE__, __LINE__)
394 #else
395  #define mysql_prlock_rdlock(RW) \
396  inline_mysql_prlock_rdlock(RW)
397 #endif
398 
405 #ifdef HAVE_PSI_RWLOCK_INTERFACE
406  #define mysql_rwlock_wrlock(RW) \
407  inline_mysql_rwlock_wrlock(RW, __FILE__, __LINE__)
408 #else
409  #define mysql_rwlock_wrlock(RW) \
410  inline_mysql_rwlock_wrlock(RW)
411 #endif
412 
419 #ifdef HAVE_PSI_RWLOCK_INTERFACE
420  #define mysql_prlock_wrlock(RW) \
421  inline_mysql_prlock_wrlock(RW, __FILE__, __LINE__)
422 #else
423  #define mysql_prlock_wrlock(RW) \
424  inline_mysql_prlock_wrlock(RW)
425 #endif
426 
433 #ifdef HAVE_PSI_RWLOCK_INTERFACE
434  #define mysql_rwlock_tryrdlock(RW) \
435  inline_mysql_rwlock_tryrdlock(RW, __FILE__, __LINE__)
436 #else
437  #define mysql_rwlock_tryrdlock(RW) \
438  inline_mysql_rwlock_tryrdlock(RW)
439 #endif
440 
447 #ifdef HAVE_PSI_RWLOCK_INTERFACE
448  #define mysql_rwlock_trywrlock(RW) \
449  inline_mysql_rwlock_trywrlock(RW, __FILE__, __LINE__)
450 #else
451  #define mysql_rwlock_trywrlock(RW) \
452  inline_mysql_rwlock_trywrlock(RW)
453 #endif
454 
461 #define mysql_rwlock_unlock(RW) inline_mysql_rwlock_unlock(RW)
462 
469 #define mysql_prlock_unlock(RW) inline_mysql_prlock_unlock(RW)
470 
475 #define mysql_cond_register(P1, P2, P3) \
476  inline_mysql_cond_register(P1, P2, P3)
477 
486 #ifdef HAVE_PSI_COND_INTERFACE
487  #define mysql_cond_init(K, C, A) inline_mysql_cond_init(K, C, A)
488 #else
489  #define mysql_cond_init(K, C, A) inline_mysql_cond_init(C, A)
490 #endif
491 
497 #define mysql_cond_destroy(C) inline_mysql_cond_destroy(C)
498 
504 #ifdef HAVE_PSI_COND_INTERFACE
505  #define mysql_cond_wait(C, M) \
506  inline_mysql_cond_wait(C, M, __FILE__, __LINE__)
507 #else
508  #define mysql_cond_wait(C, M) \
509  inline_mysql_cond_wait(C, M)
510 #endif
511 
518 #ifdef HAVE_PSI_COND_INTERFACE
519  #define mysql_cond_timedwait(C, M, W) \
520  inline_mysql_cond_timedwait(C, M, W, __FILE__, __LINE__)
521 #else
522  #define mysql_cond_timedwait(C, M, W) \
523  inline_mysql_cond_timedwait(C, M, W)
524 #endif
525 
531 #define mysql_cond_signal(C) inline_mysql_cond_signal(C)
532 
539 #define mysql_cond_broadcast(C) inline_mysql_cond_broadcast(C)
540 
545 #define mysql_thread_register(P1, P2, P3) \
546  inline_mysql_thread_register(P1, P2, P3)
547 
565 #ifdef HAVE_PSI_THREAD_INTERFACE
566  #define mysql_thread_create(K, P1, P2, P3, P4) \
567  inline_mysql_thread_create(K, P1, P2, P3, P4)
568 #else
569  #define mysql_thread_create(K, P1, P2, P3, P4) \
570  pthread_create(P1, P2, P3, P4)
571 #endif
572 
578 #ifdef HAVE_PSI_THREAD_INTERFACE
579  #define mysql_thread_set_psi_id(I) inline_mysql_thread_set_psi_id(I)
580 #else
581  #define mysql_thread_set_psi_id(I) do {} while (0)
582 #endif
583 
584 static inline void inline_mysql_mutex_register(
585 #ifdef HAVE_PSI_MUTEX_INTERFACE
586  const char *category,
587  PSI_mutex_info *info,
588  int count
589 #else
590  const char *category __attribute__ ((unused)),
591  void *info __attribute__ ((unused)),
592  int count __attribute__ ((unused))
593 #endif
594 )
595 {
596 #ifdef HAVE_PSI_MUTEX_INTERFACE
597  PSI_MUTEX_CALL(register_mutex)(category, info, count);
598 #endif
599 }
600 
601 static inline int inline_mysql_mutex_init(
602 #ifdef HAVE_PSI_MUTEX_INTERFACE
603  PSI_mutex_key key,
604 #endif
605  mysql_mutex_t *that,
606  const pthread_mutexattr_t *attr
607 #ifdef SAFE_MUTEX
608  , const char *src_file, uint src_line
609 #endif
610  )
611 {
612 #ifdef HAVE_PSI_MUTEX_INTERFACE
613  that->m_psi= PSI_MUTEX_CALL(init_mutex)(key, &that->m_mutex);
614 #else
615  that->m_psi= NULL;
616 #endif
617 #ifdef SAFE_MUTEX
618  return safe_mutex_init(&that->m_mutex, attr, src_file, src_line);
619 #elif defined(MY_PTHREAD_FASTMUTEX)
620  return my_pthread_fastmutex_init(&that->m_mutex, attr);
621 #else
622  return pthread_mutex_init(&that->m_mutex, attr);
623 #endif
624 }
625 
626 static inline int inline_mysql_mutex_destroy(
627  mysql_mutex_t *that
628 #ifdef SAFE_MUTEX
629  , const char *src_file, uint src_line
630 #endif
631  )
632 {
633 #ifdef HAVE_PSI_MUTEX_INTERFACE
634  if (that->m_psi != NULL)
635  {
636  PSI_MUTEX_CALL(destroy_mutex)(that->m_psi);
637  that->m_psi= NULL;
638  }
639 #endif
640 #ifdef SAFE_MUTEX
641  return safe_mutex_destroy(&that->m_mutex, src_file, src_line);
642 #elif defined(MY_PTHREAD_FASTMUTEX)
643  return pthread_mutex_destroy(&that->m_mutex.mutex);
644 #else
645  return pthread_mutex_destroy(&that->m_mutex);
646 #endif
647 }
648 
649 static inline int inline_mysql_mutex_lock(
650  mysql_mutex_t *that
651 #if defined(SAFE_MUTEX) || defined (HAVE_PSI_MUTEX_INTERFACE)
652  , const char *src_file, uint src_line
653 #endif
654  )
655 {
656  int result;
657 
658 #ifdef HAVE_PSI_MUTEX_INTERFACE
659  if (that->m_psi != NULL)
660  {
661  /* Instrumentation start */
662  PSI_mutex_locker *locker;
663  PSI_mutex_locker_state state;
664  locker= PSI_MUTEX_CALL(start_mutex_wait)(&state, that->m_psi,
665  PSI_MUTEX_LOCK, src_file, src_line);
666 
667  /* Instrumented code */
668 #ifdef SAFE_MUTEX
669  result= safe_mutex_lock(&that->m_mutex, FALSE, src_file, src_line);
670 #elif defined(MY_PTHREAD_FASTMUTEX)
671  result= my_pthread_fastmutex_lock(&that->m_mutex);
672 #else
673  result= pthread_mutex_lock(&that->m_mutex);
674 #endif
675 
676  /* Instrumentation end */
677  if (locker != NULL)
678  PSI_MUTEX_CALL(end_mutex_wait)(locker, result);
679 
680  return result;
681  }
682 #endif
683 
684  /* Non instrumented code */
685 #ifdef SAFE_MUTEX
686  result= safe_mutex_lock(&that->m_mutex, FALSE, src_file, src_line);
687 #elif defined(MY_PTHREAD_FASTMUTEX)
688  result= my_pthread_fastmutex_lock(&that->m_mutex);
689 #else
690  result= pthread_mutex_lock(&that->m_mutex);
691 #endif
692 
693  return result;
694 }
695 
696 static inline int inline_mysql_mutex_trylock(
697  mysql_mutex_t *that
698 #if defined(SAFE_MUTEX) || defined (HAVE_PSI_MUTEX_INTERFACE)
699  , const char *src_file, uint src_line
700 #endif
701  )
702 {
703  int result;
704 
705 #ifdef HAVE_PSI_MUTEX_INTERFACE
706  if (that->m_psi != NULL)
707  {
708  /* Instrumentation start */
709  PSI_mutex_locker *locker;
710  PSI_mutex_locker_state state;
711  locker= PSI_MUTEX_CALL(start_mutex_wait)(&state, that->m_psi,
712  PSI_MUTEX_TRYLOCK, src_file, src_line);
713 
714  /* Instrumented code */
715 #ifdef SAFE_MUTEX
716  result= safe_mutex_lock(&that->m_mutex, TRUE, src_file, src_line);
717 #elif defined(MY_PTHREAD_FASTMUTEX)
718  result= pthread_mutex_trylock(&that->m_mutex.mutex);
719 #else
720  result= pthread_mutex_trylock(&that->m_mutex);
721 #endif
722 
723  /* Instrumentation end */
724  if (locker != NULL)
725  PSI_MUTEX_CALL(end_mutex_wait)(locker, result);
726 
727  return result;
728  }
729 #endif
730 
731  /* Non instrumented code */
732 #ifdef SAFE_MUTEX
733  result= safe_mutex_lock(&that->m_mutex, TRUE, src_file, src_line);
734 #elif defined(MY_PTHREAD_FASTMUTEX)
735  result= pthread_mutex_trylock(&that->m_mutex.mutex);
736 #else
737  result= pthread_mutex_trylock(&that->m_mutex);
738 #endif
739 
740  return result;
741 }
742 
743 static inline int inline_mysql_mutex_unlock(
744  mysql_mutex_t *that
745 #ifdef SAFE_MUTEX
746  , const char *src_file, uint src_line
747 #endif
748  )
749 {
750  int result;
751 
752 #ifdef HAVE_PSI_MUTEX_INTERFACE
753  if (that->m_psi != NULL)
754  PSI_MUTEX_CALL(unlock_mutex)(that->m_psi);
755 #endif
756 
757 #ifdef SAFE_MUTEX
758  result= safe_mutex_unlock(&that->m_mutex, src_file, src_line);
759 #elif defined(MY_PTHREAD_FASTMUTEX)
760  result= pthread_mutex_unlock(&that->m_mutex.mutex);
761 #else
762  result= pthread_mutex_unlock(&that->m_mutex);
763 #endif
764 
765  return result;
766 }
767 
768 static inline void inline_mysql_rwlock_register(
769 #ifdef HAVE_PSI_RWLOCK_INTERFACE
770  const char *category,
771  PSI_rwlock_info *info,
772  int count
773 #else
774  const char *category __attribute__ ((unused)),
775  void *info __attribute__ ((unused)),
776  int count __attribute__ ((unused))
777 #endif
778 )
779 {
780 #ifdef HAVE_PSI_RWLOCK_INTERFACE
781  PSI_RWLOCK_CALL(register_rwlock)(category, info, count);
782 #endif
783 }
784 
785 static inline int inline_mysql_rwlock_init(
786 #ifdef HAVE_PSI_RWLOCK_INTERFACE
787  PSI_rwlock_key key,
788 #endif
789  mysql_rwlock_t *that)
790 {
791 #ifdef HAVE_PSI_RWLOCK_INTERFACE
792  that->m_psi= PSI_RWLOCK_CALL(init_rwlock)(key, &that->m_rwlock);
793 #else
794  that->m_psi= NULL;
795 #endif
796  /*
797  pthread_rwlockattr_t is not used in MySQL.
798  */
799  return my_rwlock_init(&that->m_rwlock, NULL);
800 }
801 
802 #ifndef DISABLE_MYSQL_PRLOCK_H
803 static inline int inline_mysql_prlock_init(
804 #ifdef HAVE_PSI_RWLOCK_INTERFACE
805  PSI_rwlock_key key,
806 #endif
807  mysql_prlock_t *that)
808 {
809 #ifdef HAVE_PSI_RWLOCK_INTERFACE
810  that->m_psi= PSI_RWLOCK_CALL(init_rwlock)(key, &that->m_prlock);
811 #else
812  that->m_psi= NULL;
813 #endif
814  return rw_pr_init(&that->m_prlock);
815 }
816 #endif
817 
818 static inline int inline_mysql_rwlock_destroy(
819  mysql_rwlock_t *that)
820 {
821 #ifdef HAVE_PSI_RWLOCK_INTERFACE
822  if (that->m_psi != NULL)
823  {
824  PSI_RWLOCK_CALL(destroy_rwlock)(that->m_psi);
825  that->m_psi= NULL;
826  }
827 #endif
828  return rwlock_destroy(&that->m_rwlock);
829 }
830 
831 #ifndef DISABLE_MYSQL_PRLOCK_H
832 static inline int inline_mysql_prlock_destroy(
833  mysql_prlock_t *that)
834 {
835 #ifdef HAVE_PSI_RWLOCK_INTERFACE
836  if (that->m_psi != NULL)
837  {
838  PSI_RWLOCK_CALL(destroy_rwlock)(that->m_psi);
839  that->m_psi= NULL;
840  }
841 #endif
842  return rw_pr_destroy(&that->m_prlock);
843 }
844 #endif
845 
846 static inline int inline_mysql_rwlock_rdlock(
847  mysql_rwlock_t *that
848 #ifdef HAVE_PSI_RWLOCK_INTERFACE
849  , const char *src_file, uint src_line
850 #endif
851  )
852 {
853  int result;
854 
855 #ifdef HAVE_PSI_RWLOCK_INTERFACE
856  if (that->m_psi != NULL)
857  {
858  /* Instrumentation start */
859  PSI_rwlock_locker *locker;
860  PSI_rwlock_locker_state state;
861  locker= PSI_RWLOCK_CALL(start_rwlock_rdwait)(&state, that->m_psi,
862  PSI_RWLOCK_READLOCK, src_file, src_line);
863 
864  /* Instrumented code */
865  result= rw_rdlock(&that->m_rwlock);
866 
867  /* Instrumentation end */
868  if (locker != NULL)
869  PSI_RWLOCK_CALL(end_rwlock_rdwait)(locker, result);
870 
871  return result;
872  }
873 #endif
874 
875  /* Non instrumented code */
876  result= rw_rdlock(&that->m_rwlock);
877 
878  return result;
879 }
880 
881 #ifndef DISABLE_MYSQL_PRLOCK_H
882 static inline int inline_mysql_prlock_rdlock(
883  mysql_prlock_t *that
884 #ifdef HAVE_PSI_RWLOCK_INTERFACE
885  , const char *src_file, uint src_line
886 #endif
887  )
888 {
889  int result;
890 
891 #ifdef HAVE_PSI_RWLOCK_INTERFACE
892  if (that->m_psi != NULL)
893  {
894  /* Instrumentation start */
895  PSI_rwlock_locker *locker;
896  PSI_rwlock_locker_state state;
897  locker= PSI_RWLOCK_CALL(start_rwlock_rdwait)(&state, that->m_psi,
898  PSI_RWLOCK_READLOCK, src_file, src_line);
899 
900  /* Instrumented code */
901  result= rw_pr_rdlock(&that->m_prlock);
902 
903  /* Instrumentation end */
904  if (locker != NULL)
905  PSI_RWLOCK_CALL(end_rwlock_rdwait)(locker, result);
906 
907  return result;
908  }
909 #endif
910 
911  /* Non instrumented code */
912  result= rw_pr_rdlock(&that->m_prlock);
913 
914  return result;
915 }
916 #endif
917 
918 static inline int inline_mysql_rwlock_wrlock(
919  mysql_rwlock_t *that
920 #ifdef HAVE_PSI_RWLOCK_INTERFACE
921  , const char *src_file, uint src_line
922 #endif
923  )
924 {
925  int result;
926 
927 #ifdef HAVE_PSI_RWLOCK_INTERFACE
928  if (that->m_psi != NULL)
929  {
930  /* Instrumentation start */
931  PSI_rwlock_locker *locker;
932  PSI_rwlock_locker_state state;
933  locker= PSI_RWLOCK_CALL(start_rwlock_wrwait)(&state, that->m_psi,
934  PSI_RWLOCK_WRITELOCK, src_file, src_line);
935 
936  /* Instrumented code */
937  result= rw_wrlock(&that->m_rwlock);
938 
939  /* Instrumentation end */
940  if (locker != NULL)
941  PSI_RWLOCK_CALL(end_rwlock_wrwait)(locker, result);
942 
943  return result;
944  }
945 #endif
946 
947  /* Non instrumented code */
948  result= rw_wrlock(&that->m_rwlock);
949 
950  return result;
951 }
952 
953 #ifndef DISABLE_MYSQL_PRLOCK_H
954 static inline int inline_mysql_prlock_wrlock(
955  mysql_prlock_t *that
956 #ifdef HAVE_PSI_RWLOCK_INTERFACE
957  , const char *src_file, uint src_line
958 #endif
959  )
960 {
961  int result;
962 
963 #ifdef HAVE_PSI_RWLOCK_INTERFACE
964  if (that->m_psi != NULL)
965  {
966  /* Instrumentation start */
967  PSI_rwlock_locker *locker;
968  PSI_rwlock_locker_state state;
969  locker= PSI_RWLOCK_CALL(start_rwlock_wrwait)(&state, that->m_psi,
970  PSI_RWLOCK_WRITELOCK, src_file, src_line);
971 
972  /* Instrumented code */
973  result= rw_pr_wrlock(&that->m_prlock);
974 
975  /* Instrumentation end */
976  if (locker != NULL)
977  PSI_RWLOCK_CALL(end_rwlock_wrwait)(locker, result);
978 
979  return result;
980  }
981 #endif
982 
983  /* Non instrumented code */
984  result= rw_pr_wrlock(&that->m_prlock);
985 
986  return result;
987 }
988 #endif
989 
990 static inline int inline_mysql_rwlock_tryrdlock(
991  mysql_rwlock_t *that
992 #ifdef HAVE_PSI_RWLOCK_INTERFACE
993  , const char *src_file, uint src_line
994 #endif
995  )
996 {
997  int result;
998 
999 #ifdef HAVE_PSI_RWLOCK_INTERFACE
1000  if (that->m_psi != NULL)
1001  {
1002  /* Instrumentation start */
1003  PSI_rwlock_locker *locker;
1004  PSI_rwlock_locker_state state;
1005  locker= PSI_RWLOCK_CALL(start_rwlock_rdwait)(&state, that->m_psi,
1006  PSI_RWLOCK_TRYREADLOCK, src_file, src_line);
1007 
1008  /* Instrumented code */
1009  result= rw_tryrdlock(&that->m_rwlock);
1010 
1011  /* Instrumentation end */
1012  if (locker != NULL)
1013  PSI_RWLOCK_CALL(end_rwlock_rdwait)(locker, result);
1014 
1015  return result;
1016  }
1017 #endif
1018 
1019  /* Non instrumented code */
1020  result= rw_tryrdlock(&that->m_rwlock);
1021 
1022  return result;
1023 }
1024 
1025 static inline int inline_mysql_rwlock_trywrlock(
1026  mysql_rwlock_t *that
1027 #ifdef HAVE_PSI_RWLOCK_INTERFACE
1028  , const char *src_file, uint src_line
1029 #endif
1030  )
1031 {
1032  int result;
1033 
1034 #ifdef HAVE_PSI_RWLOCK_INTERFACE
1035  if (that->m_psi != NULL)
1036  {
1037  /* Instrumentation start */
1038  PSI_rwlock_locker *locker;
1039  PSI_rwlock_locker_state state;
1040  locker= PSI_RWLOCK_CALL(start_rwlock_wrwait)(&state, that->m_psi,
1041  PSI_RWLOCK_TRYWRITELOCK, src_file, src_line);
1042 
1043  /* Instrumented code */
1044  result= rw_trywrlock(&that->m_rwlock);
1045 
1046  /* Instrumentation end */
1047  if (locker != NULL)
1048  PSI_RWLOCK_CALL(end_rwlock_wrwait)(locker, result);
1049 
1050  return result;
1051  }
1052 #endif
1053 
1054  /* Non instrumented code */
1055  result= rw_trywrlock(&that->m_rwlock);
1056 
1057  return result;
1058 }
1059 
1060 static inline int inline_mysql_rwlock_unlock(
1061  mysql_rwlock_t *that)
1062 {
1063  int result;
1064 #ifdef HAVE_PSI_RWLOCK_INTERFACE
1065  if (that->m_psi != NULL)
1066  PSI_RWLOCK_CALL(unlock_rwlock)(that->m_psi);
1067 #endif
1068  result= rw_unlock(&that->m_rwlock);
1069  return result;
1070 }
1071 
1072 #ifndef DISABLE_MYSQL_PRLOCK_H
1073 static inline int inline_mysql_prlock_unlock(
1074  mysql_prlock_t *that)
1075 {
1076  int result;
1077 #ifdef HAVE_PSI_RWLOCK_INTERFACE
1078  if (that->m_psi != NULL)
1079  PSI_RWLOCK_CALL(unlock_rwlock)(that->m_psi);
1080 #endif
1081  result= rw_pr_unlock(&that->m_prlock);
1082  return result;
1083 }
1084 #endif
1085 
1086 static inline void inline_mysql_cond_register(
1087 #ifdef HAVE_PSI_COND_INTERFACE
1088  const char *category,
1089  PSI_cond_info *info,
1090  int count
1091 #else
1092  const char *category __attribute__ ((unused)),
1093  void *info __attribute__ ((unused)),
1094  int count __attribute__ ((unused))
1095 #endif
1096 )
1097 {
1098 #ifdef HAVE_PSI_COND_INTERFACE
1099  PSI_COND_CALL(register_cond)(category, info, count);
1100 #endif
1101 }
1102 
1103 static inline int inline_mysql_cond_init(
1104 #ifdef HAVE_PSI_COND_INTERFACE
1105  PSI_cond_key key,
1106 #endif
1107  mysql_cond_t *that,
1108  const pthread_condattr_t *attr)
1109 {
1110 #ifdef HAVE_PSI_COND_INTERFACE
1111  that->m_psi= PSI_COND_CALL(init_cond)(key, &that->m_cond);
1112 #else
1113  that->m_psi= NULL;
1114 #endif
1115  return pthread_cond_init(&that->m_cond, attr);
1116 }
1117 
1118 static inline int inline_mysql_cond_destroy(
1119  mysql_cond_t *that)
1120 {
1121 #ifdef HAVE_PSI_COND_INTERFACE
1122  if (that->m_psi != NULL)
1123  {
1124  PSI_COND_CALL(destroy_cond)(that->m_psi);
1125  that->m_psi= NULL;
1126  }
1127 #endif
1128  return pthread_cond_destroy(&that->m_cond);
1129 }
1130 
1131 static inline int inline_mysql_cond_wait(
1132  mysql_cond_t *that,
1133  mysql_mutex_t *mutex
1134 #ifdef HAVE_PSI_COND_INTERFACE
1135  , const char *src_file, uint src_line
1136 #endif
1137  )
1138 {
1139  int result;
1140 
1141 #ifdef HAVE_PSI_COND_INTERFACE
1142  if (that->m_psi != NULL)
1143  {
1144  /* Instrumentation start */
1145  PSI_cond_locker *locker;
1146  PSI_cond_locker_state state;
1147  locker= PSI_COND_CALL(start_cond_wait)(&state, that->m_psi, mutex->m_psi,
1148  PSI_COND_WAIT, src_file, src_line);
1149 
1150  /* Instrumented code */
1151  result= my_cond_wait(&that->m_cond, &mutex->m_mutex);
1152 
1153  /* Instrumentation end */
1154  if (locker != NULL)
1155  PSI_COND_CALL(end_cond_wait)(locker, result);
1156 
1157  return result;
1158  }
1159 #endif
1160 
1161  /* Non instrumented code */
1162  result= my_cond_wait(&that->m_cond, &mutex->m_mutex);
1163 
1164  return result;
1165 }
1166 
1167 static inline int inline_mysql_cond_timedwait(
1168  mysql_cond_t *that,
1169  mysql_mutex_t *mutex,
1170  struct timespec *abstime
1171 #ifdef HAVE_PSI_COND_INTERFACE
1172  , const char *src_file, uint src_line
1173 #endif
1174  )
1175 {
1176  int result;
1177 
1178 #ifdef HAVE_PSI_COND_INTERFACE
1179  if (that->m_psi != NULL)
1180  {
1181  /* Instrumentation start */
1182  PSI_cond_locker *locker;
1183  PSI_cond_locker_state state;
1184  locker= PSI_COND_CALL(start_cond_wait)(&state, that->m_psi, mutex->m_psi,
1185  PSI_COND_TIMEDWAIT, src_file, src_line);
1186 
1187  /* Instrumented code */
1188  result= my_cond_timedwait(&that->m_cond, &mutex->m_mutex, abstime);
1189 
1190  /* Instrumentation end */
1191  if (locker != NULL)
1192  PSI_COND_CALL(end_cond_wait)(locker, result);
1193 
1194  return result;
1195  }
1196 #endif
1197 
1198  /* Non instrumented code */
1199  result= my_cond_timedwait(&that->m_cond, &mutex->m_mutex, abstime);
1200 
1201  return result;
1202 }
1203 
1204 static inline int inline_mysql_cond_signal(
1205  mysql_cond_t *that)
1206 {
1207  int result;
1208 #ifdef HAVE_PSI_COND_INTERFACE
1209  if (that->m_psi != NULL)
1210  PSI_COND_CALL(signal_cond)(that->m_psi);
1211 #endif
1212  result= pthread_cond_signal(&that->m_cond);
1213  return result;
1214 }
1215 
1216 static inline int inline_mysql_cond_broadcast(
1217  mysql_cond_t *that)
1218 {
1219  int result;
1220 #ifdef HAVE_PSI_COND_INTERFACE
1221  if (that->m_psi != NULL)
1222  PSI_COND_CALL(broadcast_cond)(that->m_psi);
1223 #endif
1224  result= pthread_cond_broadcast(&that->m_cond);
1225  return result;
1226 }
1227 
1228 static inline void inline_mysql_thread_register(
1229 #ifdef HAVE_PSI_THREAD_INTERFACE
1230  const char *category,
1231  PSI_thread_info *info,
1232  int count
1233 #else
1234  const char *category __attribute__ ((unused)),
1235  void *info __attribute__ ((unused)),
1236  int count __attribute__ ((unused))
1237 #endif
1238 )
1239 {
1240 #ifdef HAVE_PSI_THREAD_INTERFACE
1241  PSI_THREAD_CALL(register_thread)(category, info, count);
1242 #endif
1243 }
1244 
1245 #ifdef HAVE_PSI_THREAD_INTERFACE
1246 static inline int inline_mysql_thread_create(
1247  PSI_thread_key key,
1248  pthread_t *thread, const pthread_attr_t *attr,
1249  void *(*start_routine)(void*), void *arg)
1250 {
1251  int result;
1252  result= PSI_THREAD_CALL(spawn_thread)(key, thread, attr, start_routine, arg);
1253  return result;
1254 }
1255 
1256 static inline void inline_mysql_thread_set_psi_id(ulong id)
1257 {
1258  struct PSI_thread *psi= PSI_THREAD_CALL(get_thread)();
1259  PSI_THREAD_CALL(set_thread_id)(psi, id);
1260 }
1261 #endif
1262 
1263 #endif /* DISABLE_MYSQL_THREAD_H */
1264 
1267 #endif
1268