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
|
|
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 |
||
212.5.13
by Monty Taylor
Moved my_sys/my_pthread/my_nosys and mysys_err to mysys. |
24 |
#include <mysys/my_pthread.h> |
212.5.28
by Monty Taylor
Moved my_bit and my_list |
25 |
#include <mysys/my_list.h> |
520.6.4
by Monty Taylor
Moved thr_lock.h out of common_includes. |
26 |
#include <mysys/definitions.h> |
1
by brian
clean slate |
27 |
|
28 |
struct st_thr_lock; |
|
298
by Brian Aker
ulong conversion. |
29 |
extern uint32_t locks_immediate,locks_waited ; |
53.2.23
by Monty Taylor
Fixed the thr_lock double define the right direction. |
30 |
extern pthread_mutex_t THR_LOCK_lock; |
1
by brian
clean slate |
31 |
|
32 |
||
622.1.1
by Brian Aker
32bit fixes around vars |
33 |
extern uint64_t max_write_lock_count; |
34 |
extern uint64_t table_lock_wait_timeout; |
|
146
by Brian Aker
my_bool cleanup. |
35 |
extern bool thr_lock_inited; |
1
by brian
clean slate |
36 |
extern enum thr_lock_type thr_upgraded_concurrent_insert_lock; |
37 |
||
38 |
/*
|
|
39 |
A description of the thread which owns the lock. The address
|
|
40 |
of an instance of this structure is used to uniquely identify the thread.
|
|
41 |
*/
|
|
42 |
||
43 |
typedef struct st_thr_lock_info |
|
44 |
{
|
|
45 |
pthread_t thread; |
|
46 |
my_thread_id thread_id; |
|
298
by Brian Aker
ulong conversion. |
47 |
uint32_t n_cursors; |
1
by brian
clean slate |
48 |
} THR_LOCK_INFO; |
49 |
||
50 |
/*
|
|
51 |
Lock owner identifier. Globally identifies the lock owner within the
|
|
52 |
thread and among all the threads. The address of an instance of this
|
|
53 |
structure is used as id.
|
|
54 |
*/
|
|
55 |
||
56 |
typedef struct st_thr_lock_owner |
|
57 |
{
|
|
58 |
THR_LOCK_INFO *info; |
|
59 |
} THR_LOCK_OWNER; |
|
60 |
||
61 |
||
62 |
typedef struct st_thr_lock_data { |
|
63 |
THR_LOCK_OWNER *owner; |
|
64 |
struct st_thr_lock_data *next,**prev; |
|
65 |
struct st_thr_lock *lock; |
|
66 |
pthread_cond_t *cond; |
|
67 |
enum thr_lock_type type; |
|
68 |
void *status_param; /* Param to status functions */ |
|
69 |
} THR_LOCK_DATA; |
|
70 |
||
779.4.5
by Monty Taylor
Replaced gen_lex_hash with gperf. Yay for no more building tools to build source!!! |
71 |
/* A helper type for transactional locking. */
|
72 |
struct st_table_lock_info |
|
73 |
{
|
|
74 |
enum thr_lock_type lock_type; |
|
75 |
int lock_timeout; |
|
76 |
bool lock_transactional; |
|
77 |
};
|
|
78 |
||
1
by brian
clean slate |
79 |
struct st_lock_list { |
80 |
THR_LOCK_DATA *data,**last; |
|
81 |
};
|
|
82 |
||
83 |
typedef struct st_thr_lock { |
|
84 |
LIST list; |
|
85 |
pthread_mutex_t mutex; |
|
86 |
struct st_lock_list read_wait; |
|
87 |
struct st_lock_list read; |
|
88 |
struct st_lock_list write_wait; |
|
89 |
struct st_lock_list write; |
|
90 |
/* write_lock_count is incremented for write locks and reset on read locks */
|
|
298
by Brian Aker
ulong conversion. |
91 |
uint32_t write_lock_count; |
482
by Brian Aker
Remove uint. |
92 |
uint32_t read_no_write_count; |
1
by brian
clean slate |
93 |
void (*get_status)(void*, int); /* When one gets a lock */ |
94 |
void (*copy_status)(void*,void*); |
|
95 |
void (*update_status)(void*); /* Before release of write */ |
|
96 |
void (*restore_status)(void*); /* Before release of read */ |
|
146
by Brian Aker
my_bool cleanup. |
97 |
bool (*check_status)(void *); |
1
by brian
clean slate |
98 |
} THR_LOCK; |
99 |
||
100 |
||
101 |
extern LIST *thr_lock_thread_list; |
|
102 |
||
146
by Brian Aker
my_bool cleanup. |
103 |
bool init_thr_lock(void); /* Must be called once/thread */ |
1
by brian
clean slate |
104 |
#define thr_lock_owner_init(owner, info_arg) (owner)->info= (info_arg)
|
105 |
void thr_lock_info_init(THR_LOCK_INFO *info); |
|
106 |
void thr_lock_init(THR_LOCK *lock); |
|
107 |
void thr_lock_delete(THR_LOCK *lock); |
|
108 |
void thr_lock_data_init(THR_LOCK *lock,THR_LOCK_DATA *data, |
|
109 |
void *status_param); |
|
110 |
enum enum_thr_lock_result thr_lock(THR_LOCK_DATA *data, |
|
111 |
THR_LOCK_OWNER *owner, |
|
112 |
enum thr_lock_type lock_type); |
|
113 |
void thr_unlock(THR_LOCK_DATA *data); |
|
114 |
enum enum_thr_lock_result thr_multi_lock(THR_LOCK_DATA **data, |
|
482
by Brian Aker
Remove uint. |
115 |
uint32_t count, THR_LOCK_OWNER *owner); |
116 |
void thr_multi_unlock(THR_LOCK_DATA **data,uint32_t count); |
|
146
by Brian Aker
my_bool cleanup. |
117 |
void thr_abort_locks(THR_LOCK *lock, bool upgrade_lock); |
118 |
bool thr_abort_locks_for_thread(THR_LOCK *lock, my_thread_id thread); |
|
119 |
bool thr_upgrade_write_delay_lock(THR_LOCK_DATA *data); |
|
1
by brian
clean slate |
120 |
void thr_downgrade_write_lock(THR_LOCK_DATA *data, |
121 |
enum thr_lock_type new_lock_type); |
|
146
by Brian Aker
my_bool cleanup. |
122 |
bool thr_reschedule_write_lock(THR_LOCK_DATA *data); |
1
by brian
clean slate |
123 |
#ifdef __cplusplus
|
124 |
}
|
|
125 |
#endif
|
|
126 |
#endif /* _thr_lock_h */ |