summaryrefslogtreecommitdiff
path: root/storage/xtradb/sync/sync0rw.c
diff options
context:
space:
mode:
Diffstat (limited to 'storage/xtradb/sync/sync0rw.c')
-rw-r--r--storage/xtradb/sync/sync0rw.c218
1 files changed, 112 insertions, 106 deletions
diff --git a/storage/xtradb/sync/sync0rw.c b/storage/xtradb/sync/sync0rw.c
index 09c732eefc9..07eac403dfe 100644
--- a/storage/xtradb/sync/sync0rw.c
+++ b/storage/xtradb/sync/sync0rw.c
@@ -23,7 +23,8 @@ Place, Suite 330, Boston, MA 02111-1307 USA
*****************************************************************************/
-/******************************************************
+/**************************************************//**
+@file sync/sync0rw.c
The read-write lock (for thread synchronization)
Created 9/11/1995 Heikki Tuuri
@@ -37,6 +38,7 @@ Created 9/11/1995 Heikki Tuuri
#include "os0thread.h"
#include "mem0mem.h"
#include "srv0srv.h"
+#include "os0sync.h" /* for INNODB_RW_LOCKS_USE_ATOMICS */
/*
IMPLEMENTATION OF THE RW_LOCK
@@ -132,29 +134,33 @@ wait_ex_event: A thread may only wait on the wait_ex_event after it has
*/
-/* number of spin waits on rw-latches,
+/** number of spin waits on rw-latches,
resulted during shared (read) locks */
UNIV_INTERN ib_int64_t rw_s_spin_wait_count = 0;
+/** number of spin loop rounds on rw-latches,
+resulted during shared (read) locks */
UNIV_INTERN ib_int64_t rw_s_spin_round_count = 0;
-/* number of OS waits on rw-latches,
+/** number of OS waits on rw-latches,
resulted during shared (read) locks */
UNIV_INTERN ib_int64_t rw_s_os_wait_count = 0;
-/* number of unlocks (that unlock shared locks),
+/** number of unlocks (that unlock shared locks),
set only when UNIV_SYNC_PERF_STAT is defined */
UNIV_INTERN ib_int64_t rw_s_exit_count = 0;
-/* number of spin waits on rw-latches,
+/** number of spin waits on rw-latches,
resulted during exclusive (write) locks */
UNIV_INTERN ib_int64_t rw_x_spin_wait_count = 0;
+/** number of spin loop rounds on rw-latches,
+resulted during exclusive (write) locks */
UNIV_INTERN ib_int64_t rw_x_spin_round_count = 0;
-/* number of OS waits on rw-latches,
+/** number of OS waits on rw-latches,
resulted during exclusive (write) locks */
UNIV_INTERN ib_int64_t rw_x_os_wait_count = 0;
-/* number of unlocks (that unlock exclusive locks),
+/** number of unlocks (that unlock exclusive locks),
set only when UNIV_SYNC_PERF_STAT is defined */
UNIV_INTERN ib_int64_t rw_x_exit_count = 0;
@@ -174,13 +180,13 @@ UNIV_INTERN os_event_t rw_lock_debug_event;
/* This is set to TRUE, if there may be waiters for the event */
UNIV_INTERN ibool rw_lock_debug_waiters;
-/**********************************************************************
+/******************************************************************//**
Creates a debug info struct. */
static
rw_lock_debug_t*
rw_lock_debug_create(void);
/*======================*/
-/**********************************************************************
+/******************************************************************//**
Frees a debug info struct. */
static
void
@@ -188,8 +194,9 @@ rw_lock_debug_free(
/*===============*/
rw_lock_debug_t* info);
-/**********************************************************************
-Creates a debug info struct. */
+/******************************************************************//**
+Creates a debug info struct.
+@return own: debug info struct */
static
rw_lock_debug_t*
rw_lock_debug_create(void)
@@ -198,7 +205,7 @@ rw_lock_debug_create(void)
return((rw_lock_debug_t*) mem_alloc(sizeof(rw_lock_debug_t)));
}
-/**********************************************************************
+/******************************************************************//**
Frees a debug info struct. */
static
void
@@ -210,7 +217,7 @@ rw_lock_debug_free(
}
#endif /* UNIV_SYNC_DEBUG */
-/**********************************************************************
+/******************************************************************//**
Creates, or rather, initializes an rw-lock object in a specified memory
location (which must be appropriately aligned). The rw-lock is initialized
to the non-locked state. Explicit freeing of the rw-lock with rw_lock_free
@@ -219,15 +226,15 @@ UNIV_INTERN
void
rw_lock_create_func(
/*================*/
- rw_lock_t* lock, /* in: pointer to memory */
+ rw_lock_t* lock, /*!< in: pointer to memory */
#ifdef UNIV_DEBUG
# ifdef UNIV_SYNC_DEBUG
- ulint level, /* in: level */
+ ulint level, /*!< in: level */
# endif /* UNIV_SYNC_DEBUG */
- const char* cmutex_name, /* in: mutex name */
#endif /* UNIV_DEBUG */
- const char* cfile_name, /* in: file name where created */
- ulint cline) /* in: file line where created */
+ const char* cmutex_name, /*!< in: mutex name */
+ const char* cfile_name, /*!< in: file name where created */
+ ulint cline) /*!< in: file line where created */
{
/* If this is the very first time a synchronization object is
created, then the following call initializes the sync system. */
@@ -235,17 +242,15 @@ rw_lock_create_func(
#ifndef INNODB_RW_LOCKS_USE_ATOMICS
mutex_create(rw_lock_get_mutex(lock), SYNC_NO_ORDER_CHECK);
- lock->mutex.cfile_name = cfile_name;
- lock->mutex.cline = cline;
+ ut_d(lock->mutex.cfile_name = cfile_name);
+ ut_d(lock->mutex.cline = cline);
-# if defined UNIV_DEBUG && !defined UNIV_HOTBACKUP
lock->mutex.cmutex_name = cmutex_name;
- lock->mutex.mutex_type = 1;
-# endif /* UNIV_DEBUG && !UNIV_HOTBACKUP */
-
+ ut_d(lock->mutex.mutex_type = 1);
#else /* INNODB_RW_LOCKS_USE_ATOMICS */
# ifdef UNIV_DEBUG
- UT_NOT_USED(cmutex_name);
+ UT_NOT_USED(cfile_name);
+ UT_NOT_USED(cline);
# endif
#endif /* INNODB_RW_LOCKS_USE_ATOMICS */
@@ -265,8 +270,7 @@ rw_lock_create_func(
lock->magic_n = RW_LOCK_MAGIC_N;
- lock->cfile_name = cfile_name;
- lock->cline = (unsigned int) cline;
+ lock->lock_name = cmutex_name;
lock->count_os_wait = 0;
lock->last_s_file_name = "not yet reserved";
@@ -288,7 +292,7 @@ rw_lock_create_func(
mutex_exit(&rw_lock_list_mutex);
}
-/**********************************************************************
+/******************************************************************//**
Calling this function is obligatory only if the memory buffer containing
the rw-lock is freed. Removes an rw-lock object from the global list. The
rw-lock is checked to be in the non-locked state. */
@@ -296,13 +300,11 @@ UNIV_INTERN
void
rw_lock_free(
/*=========*/
- rw_lock_t* lock) /* in: rw-lock */
+ rw_lock_t* lock) /*!< in: rw-lock */
{
ut_ad(rw_lock_validate(lock));
ut_a(lock->lock_word == X_LOCK_DECR);
- lock->magic_n = 0;
-
#ifndef INNODB_RW_LOCKS_USE_ATOMICS
mutex_free(rw_lock_get_mutex(lock));
#endif /* INNODB_RW_LOCKS_USE_ATOMICS */
@@ -322,17 +324,20 @@ rw_lock_free(
UT_LIST_REMOVE(list, rw_lock_list, lock);
mutex_exit(&rw_lock_list_mutex);
+
+ lock->magic_n = 0;
}
#ifdef UNIV_DEBUG
-/**********************************************************************
+/******************************************************************//**
Checks that the rw-lock has been initialized and that there are no
-simultaneous shared and exclusive locks. */
+simultaneous shared and exclusive locks.
+@return TRUE */
UNIV_INTERN
ibool
rw_lock_validate(
/*=============*/
- rw_lock_t* lock)
+ rw_lock_t* lock) /*!< in: rw-lock */
{
ut_a(lock);
@@ -347,7 +352,7 @@ rw_lock_validate(
}
#endif /* UNIV_DEBUG */
-/**********************************************************************
+/******************************************************************//**
Lock an rw-lock in shared mode for the current thread. If the rw-lock is
locked in exclusive mode, or there is an exclusive lock request waiting,
the function spins a preset time (controlled by SYNC_SPIN_ROUNDS), waiting
@@ -356,18 +361,18 @@ UNIV_INTERN
void
rw_lock_s_lock_spin(
/*================*/
- rw_lock_t* lock, /* in: pointer to rw-lock */
- ulint pass, /* in: pass value; != 0, if the lock
+ rw_lock_t* lock, /*!< in: pointer to rw-lock */
+ ulint pass, /*!< in: pass value; != 0, if the lock
will be passed to another thread to unlock */
- const char* file_name, /* in: file name where lock requested */
- ulint line) /* in: line where requested */
+ const char* file_name, /*!< in: file name where lock requested */
+ ulint line) /*!< in: line where requested */
{
ulint index; /* index of the reserved wait cell */
ulint i = 0; /* spin round count */
ut_ad(rw_lock_validate(lock));
- rw_s_spin_wait_count++; /* Count calls to this function */
+ rw_s_spin_wait_count++; /*!< Count calls to this function */
lock_loop:
/* Spin waiting for the writer field to become free */
@@ -386,10 +391,10 @@ lock_loop:
if (srv_print_latch_waits) {
fprintf(stderr,
"Thread %lu spin wait rw-s-lock at %p"
- " cfile %s cline %lu rnds %lu\n",
+ " '%s' rnds %lu\n",
(ulong) os_thread_pf(os_thread_get_curr_id()),
(void*) lock,
- lock->cfile_name, (ulong) lock->cline, (ulong) i);
+ lock->lock_name, (ulong) i);
}
/* We try once again to obtain the lock */
@@ -422,10 +427,9 @@ lock_loop:
if (srv_print_latch_waits) {
fprintf(stderr,
"Thread %lu OS wait rw-s-lock at %p"
- " cfile %s cline %lu\n",
+ " '%s'\n",
os_thread_pf(os_thread_get_curr_id()),
- (void*) lock, lock->cfile_name,
- (ulong) lock->cline);
+ (void*) lock, lock->lock_name);
}
/* these stats may not be accurate */
@@ -439,7 +443,7 @@ lock_loop:
}
}
-/**********************************************************************
+/******************************************************************//**
This function is used in the insert buffer to move the ownership of an
x-latch on a buffer frame to the current thread. The x-latch was set by
the buffer read operation and it protected the buffer frame while the
@@ -451,7 +455,7 @@ UNIV_INTERN
void
rw_lock_x_lock_move_ownership(
/*==========================*/
- rw_lock_t* lock) /* in: lock which was x-locked in the
+ rw_lock_t* lock) /*!< in: lock which was x-locked in the
buffer read */
{
ut_ad(rw_lock_is_locked(lock, RW_LOCK_EX));
@@ -459,20 +463,20 @@ rw_lock_x_lock_move_ownership(
rw_lock_set_writer_id_and_recursion_flag(lock, TRUE);
}
-/**********************************************************************
+/******************************************************************//**
Function for the next writer to call. Waits for readers to exit.
-The caller must have already decremented lock_word by X_LOCK_DECR.*/
+The caller must have already decremented lock_word by X_LOCK_DECR. */
UNIV_INLINE
void
rw_lock_x_lock_wait(
/*================*/
- rw_lock_t* lock, /* in: pointer to rw-lock */
+ rw_lock_t* lock, /*!< in: pointer to rw-lock */
#ifdef UNIV_SYNC_DEBUG
- ulint pass, /* in: pass value; != 0, if the lock will
+ ulint pass, /*!< in: pass value; != 0, if the lock will
be passed to another thread to unlock */
#endif
- const char* file_name,/* in: file name where lock requested */
- ulint line) /* in: line where requested */
+ const char* file_name,/*!< in: file name where lock requested */
+ ulint line) /*!< in: line where requested */
{
ulint index;
ulint i = 0;
@@ -527,19 +531,18 @@ rw_lock_x_lock_wait(
rw_x_spin_round_count += i;
}
-/**********************************************************************
-Low-level function for acquiring an exclusive lock. */
+/******************************************************************//**
+Low-level function for acquiring an exclusive lock.
+@return RW_LOCK_NOT_LOCKED if did not succeed, RW_LOCK_EX if success. */
UNIV_INLINE
ibool
rw_lock_x_lock_low(
/*===============*/
- /* out: RW_LOCK_NOT_LOCKED if did
- not succeed, RW_LOCK_EX if success. */
- rw_lock_t* lock, /* in: pointer to rw-lock */
- ulint pass, /* in: pass value; != 0, if the lock will
+ rw_lock_t* lock, /*!< in: pointer to rw-lock */
+ ulint pass, /*!< in: pass value; != 0, if the lock will
be passed to another thread to unlock */
- const char* file_name,/* in: file name where lock requested */
- ulint line) /* in: line where requested */
+ const char* file_name,/*!< in: file name where lock requested */
+ ulint line) /*!< in: line where requested */
{
os_thread_id_t curr_thread = os_thread_get_curr_id();
@@ -582,7 +585,7 @@ rw_lock_x_lock_low(
return(TRUE);
}
-/**********************************************************************
+/******************************************************************//**
NOTE! Use the corresponding macro, not directly this function! Lock an
rw-lock in exclusive mode for the current thread. If the rw-lock is locked
in shared or exclusive mode, or there is an exclusive lock request waiting,
@@ -595,14 +598,14 @@ UNIV_INTERN
void
rw_lock_x_lock_func(
/*================*/
- rw_lock_t* lock, /* in: pointer to rw-lock */
- ulint pass, /* in: pass value; != 0, if the lock will
+ rw_lock_t* lock, /*!< in: pointer to rw-lock */
+ ulint pass, /*!< in: pass value; != 0, if the lock will
be passed to another thread to unlock */
- const char* file_name,/* in: file name where lock requested */
- ulint line) /* in: line where requested */
+ const char* file_name,/*!< in: file name where lock requested */
+ ulint line) /*!< in: line where requested */
{
- ulint index; /* index of the reserved wait cell */
- ulint i; /* spin round count */
+ ulint index; /*!< index of the reserved wait cell */
+ ulint i; /*!< spin round count */
ibool spinning = FALSE;
ut_ad(rw_lock_validate(lock));
@@ -645,9 +648,9 @@ lock_loop:
if (srv_print_latch_waits) {
fprintf(stderr,
"Thread %lu spin wait rw-x-lock at %p"
- " cfile %s cline %lu rnds %lu\n",
+ " '%s' rnds %lu\n",
os_thread_pf(os_thread_get_curr_id()), (void*) lock,
- lock->cfile_name, (ulong) lock->cline, (ulong) i);
+ lock->lock_name, (ulong) i);
}
sync_array_reserve_cell(sync_primary_wait_array,
@@ -668,9 +671,9 @@ lock_loop:
if (srv_print_latch_waits) {
fprintf(stderr,
"Thread %lu OS wait for rw-x-lock at %p"
- " cfile %s cline %lu\n",
+ " '%s'\n",
os_thread_pf(os_thread_get_curr_id()), (void*) lock,
- lock->cfile_name, (ulong) lock->cline);
+ lock->lock_name);
}
/* these stats may not be accurate */
@@ -684,7 +687,7 @@ lock_loop:
}
#ifdef UNIV_SYNC_DEBUG
-/**********************************************************************
+/******************************************************************//**
Acquires the debug mutex. We cannot use the mutex defined in sync0sync,
because the debug mutex is also acquired in sync0arr while holding the OS
mutex protecting the sync array, and the ordinary mutex_enter might
@@ -713,7 +716,7 @@ loop:
goto loop;
}
-/**********************************************************************
+/******************************************************************//**
Releases the debug mutex. */
UNIV_INTERN
void
@@ -728,17 +731,17 @@ rw_lock_debug_mutex_exit(void)
}
}
-/**********************************************************************
+/******************************************************************//**
Inserts the debug information for an rw-lock. */
UNIV_INTERN
void
rw_lock_add_debug_info(
/*===================*/
- rw_lock_t* lock, /* in: rw-lock */
- ulint pass, /* in: pass value */
- ulint lock_type, /* in: lock type */
- const char* file_name, /* in: file where requested */
- ulint line) /* in: line where requested */
+ rw_lock_t* lock, /*!< in: rw-lock */
+ ulint pass, /*!< in: pass value */
+ ulint lock_type, /*!< in: lock type */
+ const char* file_name, /*!< in: file where requested */
+ ulint line) /*!< in: line where requested */
{
rw_lock_debug_t* info;
@@ -764,15 +767,15 @@ rw_lock_add_debug_info(
}
}
-/**********************************************************************
+/******************************************************************//**
Removes a debug information struct for an rw-lock. */
UNIV_INTERN
void
rw_lock_remove_debug_info(
/*======================*/
- rw_lock_t* lock, /* in: rw-lock */
- ulint pass, /* in: pass value */
- ulint lock_type) /* in: lock type */
+ rw_lock_t* lock, /*!< in: rw-lock */
+ ulint pass, /*!< in: pass value */
+ ulint lock_type) /*!< in: lock type */
{
rw_lock_debug_t* info;
@@ -810,16 +813,16 @@ rw_lock_remove_debug_info(
#endif /* UNIV_SYNC_DEBUG */
#ifdef UNIV_SYNC_DEBUG
-/**********************************************************************
+/******************************************************************//**
Checks if the thread has locked the rw-lock in the specified mode, with
-the pass value == 0. */
+the pass value == 0.
+@return TRUE if locked */
UNIV_INTERN
ibool
rw_lock_own(
/*========*/
- /* out: TRUE if locked */
- rw_lock_t* lock, /* in: rw-lock */
- ulint lock_type) /* in: lock type: RW_LOCK_SHARED,
+ rw_lock_t* lock, /*!< in: rw-lock */
+ ulint lock_type) /*!< in: lock type: RW_LOCK_SHARED,
RW_LOCK_EX */
{
rw_lock_debug_t* info;
@@ -851,15 +854,15 @@ rw_lock_own(
}
#endif /* UNIV_SYNC_DEBUG */
-/**********************************************************************
-Checks if somebody has locked the rw-lock in the specified mode. */
+/******************************************************************//**
+Checks if somebody has locked the rw-lock in the specified mode.
+@return TRUE if locked */
UNIV_INTERN
ibool
rw_lock_is_locked(
/*==============*/
- /* out: TRUE if locked */
- rw_lock_t* lock, /* in: rw-lock */
- ulint lock_type) /* in: lock type: RW_LOCK_SHARED,
+ rw_lock_t* lock, /*!< in: rw-lock */
+ ulint lock_type) /*!< in: lock type: RW_LOCK_SHARED,
RW_LOCK_EX */
{
ibool ret = FALSE;
@@ -883,13 +886,13 @@ rw_lock_is_locked(
}
#ifdef UNIV_SYNC_DEBUG
-/*******************************************************************
+/***************************************************************//**
Prints debug info of currently locked rw-locks. */
UNIV_INTERN
void
rw_lock_list_print_info(
/*====================*/
- FILE* file) /* in: file where to print */
+ FILE* file) /*!< in: file where to print */
{
rw_lock_t* lock;
ulint count = 0;
@@ -937,13 +940,13 @@ rw_lock_list_print_info(
mutex_exit(&rw_lock_list_mutex);
}
-/*******************************************************************
+/***************************************************************//**
Prints debug info of an rw-lock. */
UNIV_INTERN
void
rw_lock_print(
/*==========*/
- rw_lock_t* lock) /* in: rw-lock */
+ rw_lock_t* lock) /*!< in: rw-lock */
{
rw_lock_debug_t* info;
@@ -953,7 +956,12 @@ rw_lock_print(
"RW-LATCH: %p ", (void*) lock);
#ifndef INNODB_RW_LOCKS_USE_ATOMICS
- mutex_enter(&(lock->mutex));
+ /* We used to acquire lock->mutex here, but it would cause a
+ recursive call to sync_thread_add_level() if UNIV_SYNC_DEBUG
+ is defined. Since this function is only invoked from
+ sync_thread_levels_g(), let us choose the smaller evil:
+ performing dirty reads instead of causing bogus deadlocks or
+ assertion failures. */
#endif
if (lock->lock_word != X_LOCK_DECR) {
@@ -969,18 +977,15 @@ rw_lock_print(
info = UT_LIST_GET_NEXT(list, info);
}
}
-#ifndef INNODB_RW_LOCKS_USE_ATOMICS
- mutex_exit(&(lock->mutex));
-#endif
}
-/*************************************************************************
+/*********************************************************************//**
Prints info of a debug struct. */
UNIV_INTERN
void
rw_lock_debug_print(
/*================*/
- rw_lock_debug_t* info) /* in: debug struct */
+ rw_lock_debug_t* info) /*!< in: debug struct */
{
ulint rwt;
@@ -1004,9 +1009,10 @@ rw_lock_debug_print(
putc('\n', stderr);
}
-/*******************************************************************
+/***************************************************************//**
Returns the number of currently locked rw-locks. Works only in the debug
-version. */
+version.
+@return number of locked rw-locks */
UNIV_INTERN
ulint
rw_lock_n_locked(void)