1 /* Copyright (c) 2008, 2013, Oracle and/or its affiliates.
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, version 2.0,
5   as published by the Free Software Foundation.
6 
7   This program is also distributed with certain software (including
8   but not limited to OpenSSL) that is licensed under separate terms,
9   as designated in a particular file or component or in included license
10   documentation.  The authors of MySQL hereby grant you an additional
11   permission to link the program and your derivative works with the
12   separately licensed software that they have included with MySQL.
13 
14   This program is distributed in the hope that it will be useful,
15   but WITHOUT ANY WARRANTY; without even the implied warranty of
16   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   GNU General Public License, version 2.0, for more details.
18 
19   You should have received a copy of the GNU General Public License
20   along with this program; if not, write to the Free Software Foundation,
21   51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */
22 
23 #ifndef MYSQL_THREAD_H
24 #define MYSQL_THREAD_H
25 
26 /**
27   @file mysql/psi/mysql_thread.h
28   Instrumentation helpers for mysys threads, mutexes,
29   read write locks and conditions.
30   This header file provides the necessary declarations
31   to use the mysys thread API with the performance schema instrumentation.
32   In some compilers (SunStudio), 'static inline' functions, when declared
33   but not used, are not optimized away (because they are unused) by default,
34   so that including a static inline function from a header file does
35   create unwanted dependencies, causing unresolved symbols at link time.
36   Other compilers, like gcc, optimize these dependencies by default.
37 
38   Since the instrumented APIs declared here are wrapper on top
39   of my_pthread / safemutex / etc APIs,
40   including mysql/psi/mysql_thread.h assumes that
41   the dependency on my_pthread and safemutex already exists.
42 */
43 /*
44   Note: there are several orthogonal dimensions here.
45 
46   Dimension 1: Instrumentation
47   HAVE_PSI_INTERFACE is defined when the instrumentation is compiled in.
48   This may happen both in debug or production builds.
49 
50   Dimension 2: Debug
51   SAFE_MUTEX is defined when debug is compiled in.
52   This may happen both with and without instrumentation.
53 
54   Dimension 3: Platform
55   Mutexes are implemented with one of:
56   - the pthread library
57   - fast mutexes
58   - window apis
59   This is implemented by various macro definitions in my_pthread.h
60 
61   This causes complexity with '#ifdef'-ery that can't be avoided.
62 */
63 
64 #include "mysql/psi/psi.h"
65 
66 /**
67   @defgroup Thread_instrumentation Thread Instrumentation
68   @ingroup Instrumentation_interface
69   @{
70 */
71 
72 #ifdef HAVE_PSI_THREAD_INTERFACE
73 #define PSI_CALL_delete_current_thread    PSI_THREAD_CALL(delete_current_thread)
74 #define PSI_CALL_get_thread               PSI_THREAD_CALL(get_thread)
75 #define PSI_CALL_new_thread               PSI_THREAD_CALL(new_thread)
76 #define PSI_CALL_register_thread          PSI_THREAD_CALL(register_thread)
77 #define PSI_CALL_set_thread               PSI_THREAD_CALL(set_thread)
78 #define PSI_CALL_set_thread_connect_attrs PSI_THREAD_CALL(set_thread_connect_attrs)
79 #define PSI_CALL_set_thread_db            PSI_THREAD_CALL(set_thread_db)
80 #define PSI_CALL_set_thread_id            PSI_THREAD_CALL(set_thread_id)
81 #define PSI_CALL_set_thread_info          PSI_THREAD_CALL(set_thread_info)
82 #define PSI_CALL_set_thread_start_time    PSI_THREAD_CALL(set_thread_start_time)
83 #define PSI_CALL_set_thread_user_host     PSI_THREAD_CALL(set_thread_user_host)
84 #define PSI_CALL_spawn_thread             PSI_THREAD_CALL(spawn_thread)
85 #else
86 #define PSI_CALL_delete_current_thread()                do { } while(0)
87 #define PSI_CALL_get_thread()                           NULL
88 #define PSI_CALL_new_thread(A1,A2,A3)                   NULL
89 #define PSI_CALL_register_thread(A1,A2,A3)              do { } while(0)
90 #define PSI_CALL_set_thread(A1)                         do { } while(0)
91 #define PSI_CALL_set_thread_connect_attrs(A1,A2,A3)     0
92 #define PSI_CALL_set_thread_db(A1,A2)                   do { } while(0)
93 #define PSI_CALL_set_thread_id(A1,A2)                   do { } while(0)
94 #define PSI_CALL_set_thread_info(A1, A2)                do { } while(0)
95 #define PSI_CALL_set_thread_start_time(A1)              do { } while(0)
96 #define PSI_CALL_set_thread_user_host(A1, A2, A3, A4)   do { } while(0)
97 #define PSI_CALL_spawn_thread(A1, A2, A3, A4, A5)       0
98 #endif
99 
100 
101 /**
102   An instrumented mutex structure.
103   @sa mysql_mutex_t
104 */
105 struct st_mysql_mutex
106 {
107   /** The real mutex. */
108 #ifdef SAFE_MUTEX
109   safe_mutex_t m_mutex;
110 #else
111   pthread_mutex_t m_mutex;
112 #endif
113   /**
114     The instrumentation hook.
115     Note that this hook is not conditionally defined,
116     for binary compatibility of the @c mysql_mutex_t interface.
117   */
118   struct PSI_mutex *m_psi;
119 };
120 
121 /**
122   Type of an instrumented mutex.
123   @c mysql_mutex_t is a drop-in replacement for @c pthread_mutex_t.
124   @sa mysql_mutex_assert_owner
125   @sa mysql_mutex_assert_not_owner
126   @sa mysql_mutex_init
127   @sa mysql_mutex_lock
128   @sa mysql_mutex_unlock
129   @sa mysql_mutex_destroy
130 */
131 typedef struct st_mysql_mutex mysql_mutex_t;
132 
133 /**
134   An instrumented rwlock structure.
135   @sa mysql_rwlock_t
136 */
137 struct st_mysql_rwlock
138 {
139   /** The real rwlock */
140   rw_lock_t m_rwlock;
141   /**
142     The instrumentation hook.
143     Note that this hook is not conditionally defined,
144     for binary compatibility of the @c mysql_rwlock_t interface.
145   */
146   struct PSI_rwlock *m_psi;
147 };
148 
149 /**
150   An instrumented prlock structure.
151   @sa mysql_prlock_t
152 */
153 struct st_mysql_prlock
154 {
155   /** The real prlock */
156   rw_pr_lock_t m_prlock;
157   /**
158     The instrumentation hook.
159     Note that this hook is not conditionally defined,
160     for binary compatibility of the @c mysql_rwlock_t interface.
161   */
162   struct PSI_rwlock *m_psi;
163 };
164 
165 /**
166   Type of an instrumented rwlock.
167   @c mysql_rwlock_t is a drop-in replacement for @c pthread_rwlock_t.
168   @sa mysql_rwlock_init
169   @sa mysql_rwlock_rdlock
170   @sa mysql_rwlock_tryrdlock
171   @sa mysql_rwlock_wrlock
172   @sa mysql_rwlock_trywrlock
173   @sa mysql_rwlock_unlock
174   @sa mysql_rwlock_destroy
175 */
176 typedef struct st_mysql_rwlock mysql_rwlock_t;
177 
178 /**
179   Type of an instrumented prlock.
180   A prlock is a read write lock that 'prefers readers' (pr).
181   @c mysql_prlock_t is a drop-in replacement for @c rw_pr_lock_t.
182   @sa mysql_prlock_init
183   @sa mysql_prlock_rdlock
184   @sa mysql_prlock_wrlock
185   @sa mysql_prlock_unlock
186   @sa mysql_prlock_destroy
187 */
188 typedef struct st_mysql_prlock mysql_prlock_t;
189 
190 /**
191   An instrumented cond structure.
192   @sa mysql_cond_t
193 */
194 struct st_mysql_cond
195 {
196   /** The real condition */
197   pthread_cond_t m_cond;
198   /**
199     The instrumentation hook.
200     Note that this hook is not conditionally defined,
201     for binary compatibility of the @c mysql_cond_t interface.
202   */
203   struct PSI_cond *m_psi;
204 };
205 
206 /**
207   Type of an instrumented condition.
208   @c mysql_cond_t is a drop-in replacement for @c pthread_cond_t.
209   @sa mysql_cond_init
210   @sa mysql_cond_wait
211   @sa mysql_cond_timedwait
212   @sa mysql_cond_signal
213   @sa mysql_cond_broadcast
214   @sa mysql_cond_destroy
215 */
216 typedef struct st_mysql_cond mysql_cond_t;
217 
218 /*
219   Consider the following code:
220     static inline void foo() { bar(); }
221   when foo() is never called.
222 
223   With gcc, foo() is a local static function, so the dependencies
224   are optimized away at compile time, and there is no dependency on bar().
225   With other compilers (HP, Sun Studio), the function foo() implementation
226   is compiled, and bar() needs to be present to link.
227 
228   Due to the existing header dependencies in MySQL code, this header file
229   is sometime used when it is not needed, which in turn cause link failures
230   on some platforms.
231   The proper fix would be to cut these extra dependencies in the calling code.
232   DISABLE_MYSQL_THREAD_H is a work around to limit dependencies.
233   DISABLE_MYSQL_PRLOCK_H is similar, and is used to disable specifically
234   the prlock wrappers.
235 */
236 #ifndef DISABLE_MYSQL_THREAD_H
237 
238 /**
239   @def mysql_mutex_assert_owner(M)
240   Wrapper, to use safe_mutex_assert_owner with instrumented mutexes.
241   @c mysql_mutex_assert_owner is a drop-in replacement
242   for @c safe_mutex_assert_owner.
243 */
244 #define mysql_mutex_assert_owner(M) \
245   safe_mutex_assert_owner(&(M)->m_mutex)
246 
247 /**
248   @def mysql_mutex_assert_not_owner(M)
249   Wrapper, to use safe_mutex_assert_not_owner with instrumented mutexes.
250   @c mysql_mutex_assert_not_owner is a drop-in replacement
251   for @c safe_mutex_assert_not_owner.
252 */
253 #define mysql_mutex_assert_not_owner(M) \
254   safe_mutex_assert_not_owner(&(M)->m_mutex)
255 
256 #define mysql_mutex_setflags(M, F) \
257   safe_mutex_setflags(&(M)->m_mutex, (F))
258 
259 /** Wrappers for instrumented prlock objects.  */
260 
261 #define mysql_prlock_assert_write_owner(M) \
262   rw_pr_lock_assert_write_owner(&(M)->m_prlock)
263 
264 #define mysql_prlock_assert_not_write_owner(M) \
265   rw_pr_lock_assert_not_write_owner(&(M)->m_prlock)
266 
267 /**
268   @def mysql_mutex_register(P1, P2, P3)
269   Mutex registration.
270 */
271 #define mysql_mutex_register(P1, P2, P3) \
272   inline_mysql_mutex_register(P1, P2, P3)
273 
274 /**
275   @def mysql_mutex_init(K, M, A)
276   Instrumented mutex_init.
277   @c mysql_mutex_init is a replacement for @c pthread_mutex_init.
278   @param K The PSI_mutex_key for this instrumented mutex
279   @param M The mutex to initialize
280   @param A Mutex attributes
281 */
282 
283 #ifdef HAVE_PSI_MUTEX_INTERFACE
284   #ifdef SAFE_MUTEX
285     #define mysql_mutex_init(K, M, A) \
286       inline_mysql_mutex_init(K, M, A, #M, __FILE__, __LINE__)
287   #else
288     #define mysql_mutex_init(K, M, A) \
289       inline_mysql_mutex_init(K, M, A)
290   #endif
291 #else
292   #ifdef SAFE_MUTEX
293     #define mysql_mutex_init(K, M, A) \
294       inline_mysql_mutex_init(M, A, #M, __FILE__, __LINE__)
295   #else
296     #define mysql_mutex_init(K, M, A) \
297       inline_mysql_mutex_init(M, A)
298   #endif
299 #endif
300 
301 /**
302   @def mysql_mutex_destroy(M)
303   Instrumented mutex_destroy.
304   @c mysql_mutex_destroy is a drop-in replacement
305   for @c pthread_mutex_destroy.
306 */
307 #ifdef SAFE_MUTEX
308   #define mysql_mutex_destroy(M) \
309     inline_mysql_mutex_destroy(M, __FILE__, __LINE__)
310 #else
311   #define mysql_mutex_destroy(M) \
312     inline_mysql_mutex_destroy(M)
313 #endif
314 
315 /**
316   @def mysql_mutex_lock(M)
317   Instrumented mutex_lock.
318   @c mysql_mutex_lock is a drop-in replacement for @c pthread_mutex_lock.
319   @param M The mutex to lock
320 */
321 
322 #if defined(SAFE_MUTEX) || defined (HAVE_PSI_MUTEX_INTERFACE)
323   #define mysql_mutex_lock(M) \
324     inline_mysql_mutex_lock(M, __FILE__, __LINE__)
325 #else
326   #define mysql_mutex_lock(M) \
327     inline_mysql_mutex_lock(M)
328 #endif
329 
330 /**
331   @def mysql_mutex_trylock(M)
332   Instrumented mutex_lock.
333   @c mysql_mutex_trylock is a drop-in replacement
334   for @c pthread_mutex_trylock.
335 */
336 
337 #if defined(SAFE_MUTEX) || defined (HAVE_PSI_MUTEX_INTERFACE)
338   #define mysql_mutex_trylock(M) \
339     inline_mysql_mutex_trylock(M, __FILE__, __LINE__)
340 #else
341   #define mysql_mutex_trylock(M) \
342     inline_mysql_mutex_trylock(M)
343 #endif
344 
345 /**
346   @def mysql_mutex_unlock(M)
347   Instrumented mutex_unlock.
348   @c mysql_mutex_unlock is a drop-in replacement for @c pthread_mutex_unlock.
349 */
350 #ifdef SAFE_MUTEX
351   #define mysql_mutex_unlock(M) \
352     inline_mysql_mutex_unlock(M, __FILE__, __LINE__)
353 #else
354   #define mysql_mutex_unlock(M) \
355     inline_mysql_mutex_unlock(M)
356 #endif
357 
358 /**
359   @def mysql_rwlock_register(P1, P2, P3)
360   Rwlock registration.
361 */
362 #define mysql_rwlock_register(P1, P2, P3) \
363   inline_mysql_rwlock_register(P1, P2, P3)
364 
365 /**
366   @def mysql_rwlock_init(K, RW)
367   Instrumented rwlock_init.
368   @c mysql_rwlock_init is a replacement for @c pthread_rwlock_init.
369   Note that pthread_rwlockattr_t is not supported in MySQL.
370   @param K The PSI_rwlock_key for this instrumented rwlock
371   @param RW The rwlock to initialize
372 */
373 #ifdef HAVE_PSI_RWLOCK_INTERFACE
374   #define mysql_rwlock_init(K, RW) inline_mysql_rwlock_init(K, RW)
375 #else
376   #define mysql_rwlock_init(K, RW) inline_mysql_rwlock_init(RW)
377 #endif
378 
379 /**
380   @def mysql_prlock_init(K, RW)
381   Instrumented rw_pr_init.
382   @c mysql_prlock_init is a replacement for @c rw_pr_init.
383   @param K The PSI_rwlock_key for this instrumented prlock
384   @param RW The prlock to initialize
385 */
386 #ifdef HAVE_PSI_RWLOCK_INTERFACE
387   #define mysql_prlock_init(K, RW) inline_mysql_prlock_init(K, RW)
388 #else
389   #define mysql_prlock_init(K, RW) inline_mysql_prlock_init(RW)
390 #endif
391 
392 /**
393   @def mysql_rwlock_destroy(RW)
394   Instrumented rwlock_destroy.
395   @c mysql_rwlock_destroy is a drop-in replacement
396   for @c pthread_rwlock_destroy.
397 */
398 #define mysql_rwlock_destroy(RW) inline_mysql_rwlock_destroy(RW)
399 
400 /**
401   @def mysql_prlock_destroy(RW)
402   Instrumented rw_pr_destroy.
403   @c mysql_prlock_destroy is a drop-in replacement
404   for @c rw_pr_destroy.
405 */
406 #define mysql_prlock_destroy(RW) inline_mysql_prlock_destroy(RW)
407 
408 /**
409   @def mysql_rwlock_rdlock(RW)
410   Instrumented rwlock_rdlock.
411   @c mysql_rwlock_rdlock is a drop-in replacement
412   for @c pthread_rwlock_rdlock.
413 */
414 #ifdef HAVE_PSI_RWLOCK_INTERFACE
415   #define mysql_rwlock_rdlock(RW) \
416     inline_mysql_rwlock_rdlock(RW, __FILE__, __LINE__)
417 #else
418   #define mysql_rwlock_rdlock(RW) \
419     inline_mysql_rwlock_rdlock(RW)
420 #endif
421 
422 /**
423   @def mysql_prlock_rdlock(RW)
424   Instrumented rw_pr_rdlock.
425   @c mysql_prlock_rdlock is a drop-in replacement
426   for @c rw_pr_rdlock.
427 */
428 #ifdef HAVE_PSI_RWLOCK_INTERFACE
429   #define mysql_prlock_rdlock(RW) \
430     inline_mysql_prlock_rdlock(RW, __FILE__, __LINE__)
431 #else
432   #define mysql_prlock_rdlock(RW) \
433     inline_mysql_prlock_rdlock(RW)
434 #endif
435 
436 /**
437   @def mysql_rwlock_wrlock(RW)
438   Instrumented rwlock_wrlock.
439   @c mysql_rwlock_wrlock is a drop-in replacement
440   for @c pthread_rwlock_wrlock.
441 */
442 #ifdef HAVE_PSI_RWLOCK_INTERFACE
443   #define mysql_rwlock_wrlock(RW) \
444     inline_mysql_rwlock_wrlock(RW, __FILE__, __LINE__)
445 #else
446   #define mysql_rwlock_wrlock(RW) \
447     inline_mysql_rwlock_wrlock(RW)
448 #endif
449 
450 /**
451   @def mysql_prlock_wrlock(RW)
452   Instrumented rw_pr_wrlock.
453   @c mysql_prlock_wrlock is a drop-in replacement
454   for @c rw_pr_wrlock.
455 */
456 #ifdef HAVE_PSI_RWLOCK_INTERFACE
457   #define mysql_prlock_wrlock(RW) \
458     inline_mysql_prlock_wrlock(RW, __FILE__, __LINE__)
459 #else
460   #define mysql_prlock_wrlock(RW) \
461     inline_mysql_prlock_wrlock(RW)
462 #endif
463 
464 /**
465   @def mysql_rwlock_tryrdlock(RW)
466   Instrumented rwlock_tryrdlock.
467   @c mysql_rwlock_tryrdlock is a drop-in replacement
468   for @c pthread_rwlock_tryrdlock.
469 */
470 #ifdef HAVE_PSI_RWLOCK_INTERFACE
471   #define mysql_rwlock_tryrdlock(RW) \
472     inline_mysql_rwlock_tryrdlock(RW, __FILE__, __LINE__)
473 #else
474   #define mysql_rwlock_tryrdlock(RW) \
475     inline_mysql_rwlock_tryrdlock(RW)
476 #endif
477 
478 /**
479   @def mysql_rwlock_trywrlock(RW)
480   Instrumented rwlock_trywrlock.
481   @c mysql_rwlock_trywrlock is a drop-in replacement
482   for @c pthread_rwlock_trywrlock.
483 */
484 #ifdef HAVE_PSI_RWLOCK_INTERFACE
485   #define mysql_rwlock_trywrlock(RW) \
486     inline_mysql_rwlock_trywrlock(RW, __FILE__, __LINE__)
487 #else
488   #define mysql_rwlock_trywrlock(RW) \
489     inline_mysql_rwlock_trywrlock(RW)
490 #endif
491 
492 /**
493   @def mysql_rwlock_unlock(RW)
494   Instrumented rwlock_unlock.
495   @c mysql_rwlock_unlock is a drop-in replacement
496   for @c pthread_rwlock_unlock.
497 */
498 #define mysql_rwlock_unlock(RW) inline_mysql_rwlock_unlock(RW)
499 
500 /**
501   @def mysql_prlock_unlock(RW)
502   Instrumented rw_pr_unlock.
503   @c mysql_prlock_unlock is a drop-in replacement
504   for @c rw_pr_unlock.
505 */
506 #define mysql_prlock_unlock(RW) inline_mysql_prlock_unlock(RW)
507 
508 /**
509   @def mysql_cond_register(P1, P2, P3)
510   Cond registration.
511 */
512 #define mysql_cond_register(P1, P2, P3) \
513   inline_mysql_cond_register(P1, P2, P3)
514 
515 /**
516   @def mysql_cond_init(K, C, A)
517   Instrumented cond_init.
518   @c mysql_cond_init is a replacement for @c pthread_cond_init.
519   @param C The cond to initialize
520   @param K The PSI_cond_key for this instrumented cond
521   @param A Condition attributes
522 */
523 #ifdef HAVE_PSI_COND_INTERFACE
524   #define mysql_cond_init(K, C, A) inline_mysql_cond_init(K, C, A)
525 #else
526   #define mysql_cond_init(K, C, A) inline_mysql_cond_init(C, A)
527 #endif
528 
529 /**
530   @def mysql_cond_destroy(C)
531   Instrumented cond_destroy.
532   @c mysql_cond_destroy is a drop-in replacement for @c pthread_cond_destroy.
533 */
534 #define mysql_cond_destroy(C) inline_mysql_cond_destroy(C)
535 
536 /**
537   @def mysql_cond_wait(C)
538   Instrumented cond_wait.
539   @c mysql_cond_wait is a drop-in replacement for @c pthread_cond_wait.
540 */
541 #ifdef HAVE_PSI_COND_INTERFACE
542   #define mysql_cond_wait(C, M) \
543     inline_mysql_cond_wait(C, M, __FILE__, __LINE__)
544 #else
545   #define mysql_cond_wait(C, M) \
546     inline_mysql_cond_wait(C, M)
547 #endif
548 
549 /**
550   @def mysql_cond_timedwait(C, M, W)
551   Instrumented cond_timedwait.
552   @c mysql_cond_timedwait is a drop-in replacement
553   for @c pthread_cond_timedwait.
554 */
555 #ifdef HAVE_PSI_COND_INTERFACE
556   #define mysql_cond_timedwait(C, M, W) \
557     inline_mysql_cond_timedwait(C, M, W, __FILE__, __LINE__)
558 #else
559   #define mysql_cond_timedwait(C, M, W) \
560     inline_mysql_cond_timedwait(C, M, W)
561 #endif
562 
563 /**
564   @def mysql_cond_signal(C)
565   Instrumented cond_signal.
566   @c mysql_cond_signal is a drop-in replacement for @c pthread_cond_signal.
567 */
568 #define mysql_cond_signal(C) inline_mysql_cond_signal(C)
569 
570 /**
571   @def mysql_cond_broadcast(C)
572   Instrumented cond_broadcast.
573   @c mysql_cond_broadcast is a drop-in replacement
574   for @c pthread_cond_broadcast.
575 */
576 #define mysql_cond_broadcast(C) inline_mysql_cond_broadcast(C)
577 
578 /**
579   @def mysql_thread_register(P1, P2, P3)
580   Thread registration.
581 */
582 #define mysql_thread_register(P1, P2, P3) \
583   inline_mysql_thread_register(P1, P2, P3)
584 
585 /**
586   @def mysql_thread_create(K, P1, P2, P3, P4)
587   Instrumented pthread_create.
588   This function creates both the thread instrumentation and a thread.
589   @c mysql_thread_create is a replacement for @c pthread_create.
590   The parameter P4 (or, if it is NULL, P1) will be used as the
591   instrumented thread "indentity".
592   Providing a P1 / P4 parameter with a different value for each call
593   will on average improve performances, since this thread identity value
594   is used internally to randomize access to data and prevent contention.
595   This is optional, and the improvement is not guaranteed, only statistical.
596   @param K The PSI_thread_key for this instrumented thread
597   @param P1 pthread_create parameter 1
598   @param P2 pthread_create parameter 2
599   @param P3 pthread_create parameter 3
600   @param P4 pthread_create parameter 4
601 */
602 #ifdef HAVE_PSI_THREAD_INTERFACE
603   #define mysql_thread_create(K, P1, P2, P3, P4) \
604     inline_mysql_thread_create(K, P1, P2, P3, P4)
605 #else
606   #define mysql_thread_create(K, P1, P2, P3, P4) \
607     pthread_create(P1, P2, P3, P4)
608 #endif
609 
610 /**
611   @def mysql_thread_set_psi_id(I)
612   Set the thread identifier for the instrumentation.
613   @param I The thread identifier
614 */
615 #ifdef HAVE_PSI_THREAD_INTERFACE
616   #define mysql_thread_set_psi_id(I) inline_mysql_thread_set_psi_id(I)
617 #else
618   #define mysql_thread_set_psi_id(I) do {} while (0)
619 #endif
620 
inline_mysql_mutex_register(const char * category,PSI_mutex_info * info,int count)621 static inline void inline_mysql_mutex_register(
622 #ifdef HAVE_PSI_MUTEX_INTERFACE
623   const char *category,
624   PSI_mutex_info *info,
625   int count
626 #else
627   const char *category __attribute__ ((unused)),
628   void *info __attribute__ ((unused)),
629   int count __attribute__ ((unused))
630 #endif
631 )
632 {
633 #ifdef HAVE_PSI_MUTEX_INTERFACE
634   PSI_MUTEX_CALL(register_mutex)(category, info, count);
635 #endif
636 }
637 
inline_mysql_mutex_init(PSI_mutex_key key,mysql_mutex_t * that,const pthread_mutexattr_t * attr,const char * src_name,const char * src_file,uint src_line)638 static inline int inline_mysql_mutex_init(
639 #ifdef HAVE_PSI_MUTEX_INTERFACE
640   PSI_mutex_key key,
641 #endif
642   mysql_mutex_t *that,
643   const pthread_mutexattr_t *attr
644 #ifdef SAFE_MUTEX
645   , const char *src_name, const char *src_file, uint src_line
646 #endif
647   )
648 {
649 #ifdef HAVE_PSI_MUTEX_INTERFACE
650   that->m_psi= PSI_MUTEX_CALL(init_mutex)(key, &that->m_mutex);
651 #else
652   that->m_psi= NULL;
653 #endif
654 #ifdef SAFE_MUTEX
655   return safe_mutex_init(&that->m_mutex, attr, src_name, src_file, src_line);
656 #else
657   return pthread_mutex_init(&that->m_mutex, attr);
658 #endif
659 }
660 
inline_mysql_mutex_destroy(mysql_mutex_t * that,const char * src_file,uint src_line)661 static inline int inline_mysql_mutex_destroy(
662   mysql_mutex_t *that
663 #ifdef SAFE_MUTEX
664   , const char *src_file, uint src_line
665 #endif
666   )
667 {
668 #ifdef HAVE_PSI_MUTEX_INTERFACE
669   if (that->m_psi != NULL)
670   {
671     PSI_MUTEX_CALL(destroy_mutex)(that->m_psi);
672     that->m_psi= NULL;
673   }
674 #endif
675 #ifdef SAFE_MUTEX
676   return safe_mutex_destroy(&that->m_mutex, src_file, src_line);
677 #else
678   return pthread_mutex_destroy(&that->m_mutex);
679 #endif
680 }
681 
inline_mysql_mutex_lock(mysql_mutex_t * that,const char * src_file,uint src_line)682 static inline int inline_mysql_mutex_lock(
683   mysql_mutex_t *that
684 #if defined(SAFE_MUTEX) || defined (HAVE_PSI_MUTEX_INTERFACE)
685   , const char *src_file, uint src_line
686 #endif
687   )
688 {
689   int result;
690 
691 #ifdef HAVE_PSI_MUTEX_INTERFACE
692   if (psi_likely(that->m_psi != NULL))
693   {
694     /* Instrumentation start */
695     PSI_mutex_locker *locker;
696     PSI_mutex_locker_state state;
697     locker= PSI_MUTEX_CALL(start_mutex_wait)(&state, that->m_psi,
698                                        PSI_MUTEX_LOCK, src_file, src_line);
699 
700     /* Instrumented code */
701 #ifdef SAFE_MUTEX
702     result= safe_mutex_lock(&that->m_mutex, FALSE, src_file, src_line);
703 #else
704     result= pthread_mutex_lock(&that->m_mutex);
705 #endif
706 
707     /* Instrumentation end */
708     if (locker != NULL)
709       PSI_MUTEX_CALL(end_mutex_wait)(locker, result);
710 
711     return result;
712   }
713 #endif
714 
715   /* Non instrumented code */
716 #ifdef SAFE_MUTEX
717   result= safe_mutex_lock(&that->m_mutex, FALSE, src_file, src_line);
718 #else
719   result= pthread_mutex_lock(&that->m_mutex);
720 #endif
721 
722   return result;
723 }
724 
inline_mysql_mutex_trylock(mysql_mutex_t * that,const char * src_file,uint src_line)725 static inline int inline_mysql_mutex_trylock(
726   mysql_mutex_t *that
727 #if defined(SAFE_MUTEX) || defined (HAVE_PSI_MUTEX_INTERFACE)
728   , const char *src_file, uint src_line
729 #endif
730   )
731 {
732   int result;
733 
734 #ifdef HAVE_PSI_MUTEX_INTERFACE
735   if (psi_likely(that->m_psi != NULL))
736   {
737     /* Instrumentation start */
738     PSI_mutex_locker *locker;
739     PSI_mutex_locker_state state;
740     locker= PSI_MUTEX_CALL(start_mutex_wait)(&state, that->m_psi,
741                                        PSI_MUTEX_TRYLOCK, src_file, src_line);
742 
743     /* Instrumented code */
744 #ifdef SAFE_MUTEX
745     result= safe_mutex_lock(&that->m_mutex, TRUE, src_file, src_line);
746 #else
747     result= pthread_mutex_trylock(&that->m_mutex);
748 #endif
749 
750     /* Instrumentation end */
751     if (locker != NULL)
752       PSI_MUTEX_CALL(end_mutex_wait)(locker, result);
753 
754     return result;
755   }
756 #endif
757 
758   /* Non instrumented code */
759 #ifdef SAFE_MUTEX
760   result= safe_mutex_lock(&that->m_mutex, TRUE, src_file, src_line);
761 #else
762   result= pthread_mutex_trylock(&that->m_mutex);
763 #endif
764 
765   return result;
766 }
767 
inline_mysql_mutex_unlock(mysql_mutex_t * that,const char * src_file,uint src_line)768 static inline int inline_mysql_mutex_unlock(
769   mysql_mutex_t *that
770 #ifdef SAFE_MUTEX
771   , const char *src_file, uint src_line
772 #endif
773   )
774 {
775   int result;
776 
777 #ifdef HAVE_PSI_MUTEX_INTERFACE
778   if (psi_likely(that->m_psi != NULL))
779     PSI_MUTEX_CALL(unlock_mutex)(that->m_psi);
780 #endif
781 
782 #ifdef SAFE_MUTEX
783   result= safe_mutex_unlock(&that->m_mutex, src_file, src_line);
784 #else
785   result= pthread_mutex_unlock(&that->m_mutex);
786 #endif
787 
788   return result;
789 }
790 
inline_mysql_rwlock_register(const char * category,PSI_rwlock_info * info,int count)791 static inline void inline_mysql_rwlock_register(
792 #ifdef HAVE_PSI_RWLOCK_INTERFACE
793   const char *category,
794   PSI_rwlock_info *info,
795   int count
796 #else
797   const char *category __attribute__ ((unused)),
798   void *info __attribute__ ((unused)),
799   int count __attribute__ ((unused))
800 #endif
801 )
802 {
803 #ifdef HAVE_PSI_RWLOCK_INTERFACE
804   PSI_RWLOCK_CALL(register_rwlock)(category, info, count);
805 #endif
806 }
807 
inline_mysql_rwlock_init(PSI_rwlock_key key,mysql_rwlock_t * that)808 static inline int inline_mysql_rwlock_init(
809 #ifdef HAVE_PSI_RWLOCK_INTERFACE
810   PSI_rwlock_key key,
811 #endif
812   mysql_rwlock_t *that)
813 {
814 #ifdef HAVE_PSI_RWLOCK_INTERFACE
815   that->m_psi= PSI_RWLOCK_CALL(init_rwlock)(key, &that->m_rwlock);
816 #else
817   that->m_psi= NULL;
818 #endif
819   /*
820     pthread_rwlockattr_t is not used in MySQL.
821   */
822   return my_rwlock_init(&that->m_rwlock, NULL);
823 }
824 
825 #ifndef DISABLE_MYSQL_PRLOCK_H
inline_mysql_prlock_init(PSI_rwlock_key key,mysql_prlock_t * that)826 static inline int inline_mysql_prlock_init(
827 #ifdef HAVE_PSI_RWLOCK_INTERFACE
828   PSI_rwlock_key key,
829 #endif
830   mysql_prlock_t *that)
831 {
832 #ifdef HAVE_PSI_RWLOCK_INTERFACE
833   that->m_psi= PSI_RWLOCK_CALL(init_rwlock)(key, &that->m_prlock);
834 #else
835   that->m_psi= NULL;
836 #endif
837   return rw_pr_init(&that->m_prlock);
838 }
839 #endif
840 
inline_mysql_rwlock_destroy(mysql_rwlock_t * that)841 static inline int inline_mysql_rwlock_destroy(
842   mysql_rwlock_t *that)
843 {
844 #ifdef HAVE_PSI_RWLOCK_INTERFACE
845   if (psi_likely(that->m_psi != NULL))
846   {
847     PSI_RWLOCK_CALL(destroy_rwlock)(that->m_psi);
848     that->m_psi= NULL;
849   }
850 #endif
851   return rwlock_destroy(&that->m_rwlock);
852 }
853 
854 #ifndef DISABLE_MYSQL_PRLOCK_H
inline_mysql_prlock_destroy(mysql_prlock_t * that)855 static inline int inline_mysql_prlock_destroy(
856   mysql_prlock_t *that)
857 {
858 #ifdef HAVE_PSI_RWLOCK_INTERFACE
859   if (psi_likely(that->m_psi != NULL))
860   {
861     PSI_RWLOCK_CALL(destroy_rwlock)(that->m_psi);
862     that->m_psi= NULL;
863   }
864 #endif
865   return rw_pr_destroy(&that->m_prlock);
866 }
867 #endif
868 
inline_mysql_rwlock_rdlock(mysql_rwlock_t * that,const char * src_file,uint src_line)869 static inline int inline_mysql_rwlock_rdlock(
870   mysql_rwlock_t *that
871 #ifdef HAVE_PSI_RWLOCK_INTERFACE
872   , const char *src_file, uint src_line
873 #endif
874   )
875 {
876   int result;
877 
878 #ifdef HAVE_PSI_RWLOCK_INTERFACE
879   if (psi_likely(that->m_psi != NULL))
880   {
881     /* Instrumentation start */
882     PSI_rwlock_locker *locker;
883     PSI_rwlock_locker_state state;
884     locker= PSI_RWLOCK_CALL(start_rwlock_rdwait)(&state, that->m_psi,
885                                           PSI_RWLOCK_READLOCK, src_file, src_line);
886 
887     /* Instrumented code */
888     result= rw_rdlock(&that->m_rwlock);
889 
890     /* Instrumentation end */
891     if (locker != NULL)
892       PSI_RWLOCK_CALL(end_rwlock_rdwait)(locker, result);
893 
894     return result;
895   }
896 #endif
897 
898   /* Non instrumented code */
899   result= rw_rdlock(&that->m_rwlock);
900 
901   return result;
902 }
903 
904 #ifndef DISABLE_MYSQL_PRLOCK_H
inline_mysql_prlock_rdlock(mysql_prlock_t * that,const char * src_file,uint src_line)905 static inline int inline_mysql_prlock_rdlock(
906   mysql_prlock_t *that
907 #ifdef HAVE_PSI_RWLOCK_INTERFACE
908   , const char *src_file, uint src_line
909 #endif
910   )
911 {
912   int result;
913 
914 #ifdef HAVE_PSI_RWLOCK_INTERFACE
915   if (psi_likely(that->m_psi != NULL))
916   {
917     /* Instrumentation start */
918     PSI_rwlock_locker *locker;
919     PSI_rwlock_locker_state state;
920     locker= PSI_RWLOCK_CALL(start_rwlock_rdwait)(&state, that->m_psi,
921                                           PSI_RWLOCK_READLOCK, src_file, src_line);
922 
923     /* Instrumented code */
924     result= rw_pr_rdlock(&that->m_prlock);
925 
926     /* Instrumentation end */
927     if (locker != NULL)
928       PSI_RWLOCK_CALL(end_rwlock_rdwait)(locker, result);
929 
930     return result;
931   }
932 #endif
933 
934   /* Non instrumented code */
935   result= rw_pr_rdlock(&that->m_prlock);
936 
937   return result;
938 }
939 #endif
940 
inline_mysql_rwlock_wrlock(mysql_rwlock_t * that,const char * src_file,uint src_line)941 static inline int inline_mysql_rwlock_wrlock(
942   mysql_rwlock_t *that
943 #ifdef HAVE_PSI_RWLOCK_INTERFACE
944   , const char *src_file, uint src_line
945 #endif
946   )
947 {
948   int result;
949 
950 #ifdef HAVE_PSI_RWLOCK_INTERFACE
951   if (psi_likely(that->m_psi != NULL))
952   {
953     /* Instrumentation start */
954     PSI_rwlock_locker *locker;
955     PSI_rwlock_locker_state state;
956     locker= PSI_RWLOCK_CALL(start_rwlock_wrwait)(&state, that->m_psi,
957                                           PSI_RWLOCK_WRITELOCK, src_file, src_line);
958 
959     /* Instrumented code */
960     result= rw_wrlock(&that->m_rwlock);
961 
962     /* Instrumentation end */
963     if (locker != NULL)
964       PSI_RWLOCK_CALL(end_rwlock_wrwait)(locker, result);
965 
966     return result;
967   }
968 #endif
969 
970   /* Non instrumented code */
971   result= rw_wrlock(&that->m_rwlock);
972 
973   return result;
974 }
975 
976 #ifndef DISABLE_MYSQL_PRLOCK_H
inline_mysql_prlock_wrlock(mysql_prlock_t * that,const char * src_file,uint src_line)977 static inline int inline_mysql_prlock_wrlock(
978   mysql_prlock_t *that
979 #ifdef HAVE_PSI_RWLOCK_INTERFACE
980   , const char *src_file, uint src_line
981 #endif
982   )
983 {
984   int result;
985 
986 #ifdef HAVE_PSI_RWLOCK_INTERFACE
987   if (psi_likely(that->m_psi != NULL))
988   {
989     /* Instrumentation start */
990     PSI_rwlock_locker *locker;
991     PSI_rwlock_locker_state state;
992     locker= PSI_RWLOCK_CALL(start_rwlock_wrwait)(&state, that->m_psi,
993                                           PSI_RWLOCK_WRITELOCK, src_file, src_line);
994 
995     /* Instrumented code */
996     result= rw_pr_wrlock(&that->m_prlock);
997 
998     /* Instrumentation end */
999     if (locker != NULL)
1000       PSI_RWLOCK_CALL(end_rwlock_wrwait)(locker, result);
1001 
1002     return result;
1003   }
1004 #endif
1005 
1006   /* Non instrumented code */
1007   result= rw_pr_wrlock(&that->m_prlock);
1008 
1009   return result;
1010 }
1011 #endif
1012 
inline_mysql_rwlock_tryrdlock(mysql_rwlock_t * that,const char * src_file,uint src_line)1013 static inline int inline_mysql_rwlock_tryrdlock(
1014   mysql_rwlock_t *that
1015 #ifdef HAVE_PSI_RWLOCK_INTERFACE
1016   , const char *src_file, uint src_line
1017 #endif
1018   )
1019 {
1020   int result;
1021 
1022 #ifdef HAVE_PSI_RWLOCK_INTERFACE
1023   if (psi_likely(that->m_psi != NULL))
1024   {
1025     /* Instrumentation start */
1026     PSI_rwlock_locker *locker;
1027     PSI_rwlock_locker_state state;
1028     locker= PSI_RWLOCK_CALL(start_rwlock_rdwait)(&state, that->m_psi,
1029                                           PSI_RWLOCK_TRYREADLOCK, src_file, src_line);
1030 
1031     /* Instrumented code */
1032     result= rw_tryrdlock(&that->m_rwlock);
1033 
1034     /* Instrumentation end */
1035     if (locker != NULL)
1036       PSI_RWLOCK_CALL(end_rwlock_rdwait)(locker, result);
1037 
1038     return result;
1039   }
1040 #endif
1041 
1042   /* Non instrumented code */
1043   result= rw_tryrdlock(&that->m_rwlock);
1044 
1045   return result;
1046 }
1047 
inline_mysql_rwlock_trywrlock(mysql_rwlock_t * that,const char * src_file,uint src_line)1048 static inline int inline_mysql_rwlock_trywrlock(
1049   mysql_rwlock_t *that
1050 #ifdef HAVE_PSI_RWLOCK_INTERFACE
1051   , const char *src_file, uint src_line
1052 #endif
1053   )
1054 {
1055   int result;
1056 
1057 #ifdef HAVE_PSI_RWLOCK_INTERFACE
1058   if (psi_likely(that->m_psi != NULL))
1059   {
1060     /* Instrumentation start */
1061     PSI_rwlock_locker *locker;
1062     PSI_rwlock_locker_state state;
1063     locker= PSI_RWLOCK_CALL(start_rwlock_wrwait)(&state, that->m_psi,
1064                                           PSI_RWLOCK_TRYWRITELOCK, src_file, src_line);
1065 
1066     /* Instrumented code */
1067     result= rw_trywrlock(&that->m_rwlock);
1068 
1069     /* Instrumentation end */
1070     if (locker != NULL)
1071       PSI_RWLOCK_CALL(end_rwlock_wrwait)(locker, result);
1072 
1073     return result;
1074   }
1075 #endif
1076 
1077   /* Non instrumented code */
1078   result= rw_trywrlock(&that->m_rwlock);
1079 
1080   return result;
1081 }
1082 
inline_mysql_rwlock_unlock(mysql_rwlock_t * that)1083 static inline int inline_mysql_rwlock_unlock(
1084   mysql_rwlock_t *that)
1085 {
1086   int result;
1087 #ifdef HAVE_PSI_RWLOCK_INTERFACE
1088   if (psi_likely(that->m_psi != NULL))
1089     PSI_RWLOCK_CALL(unlock_rwlock)(that->m_psi);
1090 #endif
1091   result= rw_unlock(&that->m_rwlock);
1092   return result;
1093 }
1094 
1095 #ifndef DISABLE_MYSQL_PRLOCK_H
inline_mysql_prlock_unlock(mysql_prlock_t * that)1096 static inline int inline_mysql_prlock_unlock(
1097   mysql_prlock_t *that)
1098 {
1099   int result;
1100 #ifdef HAVE_PSI_RWLOCK_INTERFACE
1101   if (psi_likely(that->m_psi != NULL))
1102     PSI_RWLOCK_CALL(unlock_rwlock)(that->m_psi);
1103 #endif
1104   result= rw_pr_unlock(&that->m_prlock);
1105   return result;
1106 }
1107 #endif
1108 
inline_mysql_cond_register(const char * category,PSI_cond_info * info,int count)1109 static inline void inline_mysql_cond_register(
1110 #ifdef HAVE_PSI_COND_INTERFACE
1111   const char *category,
1112   PSI_cond_info *info,
1113   int count
1114 #else
1115   const char *category __attribute__ ((unused)),
1116   void *info __attribute__ ((unused)),
1117   int count __attribute__ ((unused))
1118 #endif
1119 )
1120 {
1121 #ifdef HAVE_PSI_COND_INTERFACE
1122   PSI_COND_CALL(register_cond)(category, info, count);
1123 #endif
1124 }
1125 
inline_mysql_cond_init(PSI_cond_key key,mysql_cond_t * that,const pthread_condattr_t * attr)1126 static inline int inline_mysql_cond_init(
1127 #ifdef HAVE_PSI_COND_INTERFACE
1128   PSI_cond_key key,
1129 #endif
1130   mysql_cond_t *that,
1131   const pthread_condattr_t *attr)
1132 {
1133 #ifdef HAVE_PSI_COND_INTERFACE
1134   that->m_psi= PSI_COND_CALL(init_cond)(key, &that->m_cond);
1135 #else
1136   that->m_psi= NULL;
1137 #endif
1138   return pthread_cond_init(&that->m_cond, attr);
1139 }
1140 
inline_mysql_cond_destroy(mysql_cond_t * that)1141 static inline int inline_mysql_cond_destroy(
1142   mysql_cond_t *that)
1143 {
1144 #ifdef HAVE_PSI_COND_INTERFACE
1145   if (psi_likely(that->m_psi != NULL))
1146   {
1147     PSI_COND_CALL(destroy_cond)(that->m_psi);
1148     that->m_psi= NULL;
1149   }
1150 #endif
1151   return pthread_cond_destroy(&that->m_cond);
1152 }
1153 
inline_mysql_cond_wait(mysql_cond_t * that,mysql_mutex_t * mutex,const char * src_file,uint src_line)1154 static inline int inline_mysql_cond_wait(
1155   mysql_cond_t *that,
1156   mysql_mutex_t *mutex
1157 #ifdef HAVE_PSI_COND_INTERFACE
1158   , const char *src_file, uint src_line
1159 #endif
1160   )
1161 {
1162   int result;
1163 
1164 #ifdef HAVE_PSI_COND_INTERFACE
1165   if (psi_likely(that->m_psi != NULL))
1166   {
1167     /* Instrumentation start */
1168     PSI_cond_locker *locker;
1169     PSI_cond_locker_state state;
1170     locker= PSI_COND_CALL(start_cond_wait)(&state, that->m_psi, mutex->m_psi,
1171                                       PSI_COND_WAIT, src_file, src_line);
1172 
1173     /* Instrumented code */
1174     result= my_cond_wait(&that->m_cond, &mutex->m_mutex);
1175 
1176     /* Instrumentation end */
1177     if (locker != NULL)
1178       PSI_COND_CALL(end_cond_wait)(locker, result);
1179 
1180     return result;
1181   }
1182 #endif
1183 
1184   /* Non instrumented code */
1185   result= my_cond_wait(&that->m_cond, &mutex->m_mutex);
1186 
1187   return result;
1188 }
1189 
inline_mysql_cond_timedwait(mysql_cond_t * that,mysql_mutex_t * mutex,const struct timespec * abstime,const char * src_file,uint src_line)1190 static inline int inline_mysql_cond_timedwait(
1191   mysql_cond_t *that,
1192   mysql_mutex_t *mutex,
1193   const struct timespec *abstime
1194 #ifdef HAVE_PSI_COND_INTERFACE
1195   , const char *src_file, uint src_line
1196 #endif
1197   )
1198 {
1199   int result;
1200 
1201 #ifdef HAVE_PSI_COND_INTERFACE
1202   if (psi_likely(that->m_psi != NULL))
1203   {
1204     /* Instrumentation start */
1205     PSI_cond_locker *locker;
1206     PSI_cond_locker_state state;
1207     locker= PSI_COND_CALL(start_cond_wait)(&state, that->m_psi, mutex->m_psi,
1208                                       PSI_COND_TIMEDWAIT, src_file, src_line);
1209 
1210     /* Instrumented code */
1211     result= my_cond_timedwait(&that->m_cond, &mutex->m_mutex, abstime);
1212 
1213     /* Instrumentation end */
1214     if (psi_likely(locker != NULL))
1215       PSI_COND_CALL(end_cond_wait)(locker, result);
1216 
1217     return result;
1218   }
1219 #endif
1220 
1221   /* Non instrumented code */
1222   result= my_cond_timedwait(&that->m_cond, &mutex->m_mutex, abstime);
1223 
1224   return result;
1225 }
1226 
inline_mysql_cond_signal(mysql_cond_t * that)1227 static inline int inline_mysql_cond_signal(
1228   mysql_cond_t *that)
1229 {
1230   int result;
1231 #ifdef HAVE_PSI_COND_INTERFACE
1232   if (psi_likely(that->m_psi != NULL))
1233     PSI_COND_CALL(signal_cond)(that->m_psi);
1234 #endif
1235   result= pthread_cond_signal(&that->m_cond);
1236   return result;
1237 }
1238 
inline_mysql_cond_broadcast(mysql_cond_t * that)1239 static inline int inline_mysql_cond_broadcast(
1240   mysql_cond_t *that)
1241 {
1242   int result;
1243 #ifdef HAVE_PSI_COND_INTERFACE
1244   if (psi_likely(that->m_psi != NULL))
1245     PSI_COND_CALL(broadcast_cond)(that->m_psi);
1246 #endif
1247   result= pthread_cond_broadcast(&that->m_cond);
1248   return result;
1249 }
1250 
inline_mysql_thread_register(const char * category,PSI_thread_info * info,int count)1251 static inline void inline_mysql_thread_register(
1252 #ifdef HAVE_PSI_THREAD_INTERFACE
1253   const char *category,
1254   PSI_thread_info *info,
1255   int count
1256 #else
1257   const char *category __attribute__ ((unused)),
1258   void *info __attribute__ ((unused)),
1259   int count __attribute__ ((unused))
1260 #endif
1261 )
1262 {
1263 #ifdef HAVE_PSI_THREAD_INTERFACE
1264   PSI_THREAD_CALL(register_thread)(category, info, count);
1265 #endif
1266 }
1267 
1268 #ifdef HAVE_PSI_THREAD_INTERFACE
inline_mysql_thread_create(PSI_thread_key key,pthread_t * thread,const pthread_attr_t * attr,void * (* start_routine)(void *),void * arg)1269 static inline int inline_mysql_thread_create(
1270   PSI_thread_key key,
1271   pthread_t *thread, const pthread_attr_t *attr,
1272   void *(*start_routine)(void*), void *arg)
1273 {
1274   int result;
1275   result= PSI_THREAD_CALL(spawn_thread)(key, thread, attr, start_routine, arg);
1276   return result;
1277 }
1278 
inline_mysql_thread_set_psi_id(my_thread_id id)1279 static inline void inline_mysql_thread_set_psi_id(my_thread_id id)
1280 {
1281   struct PSI_thread *psi= PSI_THREAD_CALL(get_thread)();
1282   PSI_THREAD_CALL(set_thread_id)(psi, id);
1283 }
1284 #endif
1285 
1286 #endif /* DISABLE_MYSQL_THREAD_H */
1287 
1288 /** @} (end of group Thread_instrumentation) */
1289 
1290 #endif
1291 
1292