~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/innobase/sync/sync0rw.cc

  • Committer: Monty Taylor
  • Date: 2011-02-13 17:26:39 UTC
  • mfrom: (2157.2.2 give-in-to-pkg-config)
  • mto: This revision was merged to the branch mainline in revision 2166.
  • Revision ID: mordred@inaugust.com-20110213172639-nhy7i72sfhoq13ms
Merged in pkg-config fixes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*****************************************************************************
2
2
 
3
 
Copyright (c) 1995, 2009, 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
18
18
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
19
19
 
20
20
You should have received a copy of the GNU General Public License along with
21
 
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
22
 
Place, Suite 330, Boston, MA 02111-1307 USA
 
21
this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
 
22
St, Fifth Floor, Boston, MA 02110-1301 USA
23
23
 
24
24
*****************************************************************************/
25
25
 
38
38
#include "os0thread.h"
39
39
#include "mem0mem.h"
40
40
#include "srv0srv.h"
 
41
#include "os0sync.h" /* for INNODB_RW_LOCKS_USE_ATOMICS */
41
42
 
42
43
/*
43
44
        IMPLEMENTATION OF THE RW_LOCK
167
168
UNIV_INTERN rw_lock_list_t      rw_lock_list;
168
169
UNIV_INTERN mutex_t             rw_lock_list_mutex;
169
170
 
 
171
#ifdef UNIV_PFS_MUTEX
 
172
UNIV_INTERN mysql_pfs_key_t     rw_lock_list_mutex_key;
 
173
UNIV_INTERN mysql_pfs_key_t     rw_lock_mutex_key;
 
174
#endif /* UNIV_PFS_MUTEX */
 
175
 
170
176
#ifdef UNIV_SYNC_DEBUG
171
177
/* The global mutex which protects debug info lists of all rw-locks.
172
178
To modify the debug info list of an rw-lock, this mutex has to be
173
179
acquired in addition to the mutex protecting the lock. */
174
180
 
175
181
UNIV_INTERN mutex_t             rw_lock_debug_mutex;
 
182
 
 
183
# ifdef UNIV_PFS_MUTEX
 
184
UNIV_INTERN mysql_pfs_key_t     rw_lock_debug_mutex_key;
 
185
# endif
 
186
 
176
187
/* If deadlock detection does not get immediately the mutex,
177
188
it may wait for this event */
178
189
UNIV_INTERN os_event_t          rw_lock_debug_event;
230
241
# ifdef UNIV_SYNC_DEBUG
231
242
        ulint           level,          /*!< in: level */
232
243
# endif /* UNIV_SYNC_DEBUG */
233
 
        const char*     cmutex_name,    /*!< in: mutex name */
 
244
        const char*     cmutex_name,    /*!< in: mutex name */
234
245
#endif /* UNIV_DEBUG */
235
246
        const char*     cfile_name,     /*!< in: file name where created */
236
247
        ulint           cline)          /*!< in: file line where created */
239
250
        created, then the following call initializes the sync system. */
240
251
 
241
252
#ifndef INNODB_RW_LOCKS_USE_ATOMICS
242
 
        mutex_create(rw_lock_get_mutex(lock), SYNC_NO_ORDER_CHECK);
 
253
        mutex_create(rw_lock_mutex_key, rw_lock_get_mutex(lock),
 
254
                     SYNC_NO_ORDER_CHECK);
243
255
 
244
256
        lock->mutex.cfile_name = cfile_name;
245
257
        lock->mutex.cline = cline;
266
278
        lock->level = level;
267
279
#endif /* UNIV_SYNC_DEBUG */
268
280
 
269
 
        lock->magic_n = RW_LOCK_MAGIC_N;
 
281
        ut_d(lock->magic_n = RW_LOCK_MAGIC_N);
270
282
 
271
283
        lock->cfile_name = cfile_name;
272
284
        lock->cline = (unsigned int) cline;
281
293
 
282
294
        mutex_enter(&rw_lock_list_mutex);
283
295
 
284
 
        if (UT_LIST_GET_LEN(rw_lock_list) > 0) {
285
 
                ut_a(UT_LIST_GET_FIRST(rw_lock_list)->magic_n
286
 
                     == RW_LOCK_MAGIC_N);
287
 
        }
 
