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

« back to all changes in this revision

Viewing changes to include/thr_lock.h

  • 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
/* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
 
2
 
 
3
   This program is free software; you can redistribute it and/or modify
 
4
   it under the terms of the GNU General Public License as published by
 
5
   the Free Software Foundation; version 2 of the License.
 
6
 
 
7
   This program is distributed in the hope that it will be useful,
 
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
   GNU General Public License for more details.
 
11
 
 
12
   You should have received a copy of the GNU General Public License
 
13
   along with this program; if not, write to the Free Software
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
15
 
 
16
/* For use with thr_lock:s */
 
17
 
 
18
#ifndef _thr_lock_h
 
19
#define _thr_lock_h
 
20
#ifdef  __cplusplus
 
21
extern "C" {
 
22
#endif
 
23
 
 
24
#include <my_pthread.h>
 
25
#include <my_list.h>
 
26
 
 
27
struct st_thr_lock;
 
28
extern ulong locks_immediate,locks_waited ;
 
29
 
 
30
/*
 
31
  Important: if a new lock type is added, a matching lock description
 
32
             must be added to sql_test.cc's lock_descriptions array.
 
33
*/
 
34
enum thr_lock_type { TL_IGNORE=-1,
 
35
                     TL_UNLOCK,                 /* UNLOCK ANY LOCK */
 
36
                     /*
 
37
                       Parser only! At open_tables() becomes TL_READ or
 
38
                       TL_READ_NO_INSERT depending on the binary log format
 
39
                       (SBR/RBR) and on the table category (log table).
 
40
                       Used for tables that are read by statements which
 
41
                       modify tables.
 
42
                     */
 
43
                     TL_READ_DEFAULT,
 
44
                     TL_READ,                   /* Read lock */
 
45
                     TL_READ_WITH_SHARED_LOCKS,
 
46
                     /* High prior. than TL_WRITE. Allow concurrent insert */
 
47
                     TL_READ_HIGH_PRIORITY,
 
48
                     /* READ, Don't allow concurrent insert */
 
49
                     TL_READ_NO_INSERT,
 
50
                     /* 
 
51
                        Write lock, but allow other threads to read / write.
 
52
                        Used by BDB tables in MySQL to mark that someone is
 
53
                        reading/writing to the table.
 
54
                      */
 
55
                     TL_WRITE_ALLOW_WRITE,
 
56
                     /*
 
57
                        Write lock, but allow other threads to read.
 
58
                        Used by ALTER TABLE in MySQL to allow readers
 
59
                        to use the table until ALTER TABLE is finished.
 
60
                     */
 
61
                     TL_WRITE_ALLOW_READ,
 
62
                     /*
 
63
                       WRITE lock used by concurrent insert. Will allow
 
64
                       READ, if one could use concurrent insert on table.
 
65
                     */
 
66
                     TL_WRITE_CONCURRENT_INSERT,
 
67
                     /* Write used by INSERT DELAYED.  Allows READ locks */
 
68
                     TL_WRITE_DELAYED,
 
69
                     /* 
 
70
                       parser only! Late bound low_priority flag. 
 
71
                       At open_tables() becomes thd->update_lock_default.
 
72
                     */
 
73
                     TL_WRITE_DEFAULT,
 
74
                     /* WRITE lock that has lower priority than TL_READ */
 
75
                     TL_WRITE_LOW_PRIORITY,
 
76
                     /* Normal WRITE lock */
 
77
                     TL_WRITE,
 
78
                     /* Abort new lock request with an error */
 
79
                     TL_WRITE_ONLY};
 
80
 
 
81
enum enum_thr_lock_result { THR_LOCK_SUCCESS= 0, THR_LOCK_ABORTED= 1,
 
82
                            THR_LOCK_WAIT_TIMEOUT= 2, THR_LOCK_DEADLOCK= 3 };
 
83
 
 
84
 
 
85
extern ulong max_write_lock_count;
 
86
extern ulong table_lock_wait_timeout;
 
87
extern my_bool thr_lock_inited;
 
88
extern enum thr_lock_type thr_upgraded_concurrent_insert_lock;
 
89
 
 
90
/*
 
91
  A description of the thread which owns the lock. The address
 
92
  of an instance of this structure is used to uniquely identify the thread.
 
93
*/
 
94
 
 
95
typedef struct st_thr_lock_info
 
96
{
 
97
  pthread_t thread;
 
98
  my_thread_id thread_id;
 
99
  ulong n_cursors;
 
100
} THR_LOCK_INFO;
 
101
 
 
102
/*
 
103
  Lock owner identifier. Globally identifies the lock owner within the
 
104
  thread and among all the threads. The address of an instance of this
 
105
  structure is used as id.
 
106
*/
 
107
 
 
108
typedef struct st_thr_lock_owner
 
109
{
 
110
  THR_LOCK_INFO *info;
 
111
} THR_LOCK_OWNER;
 
112
 
 
113
 
 
114
typedef struct st_thr_lock_data {
 
115
  THR_LOCK_OWNER *owner;
 
116
  struct st_thr_lock_data *next,**prev;
 
117
  struct st_thr_lock *lock;
 
118
  pthread_cond_t *cond;
 
119
  enum thr_lock_type type;
 
120
  void *status_param;                   /* Param to status functions */
 
121
  void *debug_print_param;
 
122
} THR_LOCK_DATA;
 
123
 
 
124
struct st_lock_list {
 
125
  THR_LOCK_DATA *data,**last;
 
126
};
 
127
 
 
128
typedef struct st_thr_lock {
 
129
  LIST list;
 
130
  pthread_mutex_t mutex;
 
131
  struct st_lock_list read_wait;
 
132
  struct st_lock_list read;
 
133
  struct st_lock_list write_wait;
 
134
  struct st_lock_list write;
 
135
  /* write_lock_count is incremented for write locks and reset on read locks */
 
136
  ulong write_lock_count;
 
137
  uint read_no_write_count;
 
138
  void (*get_status)(void*, int);       /* When one gets a lock */
 
139
  void (*copy_status)(void*,void*);
 
140
  void (*update_status)(void*);         /* Before release of write */
 
141
  void (*restore_status)(void*);         /* Before release of read */
 
142
  my_bool (*check_status)(void *);
 
143
} THR_LOCK;
 
144
 
 
145
 
 
146
extern LIST *thr_lock_thread_list;
 
147
extern pthread_mutex_t THR_LOCK_lock;
 
148
 
 
149
my_bool init_thr_lock(void);            /* Must be called once/thread */
 
150
#define thr_lock_owner_init(owner, info_arg) (owner)->info= (info_arg)
 
151
void thr_lock_info_init(THR_LOCK_INFO *info);
 
152
void thr_lock_init(THR_LOCK *lock);
 
153
void thr_lock_delete(THR_LOCK *lock);
 
154
void thr_lock_data_init(THR_LOCK *lock,THR_LOCK_DATA *data,
 
155
                        void *status_param);
 
156
enum enum_thr_lock_result thr_lock(THR_LOCK_DATA *data,
 
157
                                   THR_LOCK_OWNER *owner,
 
158
                                   enum thr_lock_type lock_type);
 
159
void thr_unlock(THR_LOCK_DATA *data);
 
160
enum enum_thr_lock_result thr_multi_lock(THR_LOCK_DATA **data,
 
161
                                         uint count, THR_LOCK_OWNER *owner);
 
162
void thr_multi_unlock(THR_LOCK_DATA **data,uint count);
 
163
void thr_abort_locks(THR_LOCK *lock, my_bool upgrade_lock);
 
164
my_bool thr_abort_locks_for_thread(THR_LOCK *lock, my_thread_id thread);
 
165
void thr_print_locks(void);             /* For debugging */
 
166
my_bool thr_upgrade_write_delay_lock(THR_LOCK_DATA *data,
 
167
                                     enum thr_lock_type new_lock_type);
 
168
void    thr_downgrade_write_lock(THR_LOCK_DATA *data,
 
169
                                 enum thr_lock_type new_lock_type);
 
170
my_bool thr_reschedule_write_lock(THR_LOCK_DATA *data);
 
171
#ifdef  __cplusplus
 
172
}
 
173
#endif
 
174
#endif /* _thr_lock_h */