~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/innobase/lock/lock0iter.cc

  • Committer: Lee
  • Date: 2008-10-30 22:02:01 UTC
  • mto: (572.1.2 devel)
  • mto: This revision was merged to the branch mainline in revision 573.
  • Revision ID: lbieber@lbieber-desktop-20081030220201-elb6qprbzpn7c5a4
add my name to the AUTHORS file

Show diffs side-by-side

added added

removed removed

Lines of Context:
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., 51 Franklin
15
 
St, Fifth Floor, Boston, MA 02110-1301 USA
16
 
 
17
 
*****************************************************************************/
18
 
 
19
 
/**************************************************//**
20
 
@file lock/lock0iter.c
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"
35
 
#ifdef UNIV_DEBUG
36
 
# include "srv0srv.h" /* kernel_mutex */
37
 
#endif /* UNIV_DEBUG */
38
 
 
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
47
 
   of a wait lock. */
48
 
UNIV_INTERN
49
 
void
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
55
 
                                        heap */
56
 
{
57
 
        ut_ad(mutex_own(&kernel_mutex));
58
 
 
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
 
 
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 */
85
 
UNIV_INTERN
86
 
const lock_t*
87
 
lock_queue_iterator_get_prev(
88
 
/*=========================*/
89
 
        lock_queue_iterator_t*  iter)   /*!< in/out: iterator */
90
 
{
91
 
        const lock_t*   prev_lock;
92
 
 
93
 
        ut_ad(mutex_own(&kernel_mutex));
94
 
 
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
 
}