~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to include/thr_lock.h

  • Committer: Brian Aker
  • Date: 2008-07-28 18:01:38 UTC
  • Revision ID: brian@tangent.org-20080728180138-q2pxlq0qiapvqsdn
Remove YEAR field type

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
   along with this program; if not, write to the Free Software
14
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
 
/* For use with thr_locks */
17
 
 
18
 
#ifndef DRIZZLED_THR_LOCK_H
19
 
#define DRIZZLED_THR_LOCK_H
20
 
 
21
 
#include <pthread.h>
22
 
 
 
16
/* For use with thr_lock:s */
 
17
 
 
18
#ifndef _thr_lock_h
 
19
#define _thr_lock_h
23
20
#ifdef  __cplusplus
24
21
extern "C" {
25
22
#endif
26
23
 
 
24
#include <my_pthread.h>
 
25
#include <my_list.h>
 
26
 
27
27
struct st_thr_lock;
28
 
extern uint32_t locks_immediate,locks_waited ;
 
28
extern ulong locks_immediate,locks_waited ;
29
29
extern pthread_mutex_t THR_LOCK_lock;
30
30
 
31
 
 
32
 
extern uint64_t max_write_lock_count;
33
 
extern uint64_t table_lock_wait_timeout;
34
 
extern bool thr_lock_inited;
35
 
 
36
 
 
37
31
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.
 
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 */
 
38
                     TL_READ_NO_INSERT,
 
39
                     /* 
 
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.
 
43
                      */
 
44
                     TL_WRITE_ALLOW_WRITE,
 
45
                     /*
 
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.
 
49
                     */
 
50
                     TL_WRITE_ALLOW_READ,
 
51
                     /*
 
52
                       WRITE lock used by concurrent insert. Will allow
 
53
                       READ, if one could use concurrent insert on table.
 
54
                     */
 
55
                     TL_WRITE_CONCURRENT_INSERT,
 
56
                     /* Write used by INSERT DELAYED.  Allows READ locks */
 
57
                     TL_WRITE_DELAYED,
 
58
                     /* 
 
59
                       parser only! Late bound low_priority flag. 
64
60
                       At open_tables() becomes thd->update_lock_default.
65
61
                     */
66
62
                     TL_WRITE_DEFAULT,
67
 
                     /* Normal WRITE lock */
68
 
                     TL_WRITE,
69
 
                     /* Abort new lock request with an error */
70
 
                     TL_WRITE_ONLY};
 
63
                     /* WRITE lock that has lower priority than TL_READ */
 
64
                     TL_WRITE_LOW_PRIORITY,
 
65
                     /* Normal WRITE lock */
 
66
                     TL_WRITE,
 
67
                     /* Abort new lock request with an error */
 
68
                     TL_WRITE_ONLY};
71
69
 
72
70
enum enum_thr_lock_result { THR_LOCK_SUCCESS= 0, THR_LOCK_ABORTED= 1,
73
71
                            THR_LOCK_WAIT_TIMEOUT= 2, THR_LOCK_DEADLOCK= 3 };
 
72
 
 
73
 
 
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;
 
78
 
74
79
/*
75
80
  A description of the thread which owns the lock. The address
76
81
  of an instance of this structure is used to uniquely identify the thread.
79
84
typedef struct st_thr_lock_info
80
85
{
81
86
  pthread_t thread;
82
 
  uint64_t thread_id;
83
 
  uint32_t n_cursors;
 
87
  my_thread_id thread_id;
 
88
  ulong n_cursors;
84
89
} THR_LOCK_INFO;
85
90
 
86
91
/*
109
114
};
110
115
 
111
116
typedef struct st_thr_lock {
 
117
  LIST list;
112
118
  pthread_mutex_t mutex;
113
119
  struct st_lock_list read_wait;
114
120
  struct st_lock_list read;
115
121
  struct st_lock_list write_wait;
116
122
  struct st_lock_list write;
117
123
  /* write_lock_count is incremented for write locks and reset on read locks */
118
 
  uint32_t write_lock_count;
119
 
  uint32_t read_no_write_count;
 
124
  ulong write_lock_count;
 
125
  uint read_no_write_count;
120
126
  void (*get_status)(void*, int);       /* When one gets a lock */
121
127
  void (*copy_status)(void*,void*);
122
128
  void (*update_status)(void*);         /* Before release of write */
125
131
} THR_LOCK;
126
132
 
127
133
 
 
134
extern LIST *thr_lock_thread_list;
 
135
 
128
136
bool init_thr_lock(void);               /* Must be called once/thread */
129
137
#define thr_lock_owner_init(owner, info_arg) (owner)->info= (info_arg)
130
138
void thr_lock_info_init(THR_LOCK_INFO *info);
132
140
void thr_lock_delete(THR_LOCK *lock);
133
141
void thr_lock_data_init(THR_LOCK *lock,THR_LOCK_DATA *data,
134
142
                        void *status_param);
 
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);
135
147
enum enum_thr_lock_result thr_multi_lock(THR_LOCK_DATA **data,
136
 
                                         uint32_t count, THR_LOCK_OWNER *owner);
137
 
void thr_multi_unlock(THR_LOCK_DATA **data,uint32_t count);
138
 
void thr_abort_locks(THR_LOCK *lock);
139
 
bool thr_abort_locks_for_thread(THR_LOCK *lock, uint64_t thread);
 
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
void thr_print_locks(void);             /* For debugging */
 
153
bool thr_upgrade_write_delay_lock(THR_LOCK_DATA *data);
 
154
void    thr_downgrade_write_lock(THR_LOCK_DATA *data,
 
155
                                 enum thr_lock_type new_lock_type);
 
156
bool thr_reschedule_write_lock(THR_LOCK_DATA *data);
140
157
#ifdef  __cplusplus
141
158
}
142
159
#endif
143
 
#endif /* DRIZZLED_THR_LOCK_H */
 
160
#endif /* _thr_lock_h */