~drizzle-trunk/drizzle/development

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
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
21
#include <pthread.h>
1122.2.10 by Monty Taylor
Fixed all of the include guards.
22
1 by brian
clean slate
23
#ifdef	__cplusplus
24
extern "C" {
25
#endif
26
27
struct st_thr_lock;
298 by Brian Aker
ulong conversion.
28
extern uint32_t locks_immediate,locks_waited ;
53.2.23 by Monty Taylor
Fixed the thr_lock double define the right direction.
29
extern pthread_mutex_t THR_LOCK_lock;
1 by brian
clean slate
30
31
622.1.1 by Brian Aker
32bit fixes around vars
32
extern uint64_t max_write_lock_count;
33
extern uint64_t table_lock_wait_timeout;
146 by Brian Aker
my_bool cleanup.
34
extern bool thr_lock_inited;
1 by brian
clean slate
35
1241.9.43 by Monty Taylor
Merged trunk. Also renamed thr_lock. Doh. I hate it when I do both.
36
37
enum thr_lock_type { TL_IGNORE=-1,
38
                     /* UNLOCK ANY LOCK */
39
                     TL_UNLOCK,
40
                     /* Read lock */
41
                     TL_READ,
42
                     TL_READ_WITH_SHARED_LOCKS,
43
                     /* READ, Don't allow concurrent insert */
44
                     TL_READ_NO_INSERT,
45
                     /*
46
                       Write lock, but allow other threads to read / write.
47
                       Used by BDB tables in MySQL to mark that someone is
48
                       reading/writing to the table.
49
                     */
50
                     TL_WRITE_ALLOW_WRITE,
51
                     /*
52
                       Write lock, but allow other threads to read.
53
                       Used by ALTER TABLE in MySQL to allow readers
54
                       to use the table until ALTER TABLE is finished.
55
                     */
56
                     TL_WRITE_ALLOW_READ,
57
                     /*
58
                       WRITE lock used by concurrent insert. Will allow
59
                       READ, if one could use concurrent insert on table.
60
                     */
61
                     TL_WRITE_CONCURRENT_INSERT,
62
                     /*
63
                       parser only! Late bound low_priority flag.
64
                       At open_tables() becomes thd->update_lock_default.
65
                     */
66
                     TL_WRITE_DEFAULT,
67
                     /* Normal WRITE lock */
68
                     TL_WRITE,
69
                     /* Abort new lock request with an error */
70
                     TL_WRITE_ONLY};
71
72
enum enum_thr_lock_result { THR_LOCK_SUCCESS= 0, THR_LOCK_ABORTED= 1,
73
                            THR_LOCK_WAIT_TIMEOUT= 2, THR_LOCK_DEADLOCK= 3 };
1 by brian
clean slate
74
/*
75
  A description of the thread which owns the lock. The address
76
  of an instance of this structure is used to uniquely identify the thread.
77
*/
78
79
typedef struct st_thr_lock_info
80
{
81
  pthread_t thread;
1241.9.43 by Monty Taylor
Merged trunk. Also renamed thr_lock. Doh. I hate it when I do both.
82
  uint64_t thread_id;
298 by Brian Aker
ulong conversion.
83
  uint32_t n_cursors;
1 by brian
clean slate
84
} THR_LOCK_INFO;
85
86
/*
87
  Lock owner identifier. Globally identifies the lock owner within the
88
  thread and among all the threads. The address of an instance of this
89
  structure is used as id.
90
*/
91
92
typedef struct st_thr_lock_owner
93
{
94
  THR_LOCK_INFO *info;
95
} THR_LOCK_OWNER;
96
97
98
typedef struct st_thr_lock_data {
99
  THR_LOCK_OWNER *owner;
100
  struct st_thr_lock_data *next,**prev;
101
  struct st_thr_lock *lock;
102
  pthread_cond_t *cond;
103
  enum thr_lock_type type;
104
  void *status_param;			/* Param to status functions */
105
} THR_LOCK_DATA;
106
107
struct st_lock_list {
108
  THR_LOCK_DATA *data,**last;
109
};
110
111
typedef struct st_thr_lock {
112
  pthread_mutex_t mutex;
113
  struct st_lock_list read_wait;
114
  struct st_lock_list read;
115
  struct st_lock_list write_wait;
116
  struct st_lock_list write;
117
  /* write_lock_count is incremented for write locks and reset on read locks */
298 by Brian Aker
ulong conversion.
118
  uint32_t write_lock_count;
482 by Brian Aker
Remove uint.
119
  uint32_t read_no_write_count;
1 by brian
clean slate
120
  void (*get_status)(void*, int);	/* When one gets a lock */
121
  void (*copy_status)(void*,void*);
122
  void (*update_status)(void*);		/* Before release of write */
123
  void (*restore_status)(void*);         /* Before release of read */
146 by Brian Aker
my_bool cleanup.
124
  bool (*check_status)(void *);
1 by brian
clean slate
125
} THR_LOCK;
126
127
146 by Brian Aker
my_bool cleanup.
128
bool init_thr_lock(void);		/* Must be called once/thread */
1 by brian
clean slate
129
#define thr_lock_owner_init(owner, info_arg) (owner)->info= (info_arg)
130
void thr_lock_info_init(THR_LOCK_INFO *info);
131
void thr_lock_init(THR_LOCK *lock);
132
void thr_lock_delete(THR_LOCK *lock);
133
void thr_lock_data_init(THR_LOCK *lock,THR_LOCK_DATA *data,
134
			void *status_param);
135
enum enum_thr_lock_result thr_multi_lock(THR_LOCK_DATA **data,
482 by Brian Aker
Remove uint.
136
                                         uint32_t count, THR_LOCK_OWNER *owner);
137
void thr_multi_unlock(THR_LOCK_DATA **data,uint32_t count);
1113.1.2 by Brian Aker
Refactor/kill some dead lock code.
138
void thr_abort_locks(THR_LOCK *lock);
1241.9.43 by Monty Taylor
Merged trunk. Also renamed thr_lock. Doh. I hate it when I do both.
139
bool thr_abort_locks_for_thread(THR_LOCK *lock, uint64_t thread);
1 by brian
clean slate
140
#ifdef	__cplusplus
141
}
142
#endif
1241.9.43 by Monty Taylor
Merged trunk. Also renamed thr_lock. Doh. I hate it when I do both.
143
#endif /* DRIZZLED_THR_LOCK_H */