296
        ut_ad(UT_LIST_GET_FIRST(rw_lock_list) == NULL
 
297
              || UT_LIST_GET_FIRST(rw_lock_list)->magic_n == RW_LOCK_MAGIC_N);
288
298
 
289
299
        UT_LIST_ADD_FIRST(list, rw_lock_list, lock);
290
300
 
297
307
rw-lock is checked to be in the non-locked state. */
298
308
UNIV_INTERN
299
309
void
300
 
rw_lock_free(
301
 
/*=========*/
 
310
rw_lock_free_func(
 
311
/*==============*/
302
312
        rw_lock_t*      lock)   /*!< in: rw-lock */
303
313
{
304
314
        ut_ad(rw_lock_validate(lock));
305
315
        ut_a(lock->lock_word == X_LOCK_DECR);
306
316
 
307
 
        lock->magic_n = 0;
308
 
 
309
317
#ifndef INNODB_RW_LOCKS_USE_ATOMICS
310
318
        mutex_free(rw_lock_get_mutex(lock));
311
319
#endif /* INNODB_RW_LOCKS_USE_ATOMICS */
315
323
 
316
324
        os_event_free(lock->wait_ex_event);
317
325
 
318
 
        if (UT_LIST_GET_PREV(list, lock)) {
319
 
                ut_a(UT_LIST_GET_PREV(list, lock)->magic_n == RW_LOCK_MAGIC_N);
320
 
        }
321
 
        if (UT_LIST_GET_NEXT(list, lock)) {
322
 
                ut_a(UT_LIST_GET_NEXT(list, lock)->magic_n == RW_LOCK_MAGIC_N);
323
 
        }
 
326
        ut_ad(UT_LIST_GET_PREV(list, lock) == NULL
 
327
              || UT_LIST_GET_PREV(list, lock)->magic_n == RW_LOCK_MAGIC_N);
 
328
        ut_ad(UT_LIST_GET_NEXT(list, lock) == NULL
 
329
              || UT_LIST_GET_NEXT(list, lock)->magic_n == RW_LOCK_MAGIC_N);
324
330
 
325
331
        UT_LIST_REMOVE(list, rw_lock_list, lock);
326
332
 
327
333
        mutex_exit(&rw_lock_list_mutex);
 
334
 
 
335
        ut_d(lock->magic_n = 0);
328
336
}
329
337
 
330
338
#ifdef UNIV_DEBUG
338
346
/*=============*/
339
347
        rw_lock_t*      lock)   /*!< in: rw-lock */
340
348
{
 
349
        ulint   waiters;
 
350
        lint    lock_word;
 
351
 
341
352
        ut_a(lock);
342
353
 
343
 
        ulint waiters = rw_lock_get_waiters(lock);
344
 
        lint lock_word = lock->lock_word;
 
354
        waiters = rw_lock_get_waiters(lock);
 
355
        lock_word = lock->lock_word;
345
356
 
346
 
        ut_a(lock->magic_n == RW_LOCK_MAGIC_N);
 
357
        ut_ad(lock->magic_n == RW_LOCK_MAGIC_N);
347
358
        ut_a(waiters == 0 || waiters == 1);
348
359
        ut_a(lock_word > -X_LOCK_DECR ||(-lock_word) % X_LOCK_DECR == 0);
349
360
 
606
617
{
607
618
        ulint   index;  /*!< index of the reserved wait cell */
608
619
        ulint   i;      /*!< spin round count */
609
 
        ibool   spinning = FALSE;
 
620
        ibool   spinning = FALSE;
610
621
 
611
622
        ut_ad(rw_lock_validate(lock));
612
623
 
991
1002
 
992
1003
        rwt       = info->lock_type;
993
1004
 
994
 
        fprintf(stderr, "Locked: thread %ld file %s line %ld  ",
 
1005
        fprintf(stderr, "Locked: thread %lu file %s line %lu  ",
995
1006
                (ulong) os_thread_pf(info->thread_id), info->file_name,
996
1007
                (ulong) info->line);
997
1008
        if (rwt == RW_LOCK_SHARED) {