~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/innobase/include/sync0rw.h

  • Committer: lbieber
  • Date: 2010-10-06 16:34:16 UTC
  • mfrom: (1816.1.3 build)
  • Revision ID: lbieber@orisndriz08-20101006163416-ea0sl59qgpglk21y
Merge Monty - Change the requirement from either libinnodb to libhaildb. Also, tied it to version 2.2
Merge Andrew - fix bug 650935: remove --compress from all clients
Merge Andrew - fix bug 653471: Add -A to drizzle client
Merge Travis - 621861 = To change C structs to C++ classes in Drizzle

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*****************************************************************************
2
2
 
3
 
Copyright (C) 1995, 2010, Innobase Oy. All Rights Reserved.
4
 
Copyright (C) 2008, Google Inc.
 
3
Copyright (c) 1995, 2009, Innobase Oy. All Rights Reserved.
 
4
Copyright (c) 2008, Google Inc.
5
5
 
6
6
Portions of this file contain modifications contributed and copyrighted by
7
7
Google, Inc. Those modifications are gratefully acknowledged and are described
105
105
set only when UNIV_SYNC_PERF_STAT is defined */
106
106
extern  ib_int64_t      rw_x_exit_count;
107
107
 
108
 
#ifdef UNIV_PFS_RWLOCK
109
 
/* Following are rwlock keys used to register with MySQL
110
 
performance schema */
111
 
# ifdef UNIV_LOG_ARCHIVE
112
 
extern  mysql_pfs_key_t archive_lock_key;
113
 
# endif /* UNIV_LOG_ARCHIVE */
114
 
extern  mysql_pfs_key_t btr_search_latch_key;
115
 
extern  mysql_pfs_key_t buf_block_lock_key;
116
 
# ifdef UNIV_SYNC_DEBUG
117
 
extern  mysql_pfs_key_t buf_block_debug_latch_key;
118
 
# endif /* UNIV_SYNC_DEBUG */
119
 
extern  mysql_pfs_key_t dict_operation_lock_key;
120
 
extern  mysql_pfs_key_t fil_space_latch_key;
121
 
extern  mysql_pfs_key_t checkpoint_lock_key;
122
 
extern  mysql_pfs_key_t trx_i_s_cache_lock_key;
123
 
extern  mysql_pfs_key_t trx_purge_latch_key;
124
 
extern  mysql_pfs_key_t index_tree_rw_lock_key;
125
 
#endif /* UNIV_PFS_RWLOCK */
126
 
 
127
 
 
128
 
#ifndef UNIV_PFS_RWLOCK
129
108
/******************************************************************//**
130
109
Creates, or rather, initializes an rw-lock object in a specified memory
131
110
location (which must be appropriately aligned). The rw-lock is initialized
132
111
to the non-locked state. Explicit freeing of the rw-lock with rw_lock_free
133
 
is necessary only if the memory block containing it is freed.
134
 
if MySQL performance schema is enabled and "UNIV_PFS_RWLOCK" is
135
 
defined, the rwlock are instrumented with performance schema probes. */
136
 
# ifdef UNIV_DEBUG
137
 
#  ifdef UNIV_SYNC_DEBUG
138
 
#   define rw_lock_create(K, L, level)                          \
 
112
is necessary only if the memory block containing it is freed. */
 
113
#ifdef UNIV_DEBUG
 
114
# ifdef UNIV_SYNC_DEBUG
 
