InnoDB Plugin
1.0
|
#include "univ.i"
#include "ut0lst.h"
#include "ut0counter.h"
#include "sync0sync.h"
#include "os0sync.h"
#include "sync0rw.ic"
Go to the source code of this file.
Data Structures | |
struct | rw_lock_stats_t |
struct | rw_lock_t |
struct | rw_lock_debug_t |
Macros | |
#define | RW_S_LATCH 1 |
#define | RW_X_LATCH 2 |
#define | RW_NO_LATCH 3 |
#define | X_LOCK_DECR 0x00100000 |
#define | rw_lock_create(K, L, level) rw_lock_create_func((L), (level), #L, __FILE__, __LINE__) |
#define | rw_lock_s_lock(M) rw_lock_s_lock_func((M), 0, __FILE__, __LINE__) |
#define | rw_lock_s_lock_inline(M, P, F, L) rw_lock_s_lock_func((M), (P), (F), (L)) |
#define | rw_lock_s_lock_gen(M, P) rw_lock_s_lock_func((M), (P), __FILE__, __LINE__) |
#define | rw_lock_s_lock_gen_nowait(M, P) rw_lock_s_lock_low((M), (P), __FILE__, __LINE__) |
#define | rw_lock_s_lock_nowait(M, F, L) rw_lock_s_lock_low((M), 0, (F), (L)) |
#define | rw_lock_s_unlock_gen(L, P) rw_lock_s_unlock_func(P, L) |
#define | rw_lock_x_lock(M) rw_lock_x_lock_func((M), 0, __FILE__, __LINE__) |
#define | rw_lock_x_lock_inline(M, P, F, L) rw_lock_x_lock_func((M), (P), (F), (L)) |
#define | rw_lock_x_lock_gen(M, P) rw_lock_x_lock_func((M), (P), __FILE__, __LINE__) |
#define | rw_lock_x_lock_nowait(M) rw_lock_x_lock_func_nowait((M), __FILE__, __LINE__) |
#define | rw_lock_x_lock_func_nowait_inline(M, F, L) rw_lock_x_lock_func_nowait((M), (F), (L)) |
#define | rw_lock_x_unlock_gen(L, P) rw_lock_x_unlock_func(P, L) |
#define | rw_lock_free(M) rw_lock_free_func(M) |
#define | rw_lock_s_unlock(L) rw_lock_s_unlock_gen(L, 0) |
#define | rw_lock_x_unlock(L) rw_lock_x_unlock_gen(L, 0) |
#define | RW_LOCK_MAGIC_N 22643 |
Typedefs | |
typedef ut_list_base< rw_lock_t > | rw_lock_list_t |
Functions | |
UNIV_INTERN void | rw_lock_create_func (rw_lock_t *lock, ulint level, const char *cmutex_name, const char *cfile_name, ulint cline) |
UNIV_INTERN void | rw_lock_free_func (rw_lock_t *lock) |
UNIV_INTERN ibool | rw_lock_validate (rw_lock_t *lock) |
UNIV_INLINE ibool | rw_lock_s_lock_low (rw_lock_t *lock, ulint pass) |
UNIV_INLINE void | rw_lock_s_lock_func (rw_lock_t *lock, ulint pass, const char *file_name, ulint line) |
UNIV_INLINE ibool | rw_lock_x_lock_func_nowait (rw_lock_t *lock, const char *file_name, ulint line) |
UNIV_INLINE void | rw_lock_s_unlock_func (ulint pass, rw_lock_t *lock) |
UNIV_INTERN void | rw_lock_x_lock_func (rw_lock_t *lock, ulint pass, const char *file_name, ulint line) |
UNIV_INLINE void | rw_lock_x_unlock_func (ulint pass, rw_lock_t *lock) |
UNIV_INTERN void | rw_lock_x_lock_move_ownership (rw_lock_t *lock) |
UNIV_INLINE ulint | rw_lock_get_x_lock_count (const rw_lock_t *lock) |
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_INLINE ulint | rw_lock_get_reader_count (const rw_lock_t *lock) |
UNIV_INLINE ibool | rw_lock_lock_word_decr (rw_lock_t *lock, ulint amount) |
UNIV_INLINE lint | rw_lock_lock_word_incr (rw_lock_t *lock, ulint amount) |
UNIV_INLINE void | rw_lock_set_writer_id_and_recursion_flag (rw_lock_t *lock, ibool recursive) |
UNIV_INTERN ibool | rw_lock_own (rw_lock_t *lock, ulint lock_type)) |
UNIV_INTERN ibool | rw_lock_is_locked (rw_lock_t *lock, ulint lock_type) |
UNIV_INTERN void | rw_lock_print (rw_lock_t *lock) |
UNIV_INTERN void | rw_lock_list_print_info (FILE *file) |
UNIV_INTERN ulint | rw_lock_n_locked (void) |
UNIV_INTERN void | rw_lock_debug_mutex_enter (void) |
UNIV_INTERN void | rw_lock_debug_mutex_exit (void) |
UNIV_INTERN void | rw_lock_debug_print (FILE *f, rw_lock_debug_t *info) |
Variables | |
rw_lock_list_t | rw_lock_list |
ib_mutex_t | rw_lock_list_mutex |
ib_mutex_t | rw_lock_debug_mutex |
os_event_t | rw_lock_debug_event |
ibool | rw_lock_debug_waiters |
rw_lock_stats_t | rw_lock_stats |
UNIV_INLINE ibool const char * | file_name |
UNIV_INLINE ibool const char ulint | line |
The read-write lock (for threads, not for database transactions)
Created 9/11/1995 Heikki Tuuri
#define rw_lock_create | ( | K, | |
L, | |||
level | |||
) | rw_lock_create_func((L), (level), #L, __FILE__, __LINE__) |
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 is necessary only if the memory block containing it is freed. if MySQL performance schema is enabled and "UNIV_PFS_RWLOCK" is defined, the rwlock are instrumented with performance schema probes.
#define RW_LOCK_MAGIC_N 22643 |
Value of rw_lock_t::magic_n
#define rw_lock_s_lock | ( | M | ) | rw_lock_s_lock_func((M), 0, __FILE__, __LINE__) |
NOTE! The following macros should be used in rw locking and unlocking, not the corresponding function.
UNIV_INTERN void rw_lock_create_func | ( | rw_lock_t * | lock, |
ulint | level, | ||
const char * | cmutex_name, | ||
const char * | cfile_name, | ||
ulint | cline | ||
) |
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 is necessary only if the memory block containing it is freed. in: file line where created
lock | in: pointer to memory |
level | in: level |
cmutex_name | in: mutex name |
cfile_name | in: file name where created |
UNIV_INTERN void rw_lock_debug_mutex_enter | ( | void | ) |
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 recursively call routines in sync0arr, leading to a deadlock on the OS mutex.
UNIV_INTERN void rw_lock_debug_mutex_exit | ( | void | ) |
Releases the debug mutex.
UNIV_INTERN void rw_lock_debug_print | ( | FILE * | f, |
rw_lock_debug_t * | info | ||
) |
Prints info of a debug struct. in: debug struct
f | in: output stream |
UNIV_INTERN void rw_lock_free_func | ( | rw_lock_t * | lock | ) |
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. in: rw-lock
UNIV_INLINE ulint rw_lock_get_reader_count | ( | const rw_lock_t * | lock | ) |
Returns the number of readers.
Returns the number of readers.
lock | in: rw-lock |
UNIV_INLINE ulint rw_lock_get_waiters | ( | const rw_lock_t * | lock | ) |
Check if there are threads waiting for the rw-lock.
Check if there are threads waiting for the rw-lock.
lock | in: rw-lock |
UNIV_INLINE ulint rw_lock_get_writer | ( | const rw_lock_t * | lock | ) |
Returns the write-status of the lock - this function made more sense with the old rw_lock implementation.
Returns the write-status of the lock - this function made more sense with the old rw_lock implementation.
lock | in: rw-lock |
UNIV_INLINE ulint rw_lock_get_x_lock_count | ( | const rw_lock_t * | lock | ) |
Returns the value of writer_count for the lock. Does not reserve the lock mutex, so the caller must be sure it is not changed during the call.
Returns the value of writer_count for the lock. Does not reserve the lock mutex, so the caller must be sure it is not changed during the call.
lock | in: rw-lock |
Checks if somebody has locked the rw-lock in the specified mode. in: lock type: RW_LOCK_SHARED, RW_LOCK_EX
lock | in: rw-lock |
UNIV_INTERN void rw_lock_list_print_info | ( | FILE * | file | ) |
Prints debug info of currently locked rw-locks. in: file where to print
Decrements lock_word the specified amount if it is greater than 0. This is used by both s_lock and x_lock operations.
Two different implementations for decrementing the lock_word of a rw_lock: one for systems supporting atomic operations, one for others. This does does not support recusive x-locks: they should be handled by the caller and need not be atomic since they are performed by the current lock holder. Returns true if the decrement was made, false if not.
lock | in/out: rw-lock |
amount | in: amount to decrement |
UNIV_INLINE lint rw_lock_lock_word_incr | ( | rw_lock_t * | lock, |
ulint | amount | ||
) |
Increments lock_word the specified amount and returns new value.
Increments lock_word the specified amount and returns new value.
lock | in/out: rw-lock |
amount | in: amount of increment |
UNIV_INTERN ulint rw_lock_n_locked | ( | void | ) |
Returns the number of currently locked rw-locks. Works only in the debug version.
Checks if the thread has locked the rw-lock in the specified mode, with the pass value == 0.
lock | in: rw-lock |
lock_type | in: lock type: RW_LOCK_SHARED, RW_LOCK_EX |
UNIV_INTERN void rw_lock_print | ( | rw_lock_t * | lock | ) |
Prints debug info of an rw-lock. in: rw-lock
UNIV_INLINE void rw_lock_s_lock_func | ( | rw_lock_t * | lock, |
ulint | pass, | ||
const char * | file_name, | ||
ulint | line | ||
) |
NOTE! Use the corresponding macro, not directly this function, except if you supply the file name and line number. 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 for the lock, before suspending the thread. in: line where requested
NOTE! Use the corresponding macro, not directly this function! 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 for the lock, before suspending the thread.
lock | in: pointer to rw-lock |
pass | in: pass value; != 0, if the lock will be passed to another thread to unlock |
file_name | in: file name where lock requested |
line | in: line where requested |
Low-level function which tries to lock an rw-lock in s-mode. Performs no spinning.
lock | in: pointer to rw-lock |
UNIV_INLINE void rw_lock_s_unlock_func | ( | ulint | pass, |
rw_lock_t * | lock | ||
) |
Releases a shared mode lock. in/out: rw-lock
Releases a shared mode lock.
pass | in: pass value; != 0, if the lock may have been passed to another thread to unlock |
lock | in/out: rw-lock |
This function sets the lock->writer_thread and lock->recursive fields. For platforms where we are using atomic builtins instead of lock->mutex it sets the lock->writer_thread field using atomics to ensure memory ordering. Note that it is assumed that the caller of this function effectively owns the lock i.e.: nobody else is allowed to modify lock->writer_thread at this point in time. The protocol is that lock->writer_thread MUST be updated BEFORE the lock->recursive flag is set. in: TRUE if recursion allowed
This function sets the lock->writer_thread and lock->recursive fields. For platforms where we are using atomic builtins instead of lock->mutex it sets the lock->writer_thread field using atomics to ensure memory ordering. Note that it is assumed that the caller of this function effectively owns the lock i.e.: nobody else is allowed to modify lock->writer_thread at this point in time. The protocol is that lock->writer_thread MUST be updated BEFORE the lock->recursive flag is set.
lock | in/out: lock to work on |
recursive | in: TRUE if recursion allowed |
Checks that the rw-lock has been initialized and that there are no simultaneous shared and exclusive locks.
UNIV_INTERN void rw_lock_x_lock_func | ( | rw_lock_t * | lock, |
ulint | pass, | ||
const char * | file_name, | ||
ulint | line | ||
) |
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, the function spins a preset time (controlled by SYNC_SPIN_ROUNDS), waiting for the lock, before suspending the thread. If the same thread has an x-lock on the rw-lock, locking succeed, with the following exception: if pass != 0, only a single x-lock may be taken on the lock. NOTE: If the same thread has an s-lock, locking does not succeed! in: line where requested
lock | in: pointer to rw-lock |
pass | in: pass value; != 0, if the lock will be passed to another thread to unlock |
file_name | in: file name where lock requested |
UNIV_INLINE ibool rw_lock_x_lock_func_nowait | ( | rw_lock_t * | lock, |
const char * | file_name, | ||
ulint | line | ||
) |
NOTE! Use the corresponding macro, not directly this function! Lock an rw-lock in exclusive mode for the current thread if the lock can be obtained immediately.
NOTE! Use the corresponding macro, not directly this function! Lock an rw-lock in exclusive mode for the current thread if the lock can be obtained immediately.
lock | in: pointer to rw-lock |
file_name | in: file name where lock requested |
line | in: line where requested |
UNIV_INTERN void rw_lock_x_lock_move_ownership | ( | rw_lock_t * | lock | ) |
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 read was done. The ownership is moved because we want that the current thread is able to acquire a second x-latch which is stored in an mtr. This, in turn, is needed to pass the debug checks of index page operations. in: lock which was x-locked in the buffer read
UNIV_INLINE void rw_lock_x_unlock_func | ( | ulint | pass, |
rw_lock_t * | lock | ||
) |
Releases an exclusive mode lock. in/out: rw-lock
Releases an exclusive mode lock.
pass | in: pass value; != 0, if the lock may have been passed to another thread to unlock |
lock | in/out: rw-lock |
UNIV_INLINE ibool const char* file_name |
< in: pass value; != 0, if the lock will be passed to another thread to unlock in: file name where lock requested
UNIV_INLINE ibool const char ulint line |
in: line where requested
os_event_t rw_lock_debug_event |
If deadlock detection does not get immediately the mutex it may wait for this event
ibool rw_lock_debug_waiters |
This is set to TRUE, if there may be waiters for the event
rw_lock_stats_t rw_lock_stats |
Counters for RW locks.