1
by brian
clean slate |
1 |
/* Copyright (C) 2000 MySQL AB
|
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
|
|
1802.10.2
by Monty Taylor
Update all of the copyright headers to include the correct address. |
14 |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
|
1
by brian
clean slate |
15 |
|
1241.9.43
by Monty Taylor
Merged trunk. Also renamed thr_lock. Doh. I hate it when I do both. |
16 |
/* For use with thr_locks */
|
17 |
||
18 |
#ifndef DRIZZLED_THR_LOCK_H
|
|
19 |
#define DRIZZLED_THR_LOCK_H
|
|
20 |
||
1786.2.1
by Brian Aker
Current boost work (more conversion). |
21 |
#include <boost/thread/mutex.hpp> |
1812.3.7
by Brian Aker
Typdef our lock type. |
22 |
#include <boost/thread/shared_mutex.hpp> |
1786.2.1
by Brian Aker
Current boost work (more conversion). |
23 |
#include <boost/thread/condition_variable.hpp> |
1241.9.43
by Monty Taylor
Merged trunk. Also renamed thr_lock. Doh. I hate it when I do both. |
24 |
#include <pthread.h> |
1122.2.10
by Monty Taylor
Fixed all of the include guards. |
25 |
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
26 |
namespace drizzled |
27 |
{
|
|
1
by brian
clean slate |
28 |
|
622.1.1
by Brian Aker
32bit fixes around vars |
29 |
extern uint64_t max_write_lock_count; |
30 |
extern uint64_t table_lock_wait_timeout; |
|
1
by brian
clean slate |
31 |
|
1241.9.43
by Monty Taylor
Merged trunk. Also renamed thr_lock. Doh. I hate it when I do both. |
32 |
|
33 |
enum thr_lock_type { TL_IGNORE=-1, |
|
34 |
/* UNLOCK ANY LOCK */
|
|
35 |
TL_UNLOCK, |
|
36 |
/* Read lock */
|
|
37 |
TL_READ, |
|
38 |
TL_READ_WITH_SHARED_LOCKS, |
|
39 |
/* READ, Don't allow concurrent insert */
|
|
40 |
TL_READ_NO_INSERT, |
|
41 |
/*
|
|
42 |
Write lock, but allow other threads to read / write.
|
|
43 |
Used by BDB tables in MySQL to mark that someone is
|
|
44 |
reading/writing to the table.
|
|
45 |
*/
|
|
46 |
TL_WRITE_ALLOW_WRITE, |
|
47 |
/*
|
|
48 |
Write lock, but allow other threads to read.
|
|
49 |
Used by ALTER TABLE in MySQL to allow readers
|
|
50 |
to use the table until ALTER TABLE is finished.
|
|
51 |
*/
|
|
52 |
TL_WRITE_ALLOW_READ, |
|
53 |
/*
|
|
54 |
WRITE lock used by concurrent insert. Will allow
|
|
55 |
READ, if one could use concurrent insert on table.
|
|
56 |
*/
|
|
57 |
TL_WRITE_CONCURRENT_INSERT, |
|
58 |
/*
|
|
59 |
parser only! Late bound low_priority flag.
|
|
60 |
At open_tables() becomes thd->update_lock_default.
|
|
61 |
*/
|
|
62 |
TL_WRITE_DEFAULT, |
|
63 |
/* Normal WRITE lock */
|
|
64 |
TL_WRITE, |
|
65 |
/* Abort new lock request with an error */
|
|
66 |
TL_WRITE_ONLY}; |
|
67 |
||
68 |
enum enum_thr_lock_result { THR_LOCK_SUCCESS= 0, THR_LOCK_ABORTED= 1, |
|
69 |
THR_LOCK_WAIT_TIMEOUT= 2, THR_LOCK_DEADLOCK= 3 }; |
|
1
by brian
clean slate |
70 |
/*
|
71 |
A description of the thread which owns the lock. The address
|
|
72 |
of an instance of this structure is used to uniquely identify the thread.
|
|
73 |
*/
|
|
74 |
||
1685.2.1
by Brian Aker
This removes custom myisam lock code from the kernel (and removes the |
75 |
struct THR_LOCK_INFO |
1
by brian
clean slate |
76 |
{
|
77 |
pthread_t thread; |
|
1241.9.43
by Monty Taylor
Merged trunk. Also renamed thr_lock. Doh. I hate it when I do both. |
78 |
uint64_t thread_id; |
298
by Brian Aker
ulong conversion. |
79 |
uint32_t n_cursors; |
1685.2.1
by Brian Aker
This removes custom myisam lock code from the kernel (and removes the |
80 |
|
81 |
THR_LOCK_INFO() : |
|
82 |
thread(0), |
|
83 |
thread_id(0), |
|
84 |
n_cursors(0) |
|
85 |
{ } |
|
86 |
||
1689.2.12
by Brian Aker
THR_LOCK_INFO::init() <-- encapsulation |
87 |
void init(); |
88 |
||
1685.2.1
by Brian Aker
This removes custom myisam lock code from the kernel (and removes the |
89 |
};
|
1
by brian
clean slate |
90 |
|
91 |
/*
|
|
92 |
Lock owner identifier. Globally identifies the lock owner within the
|
|
93 |
thread and among all the threads. The address of an instance of this
|
|
94 |
structure is used as id.
|
|
95 |
*/
|
|
96 |
||
1685.2.1
by Brian Aker
This removes custom myisam lock code from the kernel (and removes the |
97 |
struct THR_LOCK_OWNER |
1
by brian
clean slate |
98 |
{
|
99 |
THR_LOCK_INFO *info; |
|
1685.2.1
by Brian Aker
This removes custom myisam lock code from the kernel (and removes the |
100 |
|
101 |
THR_LOCK_OWNER() : |
|
102 |
info(0) |
|
103 |
{ } |
|
104 |
||
105 |
};
|
|
106 |
||
107 |
struct THR_LOCK; |
|
108 |
struct THR_LOCK_DATA; |
|
109 |
||
110 |
struct THR_LOCK_DATA { |
|
1
by brian
clean slate |
111 |
THR_LOCK_OWNER *owner; |
1685.2.1
by Brian Aker
This removes custom myisam lock code from the kernel (and removes the |
112 |
struct THR_LOCK_DATA *next,**prev; |
113 |
struct THR_LOCK *lock; |
|
1812.3.5
by Brian Aker
Move to boost condition_any |
114 |
boost::condition_variable_any *cond; |
1
by brian
clean slate |
115 |
enum thr_lock_type type; |
116 |
void *status_param; /* Param to status functions */ |
|
1685.2.1
by Brian Aker
This removes custom myisam lock code from the kernel (and removes the |
117 |
|
118 |
THR_LOCK_DATA() : |
|
119 |
owner(0), |
|
120 |
next(0), |
|
121 |
prev(0), |
|
122 |
lock(0), |
|
123 |
cond(0), |
|
124 |
type(TL_UNLOCK), |
|
125 |
status_param(0) |
|
126 |
{ } |
|
1689.2.13
by Brian Aker
More encapsulation of thr_lock |
127 |
|
128 |
void init(THR_LOCK *lock, |
|
129 |
void *status_param= NULL); |
|
1685.2.1
by Brian Aker
This removes custom myisam lock code from the kernel (and removes the |
130 |
};
|
1
by brian
clean slate |
131 |
|
132 |
struct st_lock_list { |
|
133 |
THR_LOCK_DATA *data,**last; |
|
1685.2.1
by Brian Aker
This removes custom myisam lock code from the kernel (and removes the |
134 |
|
135 |
st_lock_list() : |
|
136 |
data(0), |
|
137 |
last(0) |
|
138 |
{ } |
|
1
by brian
clean slate |
139 |
};
|
140 |
||
1685.2.1
by Brian Aker
This removes custom myisam lock code from the kernel (and removes the |
141 |
struct THR_LOCK { |
1689.2.11
by Brian Aker
Encapsulate more of the thr lock. |
142 |
private: |
1786.2.1
by Brian Aker
Current boost work (more conversion). |
143 |
boost::mutex mutex; |
1689.2.11
by Brian Aker
Encapsulate more of the thr lock. |
144 |
public: |
1
by brian
clean slate |
145 |
struct st_lock_list read_wait; |
146 |
struct st_lock_list read; |
|
147 |
struct st_lock_list write_wait; |
|
148 |
struct st_lock_list write; |
|
149 |
/* write_lock_count is incremented for write locks and reset on read locks */
|
|
298
by Brian Aker
ulong conversion. |
150 |
uint32_t write_lock_count; |
482
by Brian Aker
Remove uint. |
151 |
uint32_t read_no_write_count; |
1685.2.1
by Brian Aker
This removes custom myisam lock code from the kernel (and removes the |
152 |
|
153 |
THR_LOCK() : |
|
154 |
write_lock_count(0), |
|
155 |
read_no_write_count(0) |
|
156 |
{ } |
|
157 |
||
158 |
~THR_LOCK() |
|
159 |
{ } |
|
160 |
||
161 |
void abort_locks(); |
|
162 |
bool abort_locks_for_thread(uint64_t thread); |
|
163 |
||
164 |
void lock() |
|
165 |
{
|
|
1786.2.1
by Brian Aker
Current boost work (more conversion). |
166 |
mutex.lock(); |
1685.2.1
by Brian Aker
This removes custom myisam lock code from the kernel (and removes the |
167 |
}
|
168 |
||
169 |
void unlock() |
|
170 |
{
|
|
1786.2.1
by Brian Aker
Current boost work (more conversion). |
171 |
mutex.unlock(); |
1685.2.1
by Brian Aker
This removes custom myisam lock code from the kernel (and removes the |
172 |
}
|
173 |
||
174 |
void init() |
|
175 |
{
|
|
176 |
}
|
|
177 |
||
178 |
void deinit() |
|
179 |
{
|
|
180 |
}
|
|
181 |
||
1786.2.1
by Brian Aker
Current boost work (more conversion). |
182 |
boost::mutex *native_handle() |
1685.2.1
by Brian Aker
This removes custom myisam lock code from the kernel (and removes the |
183 |
{
|
184 |
return &mutex; |
|
185 |
}
|
|
186 |
};
|
|
187 |
||
188 |
||
1
by brian
clean slate |
189 |
#define thr_lock_owner_init(owner, info_arg) (owner)->info= (info_arg)
|
190 |
void thr_lock_init(THR_LOCK *lock); |
|
191 |
enum enum_thr_lock_result thr_multi_lock(THR_LOCK_DATA **data, |
|
482
by Brian Aker
Remove uint. |
192 |
uint32_t count, THR_LOCK_OWNER *owner); |
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
193 |
|
194 |
} /* namespace drizzled */ |
|
195 |
||
1241.9.43
by Monty Taylor
Merged trunk. Also renamed thr_lock. Doh. I hate it when I do both. |
196 |
#endif /* DRIZZLED_THR_LOCK_H */ |