16 #ifndef MYSQL_THREAD_H
17 #define MYSQL_THREAD_H
74 #elif defined(MY_PTHREAD_FASTMUTEX)
202 #ifndef DISABLE_MYSQL_THREAD_H
210 #define mysql_mutex_assert_owner(M) \
211 safe_mutex_assert_owner(&(M)->m_mutex)
219 #define mysql_mutex_assert_not_owner(M) \
220 safe_mutex_assert_not_owner(&(M)->m_mutex)
224 #define mysql_prlock_assert_write_owner(M) \
225 rw_pr_lock_assert_write_owner(&(M)->m_prlock)
227 #define mysql_prlock_assert_not_write_owner(M) \
228 rw_pr_lock_assert_not_write_owner(&(M)->m_prlock)
234 #define mysql_mutex_register(P1, P2, P3) \
235 inline_mysql_mutex_register(P1, P2, P3)
246 #ifdef HAVE_PSI_MUTEX_INTERFACE
248 #define mysql_mutex_init(K, M, A) \
249 inline_mysql_mutex_init(K, M, A, __FILE__, __LINE__)
251 #define mysql_mutex_init(K, M, A) \
252 inline_mysql_mutex_init(K, M, A)
256 #define mysql_mutex_init(K, M, A) \
257 inline_mysql_mutex_init(M, A, __FILE__, __LINE__)
259 #define mysql_mutex_init(K, M, A) \
260 inline_mysql_mutex_init(M, A)
271 #define mysql_mutex_destroy(M) \
272 inline_mysql_mutex_destroy(M, __FILE__, __LINE__)
274 #define mysql_mutex_destroy(M) \
275 inline_mysql_mutex_destroy(M)
285 #if defined(SAFE_MUTEX) || defined (HAVE_PSI_MUTEX_INTERFACE)
286 #define mysql_mutex_lock(M) \
287 inline_mysql_mutex_lock(M, __FILE__, __LINE__)
289 #define mysql_mutex_lock(M) \
290 inline_mysql_mutex_lock(M)
300 #if defined(SAFE_MUTEX) || defined (HAVE_PSI_MUTEX_INTERFACE)
301 #define mysql_mutex_trylock(M) \
302 inline_mysql_mutex_trylock(M, __FILE__, __LINE__)
304 #define mysql_mutex_trylock(M) \
305 inline_mysql_mutex_trylock(M)
314 #define mysql_mutex_unlock(M) \
315 inline_mysql_mutex_unlock(M, __FILE__, __LINE__)
317 #define mysql_mutex_unlock(M) \
318 inline_mysql_mutex_unlock(M)
325 #define mysql_rwlock_register(P1, P2, P3) \
326 inline_mysql_rwlock_register(P1, P2, P3)
336 #ifdef HAVE_PSI_RWLOCK_INTERFACE
337 #define mysql_rwlock_init(K, RW) inline_mysql_rwlock_init(K, RW)
339 #define mysql_rwlock_init(K, RW) inline_mysql_rwlock_init(RW)
349 #ifdef HAVE_PSI_RWLOCK_INTERFACE
350 #define mysql_prlock_init(K, RW) inline_mysql_prlock_init(K, RW)
352 #define mysql_prlock_init(K, RW) inline_mysql_prlock_init(RW)
361 #define mysql_rwlock_destroy(RW) inline_mysql_rwlock_destroy(RW)
369 #define mysql_prlock_destroy(RW) inline_mysql_prlock_destroy(RW)
377 #ifdef HAVE_PSI_RWLOCK_INTERFACE
378 #define mysql_rwlock_rdlock(RW) \
379 inline_mysql_rwlock_rdlock(RW, __FILE__, __LINE__)
381 #define mysql_rwlock_rdlock(RW) \
382 inline_mysql_rwlock_rdlock(RW)
391 #ifdef HAVE_PSI_RWLOCK_INTERFACE
392 #define mysql_prlock_rdlock(RW) \
393 inline_mysql_prlock_rdlock(RW, __FILE__, __LINE__)
395 #define mysql_prlock_rdlock(RW) \
396 inline_mysql_prlock_rdlock(RW)
405 #ifdef HAVE_PSI_RWLOCK_INTERFACE
406 #define mysql_rwlock_wrlock(RW) \
407 inline_mysql_rwlock_wrlock(RW, __FILE__, __LINE__)
409 #define mysql_rwlock_wrlock(RW) \
410 inline_mysql_rwlock_wrlock(RW)
419 #ifdef HAVE_PSI_RWLOCK_INTERFACE
420 #define mysql_prlock_wrlock(RW) \
421 inline_mysql_prlock_wrlock(RW, __FILE__, __LINE__)
423 #define mysql_prlock_wrlock(RW) \
424 inline_mysql_prlock_wrlock(RW)
433 #ifdef HAVE_PSI_RWLOCK_INTERFACE
434 #define mysql_rwlock_tryrdlock(RW) \
435 inline_mysql_rwlock_tryrdlock(RW, __FILE__, __LINE__)
437 #define mysql_rwlock_tryrdlock(RW) \
438 inline_mysql_rwlock_tryrdlock(RW)
447 #ifdef HAVE_PSI_RWLOCK_INTERFACE
448 #define mysql_rwlock_trywrlock(RW) \
449 inline_mysql_rwlock_trywrlock(RW, __FILE__, __LINE__)
451 #define mysql_rwlock_trywrlock(RW) \
452 inline_mysql_rwlock_trywrlock(RW)
461 #define mysql_rwlock_unlock(RW) inline_mysql_rwlock_unlock(RW)
469 #define mysql_prlock_unlock(RW) inline_mysql_prlock_unlock(RW)
475 #define mysql_cond_register(P1, P2, P3) \
476 inline_mysql_cond_register(P1, P2, P3)
486 #ifdef HAVE_PSI_COND_INTERFACE
487 #define mysql_cond_init(K, C, A) inline_mysql_cond_init(K, C, A)
489 #define mysql_cond_init(K, C, A) inline_mysql_cond_init(C, A)
497 #define mysql_cond_destroy(C) inline_mysql_cond_destroy(C)
504 #ifdef HAVE_PSI_COND_INTERFACE
505 #define mysql_cond_wait(C, M) \
506 inline_mysql_cond_wait(C, M, __FILE__, __LINE__)
508 #define mysql_cond_wait(C, M) \
509 inline_mysql_cond_wait(C, M)
518 #ifdef HAVE_PSI_COND_INTERFACE
519 #define mysql_cond_timedwait(C, M, W) \
520 inline_mysql_cond_timedwait(C, M, W, __FILE__, __LINE__)
522 #define mysql_cond_timedwait(C, M, W) \
523 inline_mysql_cond_timedwait(C, M, W)
531 #define mysql_cond_signal(C) inline_mysql_cond_signal(C)
539 #define mysql_cond_broadcast(C) inline_mysql_cond_broadcast(C)
545 #define mysql_thread_register(P1, P2, P3) \
546 inline_mysql_thread_register(P1, P2, P3)
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)
569 #define mysql_thread_create(K, P1, P2, P3, P4) \
570 pthread_create(P1, P2, P3, P4)
578 #ifdef HAVE_PSI_THREAD_INTERFACE
579 #define mysql_thread_set_psi_id(I) inline_mysql_thread_set_psi_id(I)
581 #define mysql_thread_set_psi_id(I) do {} while (0)
584 static inline void inline_mysql_mutex_register(
585 #ifdef HAVE_PSI_MUTEX_INTERFACE
586 const char *category,
587 PSI_mutex_info *info,
590 const char *category __attribute__ ((unused)),
591 void *info __attribute__ ((unused)),
592 int count __attribute__ ((unused))
596 #ifdef HAVE_PSI_MUTEX_INTERFACE
597 PSI_MUTEX_CALL(register_mutex)(category, info, count);
601 static inline int inline_mysql_mutex_init(
602 #ifdef HAVE_PSI_MUTEX_INTERFACE
606 const pthread_mutexattr_t *attr
608 ,
const char *src_file, uint src_line
612 #ifdef HAVE_PSI_MUTEX_INTERFACE
613 that->m_psi= PSI_MUTEX_CALL(init_mutex)(key, &that->m_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);
622 return pthread_mutex_init(&that->m_mutex, attr);
626 static inline int inline_mysql_mutex_destroy(
629 ,
const char *src_file, uint src_line
633 #ifdef HAVE_PSI_MUTEX_INTERFACE
634 if (that->m_psi != NULL)
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);
645 return pthread_mutex_destroy(&that->m_mutex);
649 static inline int inline_mysql_mutex_lock(
651 #
if defined(SAFE_MUTEX) || defined (HAVE_PSI_MUTEX_INTERFACE)
652 ,
const char *src_file, uint src_line
658 #ifdef HAVE_PSI_MUTEX_INTERFACE
659 if (that->m_psi != NULL)
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);
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);
673 result= pthread_mutex_lock(&that->m_mutex);
678 PSI_MUTEX_CALL(end_mutex_wait)(locker, result);
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);
690 result= pthread_mutex_lock(&that->m_mutex);
696 static inline int inline_mysql_mutex_trylock(
698 #
if defined(SAFE_MUTEX) || defined (HAVE_PSI_MUTEX_INTERFACE)
699 ,
const char *src_file, uint src_line
705 #ifdef HAVE_PSI_MUTEX_INTERFACE
706 if (that->m_psi != NULL)
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);
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);
720 result= pthread_mutex_trylock(&that->m_mutex);
725 PSI_MUTEX_CALL(end_mutex_wait)(locker, result);
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);
737 result= pthread_mutex_trylock(&that->m_mutex);
743 static inline int inline_mysql_mutex_unlock(
746 ,
const char *src_file, uint src_line
752 #ifdef HAVE_PSI_MUTEX_INTERFACE
753 if (that->m_psi != NULL)
754 PSI_MUTEX_CALL(unlock_mutex)(that->m_psi);
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);
762 result= pthread_mutex_unlock(&that->m_mutex);
768 static inline void inline_mysql_rwlock_register(
769 #ifdef HAVE_PSI_RWLOCK_INTERFACE
770 const char *category,
771 PSI_rwlock_info *info,
774 const char *category __attribute__ ((unused)),
775 void *info __attribute__ ((unused)),
776 int count __attribute__ ((unused))
780 #ifdef HAVE_PSI_RWLOCK_INTERFACE
781 PSI_RWLOCK_CALL(register_rwlock)(category, info, count);
785 static inline int inline_mysql_rwlock_init(
786 #ifdef HAVE_PSI_RWLOCK_INTERFACE
791 #ifdef HAVE_PSI_RWLOCK_INTERFACE
792 that->m_psi= PSI_RWLOCK_CALL(init_rwlock)(key, &that->m_rwlock);
799 return my_rwlock_init(&that->m_rwlock, NULL);
802 #ifndef DISABLE_MYSQL_PRLOCK_H
803 static inline int inline_mysql_prlock_init(
804 #ifdef HAVE_PSI_RWLOCK_INTERFACE
809 #ifdef HAVE_PSI_RWLOCK_INTERFACE
810 that->m_psi= PSI_RWLOCK_CALL(init_rwlock)(key, &that->m_prlock);
814 return rw_pr_init(&that->m_prlock);
818 static inline int inline_mysql_rwlock_destroy(
821 #ifdef HAVE_PSI_RWLOCK_INTERFACE
822 if (that->
m_psi != NULL)
828 return rwlock_destroy(&that->
m_rwlock);
831 #ifndef DISABLE_MYSQL_PRLOCK_H
832 static inline int inline_mysql_prlock_destroy(
835 #ifdef HAVE_PSI_RWLOCK_INTERFACE
836 if (that->
m_psi != NULL)
842 return rw_pr_destroy(&that->
m_prlock);
846 static inline int inline_mysql_rwlock_rdlock(
848 #ifdef HAVE_PSI_RWLOCK_INTERFACE
849 ,
const char *src_file, uint src_line
855 #ifdef HAVE_PSI_RWLOCK_INTERFACE
856 if (that->
m_psi != NULL)
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);
865 result= rw_rdlock(&that->m_rwlock);
869 PSI_RWLOCK_CALL(end_rwlock_rdwait)(locker, result);
876 result= rw_rdlock(&that->m_rwlock);
881 #ifndef DISABLE_MYSQL_PRLOCK_H
882 static inline int inline_mysql_prlock_rdlock(
884 #ifdef HAVE_PSI_RWLOCK_INTERFACE
885 ,
const char *src_file, uint src_line
891 #ifdef HAVE_PSI_RWLOCK_INTERFACE
892 if (that->
m_psi != NULL)
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);
901 result= rw_pr_rdlock(&that->
m_prlock);
905 PSI_RWLOCK_CALL(end_rwlock_rdwait)(locker, result);
912 result= rw_pr_rdlock(&that->
m_prlock);
918 static inline int inline_mysql_rwlock_wrlock(
920 #ifdef HAVE_PSI_RWLOCK_INTERFACE
921 ,
const char *src_file, uint src_line
927 #ifdef HAVE_PSI_RWLOCK_INTERFACE
928 if (that->
m_psi != NULL)
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);
937 result= rw_wrlock(&that->m_rwlock);
941 PSI_RWLOCK_CALL(end_rwlock_wrwait)(locker, result);
948 result= rw_wrlock(&that->m_rwlock);
953 #ifndef DISABLE_MYSQL_PRLOCK_H
954 static inline int inline_mysql_prlock_wrlock(
956 #ifdef HAVE_PSI_RWLOCK_INTERFACE
957 ,
const char *src_file, uint src_line
963 #ifdef HAVE_PSI_RWLOCK_INTERFACE
964 if (that->
m_psi != NULL)
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);
973 result= rw_pr_wrlock(&that->
m_prlock);
977 PSI_RWLOCK_CALL(end_rwlock_wrwait)(locker, result);
984 result= rw_pr_wrlock(&that->
m_prlock);
990 static inline int inline_mysql_rwlock_tryrdlock(
992 #ifdef HAVE_PSI_RWLOCK_INTERFACE
993 ,
const char *src_file, uint src_line
999 #ifdef HAVE_PSI_RWLOCK_INTERFACE
1000 if (that->
m_psi != NULL)
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);
1009 result= rw_tryrdlock(&that->m_rwlock);
1013 PSI_RWLOCK_CALL(end_rwlock_rdwait)(locker, result);
1020 result= rw_tryrdlock(&that->m_rwlock);
1025 static inline int inline_mysql_rwlock_trywrlock(
1027 #ifdef HAVE_PSI_RWLOCK_INTERFACE
1028 ,
const char *src_file, uint src_line
1034 #ifdef HAVE_PSI_RWLOCK_INTERFACE
1035 if (that->
m_psi != NULL)
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);
1044 result= rw_trywrlock(&that->m_rwlock);
1048 PSI_RWLOCK_CALL(end_rwlock_wrwait)(locker, result);
1055 result= rw_trywrlock(&that->m_rwlock);
1060 static inline int inline_mysql_rwlock_unlock(
1064 #ifdef HAVE_PSI_RWLOCK_INTERFACE
1065 if (that->
m_psi != NULL)
1066 PSI_RWLOCK_CALL(unlock_rwlock)(that->
m_psi);
1068 result= rw_unlock(&that->
m_rwlock);
1072 #ifndef DISABLE_MYSQL_PRLOCK_H
1073 static inline int inline_mysql_prlock_unlock(
1077 #ifdef HAVE_PSI_RWLOCK_INTERFACE
1078 if (that->
m_psi != NULL)
1079 PSI_RWLOCK_CALL(unlock_rwlock)(that->
m_psi);
1081 result= rw_pr_unlock(&that->
m_prlock);
1086 static inline void inline_mysql_cond_register(
1087 #ifdef HAVE_PSI_COND_INTERFACE
1088 const char *category,
1089 PSI_cond_info *info,
1092 const char *category __attribute__ ((unused)),
1093 void *info __attribute__ ((unused)),
1094 int count __attribute__ ((unused))
1098 #ifdef HAVE_PSI_COND_INTERFACE
1099 PSI_COND_CALL(register_cond)(category, info, count);
1103 static inline int inline_mysql_cond_init(
1104 #ifdef HAVE_PSI_COND_INTERFACE
1108 const pthread_condattr_t *attr)
1110 #ifdef HAVE_PSI_COND_INTERFACE
1111 that->m_psi= PSI_COND_CALL(init_cond)(key, &that->m_cond);
1115 return pthread_cond_init(&that->m_cond, attr);
1118 static inline int inline_mysql_cond_destroy(
1121 #ifdef HAVE_PSI_COND_INTERFACE
1122 if (that->
m_psi != NULL)
1128 return pthread_cond_destroy(&that->
m_cond);
1131 static inline int inline_mysql_cond_wait(
1134 #ifdef HAVE_PSI_COND_INTERFACE
1135 ,
const char *src_file, uint src_line
1141 #ifdef HAVE_PSI_COND_INTERFACE
1142 if (that->
m_psi != NULL)
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);
1151 result= my_cond_wait(&that->
m_cond, &mutex->m_mutex);
1155 PSI_COND_CALL(end_cond_wait)(locker, result);
1162 result= my_cond_wait(&that->
m_cond, &mutex->m_mutex);
1167 static inline int inline_mysql_cond_timedwait(
1171 #ifdef HAVE_PSI_COND_INTERFACE
1172 ,
const char *src_file, uint src_line
1178 #ifdef HAVE_PSI_COND_INTERFACE
1179 if (that->
m_psi != NULL)
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);
1188 result= my_cond_timedwait(&that->
m_cond, &mutex->
m_mutex, abstime);
1192 PSI_COND_CALL(end_cond_wait)(locker, result);
1199 result= my_cond_timedwait(&that->
m_cond, &mutex->
m_mutex, abstime);
1204 static inline int inline_mysql_cond_signal(
1208 #ifdef HAVE_PSI_COND_INTERFACE
1209 if (that->
m_psi != NULL)
1210 PSI_COND_CALL(signal_cond)(that->
m_psi);
1212 result= pthread_cond_signal(&that->
m_cond);
1216 static inline int inline_mysql_cond_broadcast(
1220 #ifdef HAVE_PSI_COND_INTERFACE
1221 if (that->
m_psi != NULL)
1222 PSI_COND_CALL(broadcast_cond)(that->
m_psi);
1224 result= pthread_cond_broadcast(&that->
m_cond);
1228 static inline void inline_mysql_thread_register(
1229 #ifdef HAVE_PSI_THREAD_INTERFACE
1230 const char *category,
1231 PSI_thread_info *info,
1234 const char *category __attribute__ ((unused)),
1235 void *info __attribute__ ((unused)),
1236 int count __attribute__ ((unused))
1240 #ifdef HAVE_PSI_THREAD_INTERFACE
1241 PSI_THREAD_CALL(register_thread)(category, info, count);
1245 #ifdef HAVE_PSI_THREAD_INTERFACE
1246 static inline int inline_mysql_thread_create(
1248 pthread_t *thread,
const pthread_attr_t *attr,
1249 void *(*start_routine)(
void*),
void *arg)
1252 result= PSI_THREAD_CALL(spawn_thread)(key, thread, attr, start_routine, arg);
1256 static inline void inline_mysql_thread_set_psi_id(ulong
id)
1258 struct PSI_thread *psi= PSI_THREAD_CALL(get_thread)();
1259 PSI_THREAD_CALL(set_thread_id)(psi,
id);