~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/innobase/include/sync0sync.h

  • Committer: Brian Aker
  • Date: 2008-11-04 15:39:09 UTC
  • mfrom: (575.1.2 devel)
  • Revision ID: brian@tangent.org-20081104153909-c72hn65udxs1ccal
Merge of Monty's work

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
#include "os0sync.h"
18
18
#include "sync0arr.h"
19
19
 
20
 
#ifndef UNIV_HOTBACKUP
21
 
extern bool     timed_mutexes;
22
 
#endif /* UNIV_HOTBACKUP */
23
20
 
24
21
/**********************************************************************
25
22
Initializes the synchronization data structures. */
26
 
 
 
23
UNIV_INTERN
27
24
void
28
25
sync_init(void);
29
26
/*===========*/
30
27
/**********************************************************************
31
28
Frees the resources in synchronization data structures. */
32
 
 
 
29
UNIV_INTERN
33
30
void
34
31
sync_close(void);
35
32
/*===========*/
57
54
location (which must be appropriately aligned). The mutex is initialized
58
55
in the reset state. Explicit freeing of the mutex with mutex_free is
59
56
necessary only if the memory block containing it is freed. */
60
 
 
 
57
UNIV_INTERN
61
58
void
62
59
mutex_create_func(
63
60
/*==============*/
70
67
#endif /* UNIV_DEBUG */
71
68
        const char*     cfile_name,     /* in: file name where created */
72
69
        ulint           cline);         /* in: file line where created */
 
70
 
 
71
#undef mutex_free                       /* Fix for MacOS X */
 
72
 
73
73
/**********************************************************************
74
74
Calling this function is obligatory only if the memory buffer containing
75
75
the mutex is freed. Removes a mutex object from the mutex list. The mutex
76
76
is checked to be in the reset state. */
77
 
 
78
 
#undef mutex_free                       /* Fix for MacOS X */
 
