12
12
You should have received a copy of the GNU General Public License
13
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 */
16
/* For use with thr_locks */
18
#ifndef DRIZZLED_THR_LOCK_H
19
#define DRIZZLED_THR_LOCK_H
21
#include <boost/thread/mutex.hpp>
22
#include <boost/thread/shared_mutex.hpp>
23
#include <boost/thread/condition_variable.hpp>
25
#include <drizzled/visibility.h>
30
extern uint64_t max_write_lock_count;
31
extern uint64_t table_lock_wait_timeout;
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
16
/* For use with thr_lock:s */
24
#include <mysys/my_pthread.h>
25
#include <mysys/my_list.h>
28
extern uint32_t locks_immediate,locks_waited ;
29
extern pthread_mutex_t THR_LOCK_lock;
34
31
enum thr_lock_type { TL_IGNORE=-1,
39
TL_READ_WITH_SHARED_LOCKS,
40
/* READ, Don't allow concurrent insert */
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.
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.
55
WRITE lock used by concurrent insert. Will allow
56
READ, if one could use concurrent insert on table.
58
TL_WRITE_CONCURRENT_INSERT,
60
parser only! Late bound low_priority flag.
32
TL_UNLOCK, /* UNLOCK ANY LOCK */
33
TL_READ, /* Read lock */
34
TL_READ_WITH_SHARED_LOCKS,
35
/* High prior. than TL_WRITE. Allow concurrent insert */
36
TL_READ_HIGH_PRIORITY,
37
/* READ, Don't allow concurrent insert */
40
Write lock, but allow other threads to read / write.
41
Used by BDB tables in MySQL to mark that someone is
42
reading/writing to the table.
46
Write lock, but allow other threads to read.
47
Used by ALTER TABLE in MySQL to allow readers
48
to use the table until ALTER TABLE is finished.
52
WRITE lock used by concurrent insert. Will allow
53
READ, if one could use concurrent insert on table.
55
TL_WRITE_CONCURRENT_INSERT,
56
/* Write used by INSERT DELAYED. Allows READ locks */
59
parser only! Late bound low_priority flag.
61
60
At open_tables() becomes thd->update_lock_default.
64
/* Normal WRITE lock */
66
/* Abort new lock request with an error */
63
/* WRITE lock that has lower priority than TL_READ */
64
TL_WRITE_LOW_PRIORITY,
65
/* Normal WRITE lock */
67
/* Abort new lock request with an error */
69
70
enum enum_thr_lock_result { THR_LOCK_SUCCESS= 0, THR_LOCK_ABORTED= 1,
70
71
THR_LOCK_WAIT_TIMEOUT= 2, THR_LOCK_DEADLOCK= 3 };
74
extern ulong max_write_lock_count;
75
extern ulong table_lock_wait_timeout;
76
extern bool thr_lock_inited;
77
extern enum thr_lock_type thr_upgraded_concurrent_insert_lock;
72
80
A description of the thread which owns the lock. The address
73
81
of an instance of this structure is used to uniquely identify the thread.
84
typedef struct st_thr_lock_info
87
my_thread_id thread_id;
79
88
uint32_t n_cursors;
91
92
Lock owner identifier. Globally identifies the lock owner within the
93
94
structure is used as id.
97
typedef struct st_thr_lock_owner
98
99
THR_LOCK_INFO *info;
107
struct THR_LOCK_DATA;
109
struct DRIZZLED_API THR_LOCK_DATA {
103
typedef struct st_thr_lock_data {
110
104
THR_LOCK_OWNER *owner;
111
struct THR_LOCK_DATA *next,**prev;
112
struct THR_LOCK *lock;
113
boost::condition_variable_any *cond;
105
struct st_thr_lock_data *next,**prev;
106
struct st_thr_lock *lock;
107
pthread_cond_t *cond;
114
108
enum thr_lock_type type;
115
109
void *status_param; /* Param to status functions */
127
void init(THR_LOCK *lock,
128
void *status_param= NULL);
131
112
struct st_lock_list {
132
113
THR_LOCK_DATA *data,**last;
116
typedef struct st_thr_lock {
118
pthread_mutex_t mutex;
144
119
struct st_lock_list read_wait;
145
120
struct st_lock_list read;
146
121
struct st_lock_list write_wait;
147
122
struct st_lock_list write;
148
123
/* write_lock_count is incremented for write locks and reset on read locks */
149
124
uint32_t write_lock_count;
150
uint32_t read_no_write_count;
154
read_no_write_count(0)
161
bool abort_locks_for_thread(uint64_t thread);
181
boost::mutex *native_handle()
125
uint read_no_write_count;
126
void (*get_status)(void*, int); /* When one gets a lock */
127
void (*copy_status)(void*,void*);
128
void (*update_status)(void*); /* Before release of write */
129
void (*restore_status)(void*); /* Before release of read */
130
bool (*check_status)(void *);
134
extern LIST *thr_lock_thread_list;
136
bool init_thr_lock(void); /* Must be called once/thread */
189
137
#define thr_lock_owner_init(owner, info_arg) (owner)->info= (info_arg)
190
DRIZZLED_API void thr_lock_init(THR_LOCK *lock);
191
enum enum_thr_lock_result thr_multi_lock(Session &session, THR_LOCK_DATA **data,
192
uint32_t count, THR_LOCK_OWNER *owner);
193
void thr_multi_unlock(THR_LOCK_DATA **data,uint32_t count);
195
} /* namespace drizzled */
197
#endif /* DRIZZLED_THR_LOCK_H */
138
void thr_lock_info_init(THR_LOCK_INFO *info);
139
void thr_lock_init(THR_LOCK *lock);
140
void thr_lock_delete(THR_LOCK *lock);
141
void thr_lock_data_init(THR_LOCK *lock,THR_LOCK_DATA *data,
143
enum enum_thr_lock_result thr_lock(THR_LOCK_DATA *data,
144
THR_LOCK_OWNER *owner,
145
enum thr_lock_type lock_type);
146
void thr_unlock(THR_LOCK_DATA *data);
147
enum enum_thr_lock_result thr_multi_lock(THR_LOCK_DATA **data,
148
uint count, THR_LOCK_OWNER *owner);
149
void thr_multi_unlock(THR_LOCK_DATA **data,uint count);
150
void thr_abort_locks(THR_LOCK *lock, bool upgrade_lock);
151
bool thr_abort_locks_for_thread(THR_LOCK *lock, my_thread_id thread);
152
bool thr_upgrade_write_delay_lock(THR_LOCK_DATA *data);
153
void thr_downgrade_write_lock(THR_LOCK_DATA *data,
154
enum thr_lock_type new_lock_type);
155
bool thr_reschedule_write_lock(THR_LOCK_DATA *data);
159
#endif /* _thr_lock_h */