115
#  define rw_lock_create(L, level)                                      \
139
116
        rw_lock_create_func((L), (level), #L, __FILE__, __LINE__)
140
 
#  else /* UNIV_SYNC_DEBUG */
141
 
#   define rw_lock_create(K, L, level)                          \
 
117
# else /* UNIV_SYNC_DEBUG */
 
118
#  define rw_lock_create(L, level)                                      \
142
119
        rw_lock_create_func((L), #L, __FILE__, __LINE__)
143
 
#  endif/* UNIV_SYNC_DEBUG */
144
 
# else /* UNIV_DEBUG */
145
 
#  define rw_lock_create(K, L, level)                           \
 
120
# endif /* UNIV_SYNC_DEBUG */
 
121
#else /* UNIV_DEBUG */
 
122
# define rw_lock_create(L, level)                                       \
146
123
        rw_lock_create_func((L), __FILE__, __LINE__)
147
 
# endif /* UNIV_DEBUG */
148
 
 
149
 
/**************************************************************//**
150
 
NOTE! The following macros should be used in rw locking and
151
 
unlocking, not the corresponding function. */
152
 
 
153
 
# define rw_lock_s_lock(M)                                      \
154
 
        rw_lock_s_lock_func((M), 0, __FILE__, __LINE__)
155
 
 
156
 
# define rw_lock_s_lock_gen(M, P)                               \
157
 
        rw_lock_s_lock_func((M), (P), __FILE__, __LINE__)
158
 
 
159
 
# define rw_lock_s_lock_nowait(M, F, L)                         \
160
 
        rw_lock_s_lock_low((M), 0, (F), (L))
161
 
 
162
 
# ifdef UNIV_SYNC_DEBUG
163
 
#  define rw_lock_s_unlock_gen(L, P)    rw_lock_s_unlock_func(P, L)
164
 
# else
165
 
#  define rw_lock_s_unlock_gen(L, P)    rw_lock_s_unlock_func(L)
166
 
# endif
167
 
 
168
 
 
169
 
# define rw_lock_x_lock(M)                                      \
170
 
        rw_lock_x_lock_func((M), 0, __FILE__, __LINE__)
171
 
 
172
 
# define rw_lock_x_lock_gen(M, P)                               \
173
 
        rw_lock_x_lock_func((M), (P), __FILE__, __LINE__)
174
 
 
175
 
# define rw_lock_x_lock_nowait(M)                               \
176
 
        rw_lock_x_lock_func_nowait((M), __FILE__, __LINE__)
177
 
 
178
 
# ifdef UNIV_SYNC_DEBUG
179
 
#  define rw_lock_x_unlock_gen(L, P)    rw_lock_x_unlock_func(P, L)
180
 
# else
181
 
#  define rw_lock_x_unlock_gen(L, P)    rw_lock_x_unlock_func(L)
182
 
# endif
183
 
 
184
 
# define rw_lock_free(M)                rw_lock_free_func(M)
185
 
 
186
 
#else /* !UNIV_PFS_RWLOCK */
187
 
 
188
 
/* Following macros point to Performance Schema instrumented functions. */
189
 
# ifdef UNIV_DEBUG
190
 
#  ifdef UNIV_SYNC_DEBUG
191
 
#   define rw_lock_create(K, L, level)                          \
192
 
        pfs_rw_lock_create_func((K), (L), (level), #L, __FILE__, __LINE__)
193
 
#  else /* UNIV_SYNC_DEBUG */
194
 
#   define rw_lock_create(K, L, level)                          \
195
 
        pfs_rw_lock_create_func((K), (L), #L, __FILE__, __LINE__)
196
 
#  endif/* UNIV_SYNC_DEBUG */
197
 
# else  /* UNIV_DEBUG */
198
 
#  define rw_lock_create(K, L, level)                           \
199
 
        pfs_rw_lock_create_func((K), (L), __FILE__, __LINE__)
200
 
# endif /* UNIV_DEBUG */
201
 
 
202
 
/******************************************************************
203
 
NOTE! The following macros should be used in rw locking and
204
 
unlocking, not the corresponding function. */
205
 
 
206
 
# define rw_lock_s_lock(M)                                      \
207
 
        pfs_rw_lock_s_lock_func((M), 0, __FILE__, __LINE__)
208
 
 
209
 
# define rw_lock_s_lock_gen(M, P)                               \
210
 
        pfs_rw_lock_s_lock_func((M), (P), __FILE__, __LINE__)
211
 
 
212
 
# define rw_lock_s_lock_nowait(M, F, L)                         \
213
 
        pfs_rw_lock_s_lock_low((M), 0, (F), (L))
214
 
 
215
 
# ifdef UNIV_SYNC_DEBUG
216
 
#  define rw_lock_s_unlock_gen(L, P)    pfs_rw_lock_s_unlock_func(P, L)
217
 
# else
218
 
#  define rw_lock_s_unlock_gen(L, P)    pfs_rw_lock_s_unlock_func(L)
219
 
# endif
220
 
 
221
 
# define rw_lock_x_lock(M)                                      \
222
 
        pfs_rw_lock_x_lock_func((M), 0, __FILE__, __LINE__)
223
 
 
224
 
# define rw_lock_x_lock_gen(M, P)                               \
225
 
        pfs_rw_lock_x_lock_func((M), (P), __FILE__, __LINE__)
226
 
 
227
 
# define rw_lock_x_lock_nowait(M)                               \
228
 
        pfs_rw_lock_x_lock_func_nowait((M), __FILE__, __LINE__)
229
 
 
230
 
# ifdef UNIV_SYNC_DEBUG
231
 
#  define rw_lock_x_unlock_gen(L, P)    pfs_rw_lock_x_unlock_func(P, L)
232
 
# else
233
 
#  define rw_lock_x_unlock_gen(L, P)    pfs_rw_lock_x_unlock_func(L)
234
 
# endif
235
 
 
236
 
# define rw_lock_free(M)                pfs_rw_lock_free_func(M)
237
 
 
238
 
#endif /* UNIV_PFS_RWLOCK */
239
 
 
240
 
#define rw_lock_s_unlock(L)             rw_lock_s_unlock_gen(L, 0)
241
 
#define rw_lock_x_unlock(L)             rw_lock_x_unlock_gen(L, 0)
 
124
#endif /* UNIV_DEBUG */
242
125
 
243
126
/******************************************************************//**
244
127
Creates, or rather, initializes an rw-lock object in a specified memory
254
137
# ifdef UNIV_SYNC_DEBUG
255
138
        ulint           level,          /*!< in: level */
256
139
# endif /* UNIV_SYNC_DEBUG */
257
 
        const char*     cmutex_name,    /*!< in: mutex name */
 
140
        const char*     cmutex_name,    /*!< in: mutex name */
258
141
#endif /* UNIV_DEBUG */
259
142
        const char*     cfile_name,     /*!< in: file name where created */
260
 
        ulint           cline);         /*!< in: file line where created */
 
143
        ulint           cline);         /*!< in: file line where created */
261
144
/******************************************************************//**
262
145
Calling this function is obligatory only if the memory buffer containing
263
146
the rw-lock is freed. Removes an rw-lock object from the global list. The
264
147
rw-lock is checked to be in the non-locked state. */
265
148
UNIV_INTERN
266
149
void
267
 
rw_lock_free_func(
268
 
/*==============*/
 
150
rw_lock_free(
 
151
/*=========*/
269
152
        rw_lock_t*      lock);  /*!< in: rw-lock */
270
153
#ifdef UNIV_DEBUG
271
154
/******************************************************************//**
278
161
/*=============*/
279
162
        rw_lock_t*      lock);  /*!< in: rw-lock */
280
163
#endif /* UNIV_DEBUG */
 
164
/**************************************************************//**
 
165
NOTE! The following macros should be used in rw s-locking, not the
 
166
corresponding function. */
 
167
 
 
168
#define rw_lock_s_lock(M)       rw_lock_s_lock_func(\
 
169
                (M), 0, __FILE__, __LINE__)
 
170
/**************************************************************//**
 
171
NOTE! The following macros should be used in rw s-locking, not the
 
172
corresponding function. */
 
173
 
 
174
#define rw_lock_s_lock_gen(M, P)        rw_lock_s_lock_func(\
 
175
                (M), (P), __FILE__, __LINE__)
 
