drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
sync0rw.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 1995, 2011, Oracle and/or its affiliates. All Rights Reserved.
4Copyright (C) 2008, Google Inc.
5
6Portions of this file contain modifications contributed and copyrighted by
7Google, Inc. Those modifications are gratefully acknowledged and are described
8briefly in the InnoDB documentation. The contributions by Google are
9incorporated with their permission, and subject to the conditions contained in
10the file COPYING.Google.
11
12This program is free software; you can redistribute it and/or modify it under
13the terms of the GNU General Public License as published by the Free Software
14Foundation; version 2 of the License.
15
16This program is distributed in the hope that it will be useful, but WITHOUT
17ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
19
20You should have received a copy of the GNU General Public License along with
21this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
22St, Fifth Floor, Boston, MA 02110-1301 USA
23
24*****************************************************************************/
25
26/**************************************************/
32
33#pragma once
34#ifndef sync0rw_h
35#define sync0rw_h
36
37#include "univ.i"
38#ifndef UNIV_HOTBACKUP
39#include "ut0lst.h"
40#include "sync0sync.h"
41#include "os0sync.h"
42
43/* The following undef is to prevent a name conflict with a macro
44in MySQL: */
45#undef rw_lock_t
46#endif /* !UNIV_HOTBACKUP */
47
48/* Latch types; these are used also in btr0btr.h: keep the numerical values
49smaller than 30 and the order of the numerical values like below! */
50#define RW_S_LATCH 1
51#define RW_X_LATCH 2
52#define RW_NO_LATCH 3
53
54#ifndef UNIV_HOTBACKUP
55/* We decrement lock_word by this amount for each x_lock. It is also the
56start value for the lock_word, meaning that it limits the maximum number
57of concurrent read locks before the rw_lock breaks. The current value of
580x00100000 allows 1,048,575 concurrent readers and 2047 recursive writers.*/
59#define X_LOCK_DECR 0x00100000
60
61typedef struct rw_lock_struct rw_lock_t;
62#ifdef UNIV_SYNC_DEBUG
63typedef struct rw_lock_debug_struct rw_lock_debug_t;
64#endif /* UNIV_SYNC_DEBUG */
65
66typedef UT_LIST_BASE_NODE_T(rw_lock_t) rw_lock_list_t;
67
68extern rw_lock_list_t rw_lock_list;
69extern mutex_t rw_lock_list_mutex;
70
71#ifdef UNIV_SYNC_DEBUG
72/* The global mutex which protects debug info lists of all rw-locks.
73To modify the debug info list of an rw-lock, this mutex has to be
74
75acquired in addition to the mutex protecting the lock. */
76extern mutex_t rw_lock_debug_mutex;
77extern os_event_t rw_lock_debug_event;
80extern ibool rw_lock_debug_waiters;
82#endif /* UNIV_SYNC_DEBUG */
83
86extern ib_int64_t rw_s_spin_wait_count;
89extern ib_int64_t rw_s_spin_round_count;
92extern ib_int64_t rw_s_exit_count;
95extern ib_int64_t rw_s_os_wait_count;
98extern ib_int64_t rw_x_spin_wait_count;
101extern ib_int64_t rw_x_spin_round_count;
104extern ib_int64_t rw_x_os_wait_count;
107extern ib_int64_t rw_x_exit_count;
108
109#ifdef UNIV_PFS_RWLOCK
110/* Following are rwlock keys used to register with MySQL
111performance schema */
112# ifdef UNIV_LOG_ARCHIVE
113extern mysql_pfs_key_t archive_lock_key;
114# endif /* UNIV_LOG_ARCHIVE */
115extern mysql_pfs_key_t btr_search_latch_key;
116extern mysql_pfs_key_t buf_block_lock_key;
117# ifdef UNIV_SYNC_DEBUG
118extern mysql_pfs_key_t buf_block_debug_latch_key;
119# endif /* UNIV_SYNC_DEBUG */
120extern mysql_pfs_key_t dict_operation_lock_key;
121extern mysql_pfs_key_t fil_space_latch_key;
122extern mysql_pfs_key_t checkpoint_lock_key;
123extern mysql_pfs_key_t trx_i_s_cache_lock_key;
124extern mysql_pfs_key_t trx_purge_latch_key;
125extern mysql_pfs_key_t index_tree_rw_lock_key;
126extern mysql_pfs_key_t dict_table_stats_latch_key;
127#endif /* UNIV_PFS_RWLOCK */
128
129
130#ifndef UNIV_PFS_RWLOCK
131/******************************************************************/
138# ifdef UNIV_DEBUG
139# ifdef UNIV_SYNC_DEBUG
140# define rw_lock_create(K, L, level) \
141 rw_lock_create_func((L), (level), #L, __FILE__, __LINE__)
142# else /* UNIV_SYNC_DEBUG */
143# define rw_lock_create(K, L, level) \
144 rw_lock_create_func((L), #L, __FILE__, __LINE__)
145# endif/* UNIV_SYNC_DEBUG */
146# else /* UNIV_DEBUG */
147# define rw_lock_create(K, L, level) \
148 rw_lock_create_func((L), __FILE__, __LINE__)
149# endif /* UNIV_DEBUG */
150
151/**************************************************************/
154
155# define rw_lock_s_lock(M) \
156 rw_lock_s_lock_func((M), 0, __FILE__, __LINE__)
157
158# define rw_lock_s_lock_gen(M, P) \
159 rw_lock_s_lock_func((M), (P), __FILE__, __LINE__)
160
161# define rw_lock_s_lock_nowait(M, F, L) \
162 rw_lock_s_lock_low((M), 0, (F), (L))
163
164# ifdef UNIV_SYNC_DEBUG
165# define rw_lock_s_unlock_gen(L, P) rw_lock_s_unlock_func(P, L)
166# else
167# define rw_lock_s_unlock_gen(L, P) rw_lock_s_unlock_func(L)
168# endif
169
170
171# define rw_lock_x_lock(M) \
172 rw_lock_x_lock_func((M), 0, __FILE__, __LINE__)
173
174# define rw_lock_x_lock_gen(M, P) \
175 rw_lock_x_lock_func((M), (P), __FILE__, __LINE__)
176
177# define rw_lock_x_lock_nowait(M) \
178 rw_lock_x_lock_func_nowait((M), __FILE__, __LINE__)
179
180# ifdef UNIV_SYNC_DEBUG
181# define rw_lock_x_unlock_gen(L, P) rw_lock_x_unlock_func(P, L)
182# else
183# define rw_lock_x_unlock_gen(L, P) rw_lock_x_unlock_func(L)
184# endif
185
186# define rw_lock_free(M) rw_lock_free_func(M)
187
188#else /* !UNIV_PFS_RWLOCK */
189
190/* Following macros point to Performance Schema instrumented functions. */
191# ifdef UNIV_DEBUG
192# ifdef UNIV_SYNC_DEBUG
193# define rw_lock_create(K, L, level) \
194 pfs_rw_lock_create_func((K), (L), (level), #L, __FILE__, __LINE__)
195# else /* UNIV_SYNC_DEBUG */
196# define rw_lock_create(K, L, level) \
197 pfs_rw_lock_create_func((K), (L), #L, __FILE__, __LINE__)
198# endif/* UNIV_SYNC_DEBUG */
199# else /* UNIV_DEBUG */
200# define rw_lock_create(K, L, level) \
201 pfs_rw_lock_create_func((K), (L), __FILE__, __LINE__)
202# endif /* UNIV_DEBUG */
203
204/******************************************************************
205NOTE! The following macros should be used in rw locking and
206unlocking, not the corresponding function. */
207
208# define rw_lock_s_lock(M) \
209 pfs_rw_lock_s_lock_func((M), 0, __FILE__, __LINE__)
210
211# define rw_lock_s_lock_gen(M, P) \
212 pfs_rw_lock_s_lock_func((M), (P), __FILE__, __LINE__)
213
214# define rw_lock_s_lock_nowait(M, F, L) \
215 pfs_rw_lock_s_lock_low((M), 0, (F), (L))
216
217# ifdef UNIV_SYNC_DEBUG
218# define rw_lock_s_unlock_gen(L, P) pfs_rw_lock_s_unlock_func(P, L)
219# else
220# define rw_lock_s_unlock_gen(L, P) pfs_rw_lock_s_unlock_func(L)
221# endif
222
223# define rw_lock_x_lock(M) \
224 pfs_rw_lock_x_lock_func((M), 0, __FILE__, __LINE__)
225
226# define rw_lock_x_lock_gen(M, P) \
227 pfs_rw_lock_x_lock_func((M), (P), __FILE__, __LINE__)
228
229# define rw_lock_x_lock_nowait(M) \
230 pfs_rw_lock_x_lock_func_nowait((M), __FILE__, __LINE__)
231
232# ifdef UNIV_SYNC_DEBUG
233# define rw_lock_x_unlock_gen(L, P) pfs_rw_lock_x_unlock_func(P, L)
234# else
235# define rw_lock_x_unlock_gen(L, P) pfs_rw_lock_x_unlock_func(L)
236# endif
237
238# define rw_lock_free(M) pfs_rw_lock_free_func(M)
239
240#endif /* UNIV_PFS_RWLOCK */
241
242#define rw_lock_s_unlock(L) rw_lock_s_unlock_gen(L, 0)
243#define rw_lock_x_unlock(L) rw_lock_x_unlock_gen(L, 0)
244
245/******************************************************************/
250UNIV_INTERN
251void
253/*================*/
254 rw_lock_t* lock,
255#ifdef UNIV_DEBUG
256# ifdef UNIV_SYNC_DEBUG
257 ulint level,
258# endif /* UNIV_SYNC_DEBUG */
259 const char* cmutex_name,
260#endif /* UNIV_DEBUG */
261 const char* cfile_name,
262 ulint cline);
263/******************************************************************/
267UNIV_INTERN
268void
270/*==============*/
271 rw_lock_t* lock);
272#ifdef UNIV_DEBUG
273/******************************************************************/
277UNIV_INTERN
278ibool
279rw_lock_validate(
280/*=============*/
281 rw_lock_t* lock);
282#endif /* UNIV_DEBUG */
283/******************************************************************/
287UNIV_INLINE
288ibool
290/*===============*/
291 rw_lock_t* lock,
292 ulint /*pass __attribute__((unused))*/,
295 const char* file_name,
296 ulint line);
297/******************************************************************/
304UNIV_INLINE
305void
307/*================*/
308 rw_lock_t* lock,
309 ulint pass,
311 const char* file_name,
312 ulint line);
313/******************************************************************/
318UNIV_INLINE
319ibool
321/*=======================*/
322 rw_lock_t* lock,
323 const char* file_name,
324 ulint line);
325/******************************************************************/
327UNIV_INLINE
328void
330/*==================*/
331#ifdef UNIV_SYNC_DEBUG
332 ulint pass,
334#endif
335 rw_lock_t* lock);
336
337/******************************************************************/
346UNIV_INTERN
347void
349/*================*/
350 rw_lock_t* lock,
351 ulint pass,
353 const char* file_name,
354 ulint line);
355/******************************************************************/
357UNIV_INLINE
358void
360/*==================*/
361#ifdef UNIV_SYNC_DEBUG
362 ulint pass,
364#endif
365 rw_lock_t* lock);
366
367
368/******************************************************************/
372UNIV_INLINE
373void
375/*==================*/
376 rw_lock_t* lock,
377 const char* file_name,
378 ulint line);
379/******************************************************************/
383UNIV_INLINE
384void
386/*==================*/
387 rw_lock_t* lock,
388 const char* file_name,
389 ulint line);
390/******************************************************************/
398UNIV_INTERN
399void
401/*==========================*/
402 rw_lock_t* lock);
404/******************************************************************/
407UNIV_INLINE
408void
410/*====================*/
411 rw_lock_t* lock);
412/******************************************************************/
415UNIV_INLINE
416void
418/*====================*/
419 rw_lock_t* lock);
420/******************************************************************/
424UNIV_INLINE
425ulint
427/*=====================*/
428 const rw_lock_t* lock);
429/********************************************************************/
432UNIV_INLINE
433ulint
435/*================*/
436 const rw_lock_t* lock);
437/******************************************************************/
441UNIV_INLINE
442ulint
444/*===============*/
445 const rw_lock_t* lock);
446/******************************************************************/
449UNIV_INLINE
450ulint
452/*=====================*/
453 const rw_lock_t* lock);
454/******************************************************************/
458UNIV_INLINE
459ibool
461/*===================*/
462 rw_lock_t* lock,
463 ulint amount);
464/******************************************************************/
467UNIV_INLINE
468lint
470/*===================*/
471 rw_lock_t* lock,
472 ulint amount);
473/******************************************************************/
482UNIV_INLINE
483void
485/*=====================================*/
486 rw_lock_t* lock,
487 ibool recursive);
489#ifdef UNIV_SYNC_DEBUG
490/******************************************************************/
493UNIV_INTERN
494ibool
495rw_lock_own(
496/*========*/
497 rw_lock_t* lock,
498 ulint lock_type)
500 __attribute__((warn_unused_result));
501#endif /* UNIV_SYNC_DEBUG */
502/******************************************************************/
504UNIV_INTERN
505ibool
507/*==============*/
508 rw_lock_t* lock,
509 ulint lock_type);
511#ifdef UNIV_SYNC_DEBUG
512/***************************************************************/
514UNIV_INTERN
515void
516rw_lock_print(
517/*==========*/
518 rw_lock_t* lock);
519/***************************************************************/
521UNIV_INTERN
522void
523rw_lock_list_print_info(
524/*====================*/
525 FILE* file);
526/***************************************************************/
530UNIV_INTERN
531ulint
532rw_lock_n_locked(void);
533/*==================*/
534
535/*#####################################################################*/
536
537/******************************************************************/
543UNIV_INTERN
544void
545rw_lock_debug_mutex_enter(void);
546/*==========================*/
547/******************************************************************/
549UNIV_INTERN
550void
551rw_lock_debug_mutex_exit(void);
552/*==========================*/
553/*********************************************************************/
555UNIV_INTERN
556void
557rw_lock_debug_print(
558/*================*/
559 FILE* f,
560 rw_lock_debug_t* info);
561#endif /* UNIV_SYNC_DEBUG */
562
563/* NOTE! The structure appears here only for the compiler to know its size.
564Do not use its fields directly! */
565
574 volatile lint lock_word;
576 volatile ulint waiters;
577 volatile ibool recursive;
597#ifndef INNODB_RW_LOCKS_USE_ATOMICS
599#endif /* INNODB_RW_LOCKS_USE_ATOMICS */
600
601 UT_LIST_NODE_T(rw_lock_t) list;
604#ifdef UNIV_SYNC_DEBUG
605 UT_LIST_BASE_NODE_T(rw_lock_debug_t) debug_list;
608 ulint level;
609#endif /* UNIV_SYNC_DEBUG */
610#ifdef UNIV_PFS_RWLOCK
611 struct PSI_rwlock *pfs_psi;
612#endif
614 const char* cfile_name;
615 /* last s-lock file/line is not guaranteed to be correct */
616 const char* last_s_file_name;
617 const char* last_x_file_name;
625 unsigned cline:14;
626 unsigned last_s_line:14;
627 unsigned last_x_line:14;
628#ifdef UNIV_DEBUG
629 ulint magic_n;
631#define RW_LOCK_MAGIC_N 22643
632#endif /* UNIV_DEBUG */
633};
634
635#ifdef UNIV_SYNC_DEBUG
637struct rw_lock_debug_struct {
638
639 os_thread_id_t thread_id;
641 ulint pass;
642 ulint lock_type;
644 const char* file_name;
645 ulint line;
646 UT_LIST_NODE_T(rw_lock_debug_t) list;
649};
650#endif /* UNIV_SYNC_DEBUG */
651
652/* For performance schema instrumentation, a new set of rwlock
653wrap functions are created if "UNIV_PFS_RWLOCK" is defined.
654The instrumentations are not planted directly into original
655functions, so that we keep the underlying function as they
656are. And in case, user wants to "take out" some rwlock from
657instrumentation even if performance schema (UNIV_PFS_RWLOCK)
658is defined, they can do so by reinstating APIs directly link to
659original underlying functions.
660The instrumented function names have prefix of "pfs_rw_lock_" vs.
661original name prefix of "rw_lock_". Following are list of functions
662that have been instrumented:
663
664rw_lock_create()
665rw_lock_x_lock()
666rw_lock_x_lock_gen()
667rw_lock_x_lock_nowait()
668rw_lock_x_unlock_gen()
669rw_lock_s_lock()
670rw_lock_s_lock_gen()
671rw_lock_s_lock_nowait()
672rw_lock_s_unlock_gen()
673rw_lock_free()
674
675Two function APIs rw_lock_x_unlock_direct() and rw_lock_s_unlock_direct()
676do not have any caller/user, they are not instrumented.
677*/
678
679#ifdef UNIV_PFS_RWLOCK
680/******************************************************************/
684UNIV_INLINE
685void
686pfs_rw_lock_create_func(
687/*====================*/
688 PSI_rwlock_key key,
690 rw_lock_t* lock,
691#ifdef UNIV_DEBUG
692# ifdef UNIV_SYNC_DEBUG
693 ulint level,
694# endif /* UNIV_SYNC_DEBUG */
695 const char* cmutex_name,
696#endif /* UNIV_DEBUG */
697 const char* cfile_name,
698 ulint cline);
699
700/******************************************************************/
704UNIV_INLINE
705void
706pfs_rw_lock_x_lock_func(
707/*====================*/
708 rw_lock_t* lock,
709 ulint pass,
711 const char* file_name,
712 ulint line);
713/******************************************************************/
718UNIV_INLINE
719ibool
720pfs_rw_lock_x_lock_func_nowait(
721/*===========================*/
722 rw_lock_t* lock,
723 const char* file_name,
724 ulint line);
725/******************************************************************/
729UNIV_INLINE
730void
731pfs_rw_lock_s_lock_func(
732/*====================*/
733 rw_lock_t* lock,
734 ulint pass,
736 const char* file_name,
737 ulint line);
738/******************************************************************/
743UNIV_INLINE
744ibool
745pfs_rw_lock_s_lock_low(
746/*===================*/
747 rw_lock_t* lock,
748 ulint pass,
751 const char* file_name,
752 ulint line);
753/******************************************************************/
757UNIV_INLINE
758void
759pfs_rw_lock_x_lock_func(
760/*====================*/
761 rw_lock_t* lock,
762 ulint pass,
764 const char* file_name,
765 ulint line);
766/******************************************************************/
770UNIV_INLINE
771void
772pfs_rw_lock_s_unlock_func(
773/*======================*/
774#ifdef UNIV_SYNC_DEBUG
775 ulint pass,
778#endif
779 rw_lock_t* lock);
780/******************************************************************/
784UNIV_INLINE
785void
786pfs_rw_lock_x_unlock_func(
787/*======================*/
788#ifdef UNIV_SYNC_DEBUG
789 ulint pass,
792#endif
793 rw_lock_t* lock);
794/******************************************************************/
798UNIV_INLINE
799void
800pfs_rw_lock_free_func(
801/*==================*/
802 rw_lock_t* lock);
803#endif /* UNIV_PFS_RWLOCK */
804
805
806#ifndef UNIV_NONINL
807#include "sync0rw.ic"
808#endif
809#endif /* !UNIV_HOTBACKUP */
810
811#endif
os_event_struct_t * os_event_t
Definition os0sync.h:58
os_thread_t os_thread_id_t
Definition os0thread.h:53
os_event_t event
Definition sync0rw.h:593
mutex_t mutex
Definition sync0rw.h:598
os_event_t wait_ex_event
Definition sync0rw.h:594
const char * last_x_file_name
Definition sync0rw.h:617
volatile ulint waiters
Definition sync0rw.h:576
UT_LIST_NODE_T(rw_lock_t) list
volatile lint lock_word
Definition sync0rw.h:574
unsigned last_s_line
Definition sync0rw.h:626
ibool writer_is_wait_ex
Definition sync0rw.h:618
unsigned cline
Definition sync0rw.h:625
const char * cfile_name
Definition sync0rw.h:614
ulint count_os_wait
Definition sync0rw.h:613
volatile ibool recursive
Definition sync0rw.h:577
const char * last_s_file_name
Definition sync0rw.h:616
unsigned last_x_line
Definition sync0rw.h:627
volatile os_thread_id_t writer_thread
Definition sync0rw.h:589
UNIV_INLINE void rw_lock_x_unlock_func(rw_lock_t *lock)
UNIV_INLINE void rw_lock_set_writer_id_and_recursion_flag(rw_lock_t *lock, ibool recursive)
UNIV_INLINE void rw_lock_s_lock_func(rw_lock_t *lock, ulint pass, const char *file_name, ulint line)
ib_int64_t rw_x_spin_round_count
Definition sync0rw.cc:158
ib_int64_t rw_s_spin_wait_count
Definition sync0rw.cc:140
ib_int64_t rw_s_os_wait_count
Definition sync0rw.cc:147
UNIV_INLINE void rw_lock_x_lock_direct(rw_lock_t *lock, const char *file_name, ulint line)
UNIV_INLINE void rw_lock_s_unlock_func(rw_lock_t *lock)
UNIV_INLINE ibool rw_lock_lock_word_decr(rw_lock_t *lock, ulint amount)
UNIV_INTERN void rw_lock_create_func(rw_lock_t *lock, const char *cfile_name, ulint cline)
Definition sync0rw.cc:238
UNIV_INLINE ibool rw_lock_x_lock_func_nowait(rw_lock_t *lock, const char *file_name, ulint line)
ib_int64_t rw_s_spin_round_count
Definition sync0rw.cc:143
UNIV_INLINE void rw_lock_s_lock_direct(rw_lock_t *lock, const char *file_name, ulint line)
UNIV_INLINE ibool rw_lock_s_lock_low(rw_lock_t *lock, ulint, const char *file_name, ulint line)
ib_int64_t rw_x_spin_wait_count
Definition sync0rw.cc:155
ib_int64_t rw_s_exit_count
Definition sync0rw.cc:151
UNIV_INLINE ulint rw_lock_get_waiters(const rw_lock_t *lock)
UNIV_INLINE ulint rw_lock_get_writer(const rw_lock_t *lock)
UNIV_INTERN void rw_lock_x_lock_move_ownership(rw_lock_t *lock)
Definition sync0rw.cc:473
ib_int64_t rw_x_exit_count
Definition sync0rw.cc:166
UNIV_INLINE ulint rw_lock_get_x_lock_count(const rw_lock_t *lock)
UNIV_INLINE lint rw_lock_lock_word_incr(rw_lock_t *lock, ulint amount)
UNIV_INLINE ulint rw_lock_get_reader_count(const rw_lock_t *lock)
UNIV_INLINE void rw_lock_x_unlock_direct(rw_lock_t *lock)
UNIV_INLINE void rw_lock_s_unlock_direct(rw_lock_t *lock)
UNIV_INTERN ibool rw_lock_is_locked(rw_lock_t *lock, ulint lock_type)
Definition sync0rw.cc:881
ib_int64_t rw_x_os_wait_count
Definition sync0rw.cc:162
UNIV_INTERN void rw_lock_free_func(rw_lock_t *lock)
Definition sync0rw.cc:314
UNIV_INTERN void rw_lock_x_lock_func(rw_lock_t *lock, ulint pass, const char *file_name, ulint line)
Definition sync0rw.cc:616
#define mutex_t
Definition sync0types.h:31
#define UT_LIST_NODE_T(TYPE)
Definition ut0lst.h:73
#define UT_LIST_BASE_NODE_T(TYPE)
Definition ut0lst.h:54