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