176
/**************************************************************//**
 
177
NOTE! The following macros should be used in rw s-locking, not the
 
178
corresponding function. */
 
179
 
 
180
#define rw_lock_s_lock_nowait(M, F, L)    rw_lock_s_lock_low(\
 
181
                                          (M), 0, (F), (L))
281
182
/******************************************************************//**
282
183
Low-level function which tries to lock an rw-lock in s-mode. Performs no
283
184
spinning.
287
188
rw_lock_s_lock_low(
288
189
/*===============*/
289
190
        rw_lock_t*      lock,   /*!< in: pointer to rw-lock */
290
 
        ulint           /*pass __attribute__((unused))*/,
 
191
        ulint           pass __attribute__((unused)),
291
192
                                /*!< in: pass value; != 0, if the lock will be
292
193
                                passed to another thread to unlock */
293
194
        const char*     file_name, /*!< in: file name where lock requested */
332
233
#endif
333
234
        rw_lock_t*      lock);  /*!< in/out: rw-lock */
334
235
 
 
236
#ifdef UNIV_SYNC_DEBUG
 
237
# define rw_lock_s_unlock_gen(L, P)     rw_lock_s_unlock_func(P, L)
 
238
#else
 
239
# define rw_lock_s_unlock_gen(L, P)     rw_lock_s_unlock_func(L)
 
