Drizzled Public API Documentation

thr_lock.h
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
14  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
15 
16 /* For use with thr_locks */
17 
18 #pragma once
19 
20 #include <boost/thread/mutex.hpp>
21 #include <boost/thread/shared_mutex.hpp>
22 #include <boost/thread/condition_variable.hpp>
23 
24 #include <drizzled/visibility.h>
25 #include <drizzled/common_fwd.h>
26 
27 namespace drizzled {
28 
29 extern uint64_t max_write_lock_count;
30 extern uint64_t table_lock_wait_timeout;
31 
32 enum thr_lock_type
33 {
34  TL_IGNORE=-1,
35  /* UNLOCK ANY LOCK */
36  TL_UNLOCK,
37  /* Read lock */
38  TL_READ,
39  TL_READ_WITH_SHARED_LOCKS,
40  /* READ, Don't allow concurrent insert */
41  TL_READ_NO_INSERT,
42  /*
43  Write lock, but allow other threads to read / write.
44  Used by BDB tables in MySQL to mark that someone is
45  reading/writing to the table.
46  */
47  TL_WRITE_ALLOW_WRITE,
48  /*
49  Write lock, but allow other threads to read.
50  Used by ALTER TABLE in MySQL to allow readers
51  to use the table until ALTER TABLE is finished.
52  */
53  TL_WRITE_ALLOW_READ,
54  /*
55  WRITE lock used by concurrent insert. Will allow
56  READ, if one could use concurrent insert on table.
57  */
58  TL_WRITE_CONCURRENT_INSERT,
59  /*
60  parser only! Late bound low_priority flag.
61  At open_tables() becomes thd->update_lock_default.
62  */
63  TL_WRITE_DEFAULT,
64  /* Normal WRITE lock */
65  TL_WRITE,
66  /* Abort new lock request with an error */
67  TL_WRITE_ONLY
68 };
69 
70 enum enum_thr_lock_result
71 {
72  THR_LOCK_SUCCESS= 0,
73  THR_LOCK_ABORTED= 1,
74  THR_LOCK_WAIT_TIMEOUT= 2,
75  THR_LOCK_DEADLOCK= 3
76 };
77 
78 /*
79  A description of the thread which owns the lock. The address
80  of an instance of this structure is used to uniquely identify the thread.
81 */
82 
84 {
85  uint64_t thread_id;
86  uint32_t n_cursors;
87 
88  THR_LOCK_INFO() :
89  thread_id(0),
90  n_cursors(0)
91  { }
92 
93  void init();
94 
95 };
96 
97 /*
98  Lock owner identifier. Globally identifies the lock owner within the
99  thread and among all the threads. The address of an instance of this
100  structure is used as id.
101 */
102 
104 {
105  THR_LOCK_INFO *info;
106 
107  THR_LOCK_OWNER() :
108  info(NULL)
109  { }
110 
111 };
112 
113 struct THR_LOCK;
114 struct THR_LOCK_DATA;
115 
117 {
118  THR_LOCK_OWNER *owner;
119  struct THR_LOCK_DATA *next,**prev;
120  struct THR_LOCK *lock;
121  boost::condition_variable_any *cond;
122  enum thr_lock_type type;
123  void *status_param; /* Param to status functions */
124 
125  THR_LOCK_DATA() :
126  owner(0),
127  next(0),
128  prev(0),
129  lock(0),
130  cond(0),
131  type(TL_UNLOCK),
132  status_param(0)
133  { }
134 
135  void init(THR_LOCK*, void *status_param= NULL);
136 };
137 
139 {
140  THR_LOCK_DATA *data,**last;
141 
142  st_lock_list() :
143  data(0),
144  last(0)
145  { }
146 };
147 
148 struct THR_LOCK
149 {
150 private:
151  boost::mutex mutex;
152 public:
153  struct st_lock_list read_wait;
154  struct st_lock_list read;
155  struct st_lock_list write_wait;
156  struct st_lock_list write;
157  /* write_lock_count is incremented for write locks and reset on read locks */
158  uint32_t write_lock_count;
159  uint32_t read_no_write_count;
160 
161  THR_LOCK() :
162  write_lock_count(0),
163  read_no_write_count(0)
164  { }
165 
166  void abort_locks();
167  bool abort_locks_for_thread(uint64_t thread);
168 
169  void lock()
170  {
171  mutex.lock();
172  }
173 
174  void unlock()
175  {
176  mutex.unlock();
177  }
178 
179  boost::mutex *native_handle()
180  {
181  return &mutex;
182  }
183 };
184 
185 DRIZZLED_API void thr_lock_init(THR_LOCK *lock);
186 enum_thr_lock_result thr_multi_lock(Session&, THR_LOCK_DATA**, uint32_t count, THR_LOCK_OWNER*);
187 void thr_multi_unlock(THR_LOCK_DATA**, uint32_t count);
188 
189 } /* namespace drizzled */
190 
TODO: Rename this file - func.h is stupid.
#define DRIZZLED_API
Definition: visibility.h:62
Visibility Control Macros.