77
UNIV_INTERN
79
78
void
80
79
mutex_free(
81
80
/*=======*/
85
84
corresponding function. */
86
85
 
87
86
#define mutex_enter(M)    mutex_enter_func((M), __FILE__, __LINE__)
88
 
/**********************************************************************
89
 
A noninlined function that reserves a mutex. In ha_innodb.cc we have disabled
90
 
inlining of InnoDB functions, and no inlined functions should be called from
91
 
there. That is why we need to duplicate the inlined function here. */
92
 
 
93
 
void
94
 
mutex_enter_noninline(
95
 
/*==================*/
96
 
        mutex_t*        mutex); /* in: mutex */
97
87
/******************************************************************
98
88
NOTE! The following macro should be used in mutex locking, not the
99
89
corresponding function. */
101
91
/* NOTE! currently same as mutex_enter! */
102
92
 
103
93
#define mutex_enter_fast(M)     mutex_enter_func((M), __FILE__, __LINE__)
104
 
#define mutex_enter_fast_func   mutex_enter_func;
105
94
/**********************************************************************
106
95
NOTE! Use the corresponding macro in the header file, not this function
107
96
directly. Locks a mutex for the current thread. If the mutex is reserved
124
113
NOTE! Use the corresponding macro in the header file, not this function
125
114
directly. Tries to lock the mutex for the current thread. If the lock is not
126
115
acquired immediately, returns with return value 1. */
127
 
 
 
116
UNIV_INTERN
128
117
ulint
129
118
mutex_enter_nowait_func(
130
119
/*====================*/
141
130
/*=======*/
142
131
        mutex_t*        mutex); /* in: pointer to mutex */
143
132
/**********************************************************************
144
 
Releases a mutex. */
145
 
 
146
 
void
147
 
mutex_exit_noninline(
148
 
/*=================*/
149
 
        mutex_t*        mutex); /* in: mutex */
150
 
/**********************************************************************
151
133
Returns TRUE if no mutex or rw-lock is currently locked.
152
134
Works only in the debug version. */
153
 
 
 
135
UNIV_INTERN
154
136
ibool
155
137
sync_all_freed(void);
156
138
/*================*/
158
140
FUNCTION PROTOTYPES FOR DEBUGGING */
159
141
/***********************************************************************
160
142
Prints wait info of the sync system. */
161
 
 
 
143
UNIV_INTERN
162
144
void
163
145
sync_print_wait_info(
164
146
/*=================*/
165
147
        FILE*   file);          /* in: file where to print */
166
148
/***********************************************************************
167
149
Prints info of the sync system. */
168
 
 
 
150
UNIV_INTERN
169
151
void
170
152
sync_print(
171
153
/*=======*/
173
155
#ifdef UNIV_DEBUG
174
156
/**********************************************************************
175
157
Checks that the mutex has been initialized. */
176
 
 
 
158
UNIV_INTERN
177
159
ibool
178
160
mutex_validate(
179
161
/*===========*/
181
163
/**********************************************************************
182
164
Checks that the current thread owns the mutex. Works only
183
165
in the debug version. */
184
 
 
 
166
UNIV_INTERN
185
167
ibool
186
168
mutex_own(
187
169
/*======*/
193
175
Adds a latch and its level in the thread level array. Allocates the memory
194
176
for the array if called first time for this OS thread. Makes the checks
195
177
against other latch levels stored in the array for this thread. */
196
 
 
 
178
UNIV_INTERN
197
179
void
198
180
sync_thread_add_level(
199
181
/*==================*/
202
184
                        SYNC_LEVEL_VARYING, nothing is done */
203
185
/**********************************************************************
204
186
Removes a latch from the thread level array if it is found there. */
205
 
 
 
187
UNIV_INTERN
206
188
ibool
207
189
sync_thread_reset_level(
208
190
/*====================*/
213
195
        void*   latch); /* in: pointer to a mutex or an rw-lock */
214
196
/**********************************************************************
215
197
Checks that the level array for the current thread is empty. */
216
 
 
 
198
UNIV_INTERN
217
199
ibool
218
200
sync_thread_levels_empty(void);
219
201
/*==========================*/
220
202
                        /* out: TRUE if empty */
221
203
/**********************************************************************
222
204
Checks that the level array for the current thread is empty. */
223
 
 
 
205
UNIV_INTERN
224
206
ibool
225
207
sync_thread_levels_empty_gen(
226
208
/*=========================*/
232
214
                                        allowed */
233
215
/**********************************************************************
234
216
Gets the debug information for a reserved mutex. */
235
 
 
 
217
UNIV_INTERN
236
218
void
237
219
mutex_get_debug_info(
238
220
/*=================*/
243
225
                                        the mutex */
244
226
/**********************************************************************
245
227
Counts currently reserved mutexes. Works only in the debug version. */
246
 
 
 
228
UNIV_INTERN
247
229
ulint
248
230
mutex_n_reserved(void);
249
231
/*==================*/
400
382
                                        their level set after the page is
401
383
                                        locked; see e.g.
402
384
                                        ibuf_bitmap_get_map_page(). */
 
385
#define SYNC_TRX_I_S_RWLOCK     1910    /* Used for
 
386
                                        trx_i_s_cache_t::rw_lock */
 
387
#define SYNC_TRX_I_S_LAST_READ  1900    /* Used for
 
388
                                        trx_i_s_cache_t::last_read_mutex */
 
389
#define SYNC_FILE_FORMAT_TAG    1200    /* Used to serialize access to the
 
390
                                        file format tag */
403
391
#define SYNC_DICT_OPERATION     1001    /* table create, drop, etc. reserve
404
392
                                        this in X-mode, implicit or backround
405
393
                                        operations purge, rollback, foreign
470
458
implementation of a mutual exclusion semaphore. */
471
459
 
472
460
struct mutex_struct {
 
461
        os_event_t      event;  /* Used by sync0arr.c for the wait queue */
473
462
        ulint   lock_word;      /* This ulint is the target of the atomic
474
463
                                test-and-set instruction in Win32 */
475
 
#if !defined(_WIN32) || !defined(UNIV_CAN_USE_X86_ASSEMBLER)
 
464
#if defined WIN32 && defined UNIV_CAN_USE_X86_ASSEMBLER
 
465
#else
476
466
        os_fast_mutex_t
477
467
                os_fast_mutex;  /* In other systems we use this OS mutex
478
468
                                in place of lock_word */
503
493
        ulong           count_spin_loop; /* count of spin loops */
504
494
        ulong           count_spin_rounds; /* count of spin rounds */
505
495
        ulong           count_os_yield; /* count of os_wait */
506
 
        uint64_t        lspent_time; /* mutex os_wait timer msec */
507
 
        uint64_t        lmax_spent_time; /* mutex os_wait timer msec */
 
496
        ulonglong       lspent_time; /* mutex os_wait timer msec */
 
497
        ulonglong       lmax_spent_time; /* mutex os_wait timer msec */
508
498
        const char*     cmutex_name;/* mutex name */
509
499
        ulint           mutex_type;/* 0 - usual mutex 1 - rw_lock mutex  */
510
500
# endif /* UNIV_DEBUG */