240
#endif
 
241
/*******************************************************************//**
 
242
Releases a shared mode lock. */
 
243
#define rw_lock_s_unlock(L)             rw_lock_s_unlock_gen(L, 0)
 
244
 
 
245
/**************************************************************//**
 
246
NOTE! The following macro should be used in rw x-locking, not the
 
247
corresponding function. */
 
248
 
 
249
#define rw_lock_x_lock(M)       rw_lock_x_lock_func(\
 
250
                (M), 0, __FILE__, __LINE__)
 
251
/**************************************************************//**
 
252
NOTE! The following macro should be used in rw x-locking, not the
 
253
corresponding function. */
 
254
 
 
255
#define rw_lock_x_lock_gen(M, P)        rw_lock_x_lock_func(\
 
256
                (M), (P), __FILE__, __LINE__)
 
257
/**************************************************************//**
 
258
NOTE! The following macros should be used in rw x-locking, not the
 
259
corresponding function. */
 
260
 
 
261
#define rw_lock_x_lock_nowait(M)        rw_lock_x_lock_func_nowait(\
 
262
                (M), __FILE__, __LINE__)
335
263
/******************************************************************//**
336
264
NOTE! Use the corresponding macro, not directly this function! Lock an
337
265
rw-lock in exclusive mode for the current thread. If the rw-lock is locked
362
290
#endif
363
291
        rw_lock_t*      lock);  /*!< in/out: rw-lock */
364
292
 
 
293
#ifdef UNIV_SYNC_DEBUG
 
294
# define rw_lock_x_unlock_gen(L, P)     rw_lock_x_unlock_func(P, L)
 
295
#else
 
296
# define rw_lock_x_unlock_gen(L, P)     rw_lock_x_unlock_func(L)
 
297
#endif
 
298
/*******************************************************************//**
 
299
Releases an exclusive mode lock. */
 
300
#define rw_lock_x_unlock(L)             rw_lock_x_unlock_gen(L, 0)
365
301
 
366
302
/******************************************************************//**
367
303
Low-level function which locks an rw-lock in s-mode when we know that it
493
429
rw_lock_own(
494
430
/*========*/
495
431
        rw_lock_t*      lock,           /*!< in: rw-lock */
496
 
        ulint           lock_type)      /*!< in: lock type: RW_LOCK_SHARED,
 
432
        ulint           lock_type);     /*!< in: lock type: RW_LOCK_SHARED,
497
433
                                        RW_LOCK_EX */
498
 
        __attribute__((warn_unused_result));
499
434
#endif /* UNIV_SYNC_DEBUG */
500
435
/******************************************************************//**
501
436
Checks if somebody has locked the rw-lock in the specified mode. */
604
539
                                info list of the lock */
605
540
        ulint   level;          /*!< Level in the global latching order. */
606
541
#endif /* UNIV_SYNC_DEBUG */
607
 
#ifdef UNIV_PFS_RWLOCK
608
 
        struct PSI_rwlock *pfs_psi;/*!< The instrumentation hook */
609
 
#endif
610
542
        ulint count_os_wait;    /*!< Count of os_waits. May not be accurate */
611
543
        const char*     cfile_name;/*!< File name where lock created */
612
544
        /* last s-lock file/line is not guaranteed to be correct */
622
554
        unsigned        cline:14;       /*!< Line where created */
623
555
        unsigned        last_s_line:14; /*!< Line number where last time s-locked */
624
556
        unsigned        last_x_line:14; /*!< Line number where last time x-locked */
625
 
#ifdef UNIV_DEBUG
626
557
        ulint   magic_n;        /*!< RW_LOCK_MAGIC_N */
 
