~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to storage/innobase/lock/lock0iter.c

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/******************************************************
 
2
Lock queue iterator. Can iterate over table and record
 
3
lock queues.
 
4
 
 
5
(c) 2007 Innobase Oy
 
6
 
 
7
Created July 16, 2007 Vasil Dimov
 
8
*******************************************************/
 
9
 
 
10
#define LOCK_MODULE_IMPLEMENTATION
 
11
 
 
12
#include "univ.i"
 
13
#include "lock0iter.h"
 
14
#include "lock0lock.h"
 
15
#include "lock0priv.h"
 
16
#include "ut0dbg.h"
 
17
#include "ut0lst.h"
 
18
 
 
19
/***********************************************************************
 
20
Initialize lock queue iterator so that it starts to iterate from
 
21
"lock". bit_no specifies the record number within the heap where the
 
22
record is stored. It can be undefined (ULINT_UNDEFINED) in two cases:
 
23
1. If the lock is a table lock, thus we have a table lock queue;
 
24
2. If the lock is a record lock and it is a wait lock. In this case
 
25
   bit_no is calculated in this function by using
 
26
   lock_rec_find_set_bit(). There is exactly one bit set in the bitmap
 
27
   of a wait lock. */
 
28
 
 
29
void
 
30
lock_queue_iterator_reset(
 
31
/*======================*/
 
32
        lock_queue_iterator_t*  iter,   /* out: iterator */
 
33
        lock_t*                 lock,   /* in: lock to start from */
 
34
        ulint                   bit_no) /* in: record number in the
 
35
                                        heap */
 
36
{
 
37
        iter->current_lock = lock;
 
38
 
 
39
        if (bit_no != ULINT_UNDEFINED) {
 
40
 
 
41
                iter->bit_no = bit_no;
 
42
        } else {
 
43
 
 
44
                switch (lock_get_type(lock)) {
 
45
                case LOCK_TABLE:
 
46
                        iter->bit_no = ULINT_UNDEFINED;
 
47
                        break;
 
48
                case LOCK_REC:
 
49
                        iter->bit_no = lock_rec_find_set_bit(lock);
 
50
                        ut_a(iter->bit_no != ULINT_UNDEFINED);
 
51
                        break;
 
52
                default:
 
53
                        ut_error;
 
54
                }
 
55
        }
 
56
}
 
57
 
 
58
/***********************************************************************
 
59
Gets the previous lock in the lock queue, returns NULL if there are no
 
60
more locks (i.e. the current lock is the first one). The iterator is
 
61
receded (if not-NULL is returned). */
 
62
 
 
63
lock_t*
 
64
lock_queue_iterator_get_prev(
 
65
/*=========================*/
 
66
                                        /* out: previous lock or NULL */
 
67
        lock_queue_iterator_t*  iter)   /* in/out: iterator */
 
68
{
 
69
        lock_t* prev_lock;
 
70
 
 
71
        switch (lock_get_type(iter->current_lock)) {
 
72
        case LOCK_REC:
 
73
                prev_lock = lock_rec_get_prev(
 
74
                        iter->current_lock, iter->bit_no);
 
75
                break;
 
76
        case LOCK_TABLE:
 
77
                prev_lock = UT_LIST_GET_PREV(
 
78
                        un_member.tab_lock.locks, iter->current_lock);
 
79
                break;
 
80
        default:
 
81
                ut_error;
 
82
        }
 
83
 
 
84
        if (prev_lock != NULL) {
 
85
 
 
86
                iter->current_lock = prev_lock;
 
87
        }
 
88
 
 
89
        return(prev_lock);
 
90
}