1
/*****************************************************************************
3
Copyright (C) 2007, 2009, Innobase Oy. All Rights Reserved.
5
This program is free software; you can redistribute it and/or modify it under
6
the terms of the GNU General Public License as published by the Free Software
7
Foundation; version 2 of the License.
9
This program is distributed in the hope that it will be useful, but WITHOUT
10
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13
You should have received a copy of the GNU General Public License along with
14
this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
15
St, Fifth Floor, Boston, MA 02110-1301 USA
17
*****************************************************************************/
19
/**************************************************//**
20
@file lock/lock0iter.c
21
Lock queue iterator. Can iterate over table and record
24
Created July 16, 2007 Vasil Dimov
25
*******************************************************/
27
#define LOCK_MODULE_IMPLEMENTATION
30
#include "lock0iter.h"
31
#include "lock0lock.h"
32
#include "lock0priv.h"
36
# include "srv0srv.h" /* kernel_mutex */
37
#endif /* UNIV_DEBUG */
39
/*******************************************************************//**
40
Initialize lock queue iterator so that it starts to iterate from
41
"lock". bit_no specifies the record number within the heap where the
42
record is stored. It can be undefined (ULINT_UNDEFINED) in two cases:
43
1. If the lock is a table lock, thus we have a table lock queue;
44
2. If the lock is a record lock and it is a wait lock. In this case
45
bit_no is calculated in this function by using
46
lock_rec_find_set_bit(). There is exactly one bit set in the bitmap
50
lock_queue_iterator_reset(
51
/*======================*/
52
lock_queue_iterator_t* iter, /*!< out: iterator */
53
const lock_t* lock, /*!< in: lock to start from */
54
ulint bit_no) /*!< in: record number in the
57
ut_ad(mutex_own(&kernel_mutex));
59
iter->current_lock = lock;
61
if (bit_no != ULINT_UNDEFINED) {
63
iter->bit_no = bit_no;
66
switch (lock_get_type_low(lock)) {
68
iter->bit_no = ULINT_UNDEFINED;
71
iter->bit_no = lock_rec_find_set_bit(lock);
72
ut_a(iter->bit_no != ULINT_UNDEFINED);
80
/*******************************************************************//**
81
Gets the previous lock in the lock queue, returns NULL if there are no
82
more locks (i.e. the current lock is the first one). The iterator is
83
receded (if not-NULL is returned).
84
@return previous lock or NULL */
87
lock_queue_iterator_get_prev(
88
/*=========================*/
89
lock_queue_iterator_t* iter) /*!< in/out: iterator */
91
const lock_t* prev_lock;
93
ut_ad(mutex_own(&kernel_mutex));
95
switch (lock_get_type_low(iter->current_lock)) {
97
prev_lock = lock_rec_get_prev(
98
iter->current_lock, iter->bit_no);
101
prev_lock = UT_LIST_GET_PREV(
102
un_member.tab_lock.locks, iter->current_lock);
108
if (prev_lock != NULL) {
110
iter->current_lock = prev_lock;