558
};
 
559
 
627
560
/** Value of rw_lock_struct::magic_n */
628
561
#define RW_LOCK_MAGIC_N 22643
629
 
#endif /* UNIV_DEBUG */
630
 
};
631
562
 
632
563
#ifdef UNIV_SYNC_DEBUG
633
564
/** The structure for storing debug info of an rw-lock */
646
577
};
647
578
#endif /* UNIV_SYNC_DEBUG */
648
579
 
649
 
/* For performance schema instrumentation, a new set of rwlock
650
 
wrap functions are created if "UNIV_PFS_RWLOCK" is defined.
651
 
The instrumentations are not planted directly into original
652
 
functions, so that we keep the underlying function as they
653
 
are. And in case, user wants to "take out" some rwlock from
654
 
instrumentation even if performance schema (UNIV_PFS_RWLOCK)
655
 
is defined, they can do so by reinstating APIs directly link to
656
 
original underlying functions.
657
 
The instrumented function names have prefix of "pfs_rw_lock_" vs.
658
 
original name prefix of "rw_lock_". Following are list of functions
659
 
that have been instrumented:
660
 
 
661
 
rw_lock_create()
662
 
rw_lock_x_lock()
663
 
rw_lock_x_lock_gen()
664
 
rw_lock_x_lock_nowait()
665
 
rw_lock_x_unlock_gen()
666
 
rw_lock_s_lock()
667
 
rw_lock_s_lock_gen()
668
 
rw_lock_s_lock_nowait()
669
 
rw_lock_s_unlock_gen()
670
 
rw_lock_free()
671
 
 
672
 
Two function APIs rw_lock_x_unlock_direct() and rw_lock_s_unlock_direct()
673
 
do not have any caller/user, they are not instrumented.
674
 
*/
675
 
 
676
 
#ifdef UNIV_PFS_RWLOCK
677
 
/******************************************************************//**
678
 
Performance schema instrumented wrap function for rw_lock_create_func()
679
 
NOTE! Please use the corresponding macro rw_lock_create(), not
680
 
directly this function! */
681
 
UNIV_INLINE
682
 
void
683
 
pfs_rw_lock_create_func(
684
 
/*====================*/
685
 
        PSI_rwlock_key  key,            /*!< in: key registered with
686
 
                                        performance schema */
687
 
        rw_lock_t*      lock,           /*!< in: rw lock */
688
 
#ifdef UNIV_DEBUG
689
 
# ifdef UNIV_SYNC_DEBUG
690
 
        ulint           level,          /*!< in: level */
691
 
# endif /* UNIV_SYNC_DEBUG */
692
 
        const char*     cmutex_name,    /*!< in: mutex name */
693
 
#endif /* UNIV_DEBUG */
694
 
        const char*     cfile_name,     /*!< in: file name where created */
695
 
        ulint           cline);         /*!< in: file line where created */
696
 
 
697
 
/******************************************************************//**
698
 
Performance schema instrumented wrap function for rw_lock_x_lock_func()
699
 
NOTE! Please use the corresponding macro rw_lock_x_lock(), not
700
 
directly this function! */
701
 
UNIV_INLINE
702
 
void
703
 
pfs_rw_lock_x_lock_func(
704
 
/*====================*/
705
 
        rw_lock_t*      lock,   /*!< in: pointer to rw-lock */
706
 
        ulint           pass,   /*!< in: pass value; != 0, if the lock will
707
 
                                be passed to another thread to unlock */
708
 
        const char*     file_name,/*!< in: file name where lock requested */
709
 
        ulint           line);  /*!< in: line where requested */
710
 
/******************************************************************//**
711
 
Performance schema instrumented wrap function for
712
 
rw_lock_x_lock_func_nowait()
713
 
NOTE! Please use the corresponding macro, not directly this function!
714
 
@return TRUE if success */
715
 
UNIV_INLINE
716
 
ibool
717
 
pfs_rw_lock_x_lock_func_nowait(
718
 
/*===========================*/
719
 
        rw_lock_t*      lock,   /*!< in: pointer to rw-lock */
720
 
        const char*     file_name,/*!< in: file name where lock requested */
721
 
        ulint           line);  /*!< in: line where requested */
