641.2.2
by Monty Taylor
InnoDB Plugin 1.0.3 |
1 |
/*****************************************************************************
|
2 |
||
3 |
Copyright (c) 2007, 2009, Innobase Oy. All Rights Reserved.
|
|
4 |
||
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.
|
|
8 |
||
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.
|
|
12 |
||
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., 59 Temple
|
|
15 |
Place, Suite 330, Boston, MA 02111-1307 USA
|
|
16 |
||
17 |
*****************************************************************************/
|
|
18 |
||
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
19 |
/**************************************************//**
|
20 |
@file lock/lock0iter.c
|
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
21 |
Lock queue iterator. Can iterate over table and record
|
22 |
lock queues.
|
|
23 |
||
24 |
Created July 16, 2007 Vasil Dimov
|
|
25 |
*******************************************************/
|
|
26 |
||
27 |
#define LOCK_MODULE_IMPLEMENTATION
|
|
28 |
||
29 |
#include "univ.i" |
|
30 |
#include "lock0iter.h" |
|
31 |
#include "lock0lock.h" |
|
32 |
#include "lock0priv.h" |
|
33 |
#include "ut0dbg.h" |
|
34 |
#include "ut0lst.h" |
|
641.2.2
by Monty Taylor
InnoDB Plugin 1.0.3 |
35 |
#ifdef UNIV_DEBUG
|
36 |
# include "srv0srv.h" /* kernel_mutex */ |
|
37 |
#endif /* UNIV_DEBUG */ |
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
38 |
|
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
39 |
/*******************************************************************//**
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
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
|
|
47 |
of a wait lock. */
|
|
48 |
UNIV_INTERN
|
|
49 |
void
|
|
50 |
lock_queue_iterator_reset( |
|
51 |
/*======================*/
|
|
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
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 |
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
55 |
heap */
|
56 |
{
|
|
641.2.2
by Monty Taylor
InnoDB Plugin 1.0.3 |
57 |
ut_ad(mutex_own(&kernel_mutex)); |
58 |
||
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
59 |
iter->current_lock = lock; |
60 |
||
61 |
if (bit_no != ULINT_UNDEFINED) { |
|
62 |
||
63 |
iter->bit_no = bit_no; |
|
64 |
} else { |
|
65 |
||
66 |
switch (lock_get_type_low(lock)) { |
|
67 |
case LOCK_TABLE: |
|
68 |
iter->bit_no = ULINT_UNDEFINED; |
|
69 |
break; |
|
70 |
case LOCK_REC: |
|
71 |
iter->bit_no = lock_rec_find_set_bit(lock); |
|
72 |
ut_a(iter->bit_no != ULINT_UNDEFINED); |
|
73 |
break; |
|
74 |
default: |
|
75 |
ut_error; |
|
76 |
}
|
|
77 |
}
|
|
78 |
}
|
|
79 |
||
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
80 |
/*******************************************************************//**
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
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
|
|
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
83 |
receded (if not-NULL is returned).
|
84 |
@return previous lock or NULL */
|
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
85 |
UNIV_INTERN
|
86 |
const lock_t* |
|
87 |
lock_queue_iterator_get_prev( |
|
88 |
/*=========================*/
|
|
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
89 |
lock_queue_iterator_t* iter) /*!< in/out: iterator */ |
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
90 |
{
|
91 |
const lock_t* prev_lock; |
|
92 |
||
641.2.2
by Monty Taylor
InnoDB Plugin 1.0.3 |
93 |
ut_ad(mutex_own(&kernel_mutex)); |
94 |
||
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
95 |
switch (lock_get_type_low(iter->current_lock)) { |
96 |
case LOCK_REC: |
|
97 |
prev_lock = lock_rec_get_prev( |
|
98 |
iter->current_lock, iter->bit_no); |
|
99 |
break; |
|
100 |
case LOCK_TABLE: |
|
101 |
prev_lock = UT_LIST_GET_PREV( |
|
102 |
un_member.tab_lock.locks, iter->current_lock); |
|
103 |
break; |
|
104 |
default: |
|
105 |
ut_error; |
|
106 |
}
|
|
107 |
||
108 |
if (prev_lock != NULL) { |
|
109 |
||
110 |
iter->current_lock = prev_lock; |
|
111 |
}
|
|
112 |
||
113 |
return(prev_lock); |
|
114 |
}
|