~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to include/thr_lock.h

  • Committer: brian
  • Date: 2008-06-25 05:29:13 UTC
  • Revision ID: brian@localhost.localdomain-20080625052913-6upwo0jsrl4lnapl
clean slate

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
extern "C" {
22
22
#endif
23
23
 
24
 
#include <mysys/my_pthread.h>
25
 
#include <mysys/my_list.h>
26
 
#include <mysys/definitions.h>
 
24
#include <my_pthread.h>
 
25
#include <my_list.h>
27
26
 
28
27
struct st_thr_lock;
29
 
extern uint32_t locks_immediate,locks_waited ;
30
 
extern pthread_mutex_t THR_LOCK_lock;
31
 
 
32
 
 
33
 
extern uint64_t max_write_lock_count;
34
 
extern uint64_t table_lock_wait_timeout;
35
 
extern bool thr_lock_inited;
 
28
extern ulong locks_immediate,locks_waited ;
 
29
 
 
30
enum thr_lock_type { TL_IGNORE=-1,
 
31
                     TL_UNLOCK,                 /* UNLOCK ANY LOCK */
 
32
                     TL_READ,                   /* Read lock */
 
33
                     TL_READ_WITH_SHARED_LOCKS,
 
34
                     /* High prior. than TL_WRITE. Allow concurrent insert */
 
35
                     TL_READ_HIGH_PRIORITY,
 
36
                     /* READ, Don't allow concurrent insert */
 
37
                     TL_READ_NO_INSERT,
 
38
                     /* 
 
39
                        Write lock, but allow other threads to read / write.
 
40
                        Used by BDB tables in MySQL to mark that someone is
 
41
                        reading/writing to the table.
 
42
                      */
 
43
                     TL_WRITE_ALLOW_WRITE,
 
44
                     /*
 
45
                        Write lock, but allow other threads to read.
 
46
                        Used by ALTER TABLE in MySQL to allow readers
 
47
                        to use the table until ALTER TABLE is finished.
 
48
                     */
 
49
                     TL_WRITE_ALLOW_READ,
 
50
                     /*
 
51
                       WRITE lock used by concurrent insert. Will allow
 
52
                       READ, if one could use concurrent insert on table.
 
53
                     */
 
54
                     TL_WRITE_CONCURRENT_INSERT,
 
55
                     /* Write used by INSERT DELAYED.  Allows READ locks */
 
56
                     TL_WRITE_DELAYED,
 
57
                     /* 
 
58
                       parser only! Late bound low_priority flag. 
 
59
                       At open_tables() becomes thd->update_lock_default.
 
60
                     */
 
61
                     TL_WRITE_DEFAULT,
 
62
                     /* WRITE lock that has lower priority than TL_READ */
 
63
                     TL_WRITE_LOW_PRIORITY,
 
64
                     /* Normal WRITE lock */
 
65
                     TL_WRITE,
 
66
                     /* Abort new lock request with an error */
 
67
                     TL_WRITE_ONLY};
 
68
 
 
69
enum enum_thr_lock_result { THR_LOCK_SUCCESS= 0, THR_LOCK_ABORTED= 1,
 
70
                            THR_LOCK_WAIT_TIMEOUT= 2, THR_LOCK_DEADLOCK= 3 };
 
71
 
 
72
 
 
73
extern ulong max_write_lock_count;
 
74
extern ulong table_lock_wait_timeout;
 
75
extern my_bool thr_lock_inited;
36
76
extern enum thr_lock_type thr_upgraded_concurrent_insert_lock;
37
77
 
38
78
/*
44
84
{
45
85
  pthread_t thread;
46
86
  my_thread_id thread_id;
47
 
  uint32_t n_cursors;
 
87
  ulong n_cursors;
48
88
} THR_LOCK_INFO;
49
89
 
50
90
/*
66
106
  pthread_cond_t *cond;
67
107
  enum thr_lock_type type;
68
108
  void *status_param;                   /* Param to status functions */
 
109
  void *debug_print_param;
69
110
} THR_LOCK_DATA;
70
111
 
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
 
 
79
112
struct st_lock_list {
80
113
  THR_LOCK_DATA *data,**last;
81
114
};
88
121
  struct st_lock_list write_wait;
89
122
  struct st_lock_list write;
90
123
  /* write_lock_count is incremented for write locks and reset on read locks */
91
 
  uint32_t write_lock_count;
92
 
  uint32_t read_no_write_count;
 
124
  ulong write_lock_count;
 
125
  uint read_no_write_count;
93
126
  void (*get_status)(void*, int);       /* When one gets a lock */
94
127
  void (*copy_status)(void*,void*);
95
128
  void (*update_status)(void*);         /* Before release of write */
96
129
  void (*restore_status)(void*);         /* Before release of read */
97
 
  bool (*check_status)(void *);
 
130
  my_bool (*check_status)(void *);
98
131
} THR_LOCK;
99
132
 
100
133
 
101
134
extern LIST *thr_lock_thread_list;
 
135
extern pthread_mutex_t THR_LOCK_lock;
102
136
 
103
 
bool init_thr_lock(void);               /* Must be called once/thread */
 
137
my_bool init_thr_lock(void);            /* Must be called once/thread */
104
138
#define thr_lock_owner_init(owner, info_arg) (owner)->info= (info_arg)
105
139
void thr_lock_info_init(THR_LOCK_INFO *info);
106
140
void thr_lock_init(THR_LOCK *lock);
112
146
                                   enum thr_lock_type lock_type);
113
147
void thr_unlock(THR_LOCK_DATA *data);
114
148
enum enum_thr_lock_result thr_multi_lock(THR_LOCK_DATA **data,
115
 
                                         uint32_t count, THR_LOCK_OWNER *owner);
116
 
void thr_multi_unlock(THR_LOCK_DATA **data,uint32_t count);
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);
 
149
                                         uint count, THR_LOCK_OWNER *owner);
 
150
void thr_multi_unlock(THR_LOCK_DATA **data,uint count);
 
151
void thr_abort_locks(THR_LOCK *lock, my_bool upgrade_lock);
 
152
my_bool thr_abort_locks_for_thread(THR_LOCK *lock, my_thread_id thread);
 
153
void thr_print_locks(void);             /* For debugging */
 
154
my_bool thr_upgrade_write_delay_lock(THR_LOCK_DATA *data);
120
155
void    thr_downgrade_write_lock(THR_LOCK_DATA *data,
121
156
                                 enum thr_lock_type new_lock_type);
122
 
bool thr_reschedule_write_lock(THR_LOCK_DATA *data);
 
157
my_bool thr_reschedule_write_lock(THR_LOCK_DATA *data);
123
158
#ifdef  __cplusplus
124
159
}
125
160
#endif