722
 
/******************************************************************//**
723
 
Performance schema instrumented wrap function for rw_lock_s_lock_func()
724
 
NOTE! Please use the corresponding macro rw_lock_s_lock(), not directly
725
 
this function! */
726
 
UNIV_INLINE
727
 
void
728
 
pfs_rw_lock_s_lock_func(
729
 
/*====================*/
730
 
        rw_lock_t*      lock,   /*!< in: pointer to rw-lock */
731
 
        ulint           pass,   /*!< in: pass value; != 0, if the lock will
732
 
                                be passed to another thread to unlock */
733
 
        const char*     file_name,/*!< in: file name where lock requested */
734
 
        ulint           line);  /*!< in: line where requested */
735
 
/******************************************************************//**
736
 
Performance schema instrumented wrap function for rw_lock_s_lock_func()
737
 
NOTE! Please use the corresponding macro rw_lock_s_lock(), not directly
738
 
this function!
739
 
@return TRUE if success */
740
 
UNIV_INLINE
741
 
ibool
742
 
pfs_rw_lock_s_lock_low(
743
 
/*===================*/
744
 
        rw_lock_t*      lock,   /*!< in: pointer to rw-lock */
745
 
        ulint           pass,   /*!< in: pass value; != 0, if the
746
 
                                lock will be passed to another
747
 
                                thread to unlock */
748
 
        const char*     file_name, /*!< in: file name where lock requested */
749
 
        ulint           line);  /*!< in: line where requested */
750
 
/******************************************************************//**
751
 
Performance schema instrumented wrap function for rw_lock_x_lock_func()
752
 
NOTE! Please use the corresponding macro rw_lock_x_lock(), not directly
753
 
this function! */
754
 
UNIV_INLINE
755
 
void
756
 
pfs_rw_lock_x_lock_func(
757
 
/*====================*/
758
 
        rw_lock_t*      lock,   /*!< in: pointer to rw-lock */
759
 
        ulint           pass,   /*!< in: pass value; != 0, if the lock will
760
 
                                be passed to another thread to unlock */
761
 
        const char*     file_name,/*!< in: file name where lock requested */
762
 
        ulint           line);  /*!< in: line where requested */
763
 
/******************************************************************//**
764
 
Performance schema instrumented wrap function for rw_lock_s_unlock_func()
765
 
NOTE! Please use the corresponding macro rw_lock_s_unlock(), not directly
766
 
this function! */
767
 
UNIV_INLINE
768
 
void
769
 
pfs_rw_lock_s_unlock_func(
770
 
/*======================*/
771
 
#ifdef UNIV_SYNC_DEBUG
772
 
        ulint           pass,   /*!< in: pass value; != 0, if the
773
 
                                lock may have been passed to another
774
 
                                thread to unlock */
775
 
#endif
776
 
        rw_lock_t*      lock);  /*!< in/out: rw-lock */
777
 
/******************************************************************//**
778
 
Performance schema instrumented wrap function for rw_lock_s_unlock_func()
779
 
NOTE! Please use the corresponding macro rw_lock_x_unlock(), not directly
780
 
this function! */
781
 
UNIV_INLINE
782
 
void
783
 
pfs_rw_lock_x_unlock_func(
784
 
/*======================*/
785
 
#ifdef UNIV_SYNC_DEBUG
786
 
        ulint           pass,   /*!< in: pass value; != 0, if the
787
 
                                lock may have been passed to another
788
 
                                thread to unlock */
789
 
#endif
790
 
        rw_lock_t*      lock);  /*!< in/out: rw-lock */
791
 
/******************************************************************//**
792
 
Performance schema instrumented wrap function for rw_lock_free_func()
793
 
NOTE! Please use the corresponding macro rw_lock_free(), not directly
794
 
this function! */
795
 
UNIV_INLINE
796
 
void
797
 
pfs_rw_lock_free_func(
798
 
/*==================*/
799
 
        rw_lock_t*      lock);  /*!< in: rw-lock */
800
 
#endif  /* UNIV_PFS_RWLOCK */
801
 
 
802
 
 
803
580
#ifndef UNIV_NONINL
804
581
#include "sync0rw.ic"
805
582
#endif