~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/thr_lock.h

  • Committer: lbieber
  • Date: 2010-08-04 22:35:53 UTC
  • mfrom: (1685.3.1 drizzle)
  • mto: This revision was merged to the branch mainline in revision 1687.
  • Revision ID: lbieber@orisndriz03-20100804223553-9q2sz4yc1fvkpup4
Merge Brian - custom lock encapsulation, and myisam lock removel code

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
namespace drizzled
24
24
{
25
25
 
26
 
struct st_thr_lock;
27
 
 
28
 
namespace internal
29
 
{
30
 
extern pthread_mutex_t THR_LOCK_lock;
31
 
}
32
 
 
33
26
extern uint64_t max_write_lock_count;
34
27
extern uint64_t table_lock_wait_timeout;
35
 
extern bool thr_lock_inited;
36
28
 
37
29
 
38
30
enum thr_lock_type { TL_IGNORE=-1,
77
69
  of an instance of this structure is used to uniquely identify the thread.
78
70
*/
79
71
 
80
 
typedef struct st_thr_lock_info
 
72
struct THR_LOCK_INFO
81
73
{
82
74
  pthread_t thread;
83
75
  uint64_t thread_id;
84
76
  uint32_t n_cursors;
85
 
} THR_LOCK_INFO;
 
77
 
 
78
  THR_LOCK_INFO() : 
 
79
    thread(0),
 
80
    thread_id(0),
 
81
    n_cursors(0)
 
82
  { }
 
83
 
 
84
};
86
85
 
87
86
/*
88
87
  Lock owner identifier. Globally identifies the lock owner within the
90
89
  structure is used as id.
91
90
*/
92
91
 
93
 
typedef struct st_thr_lock_owner
 
92
struct THR_LOCK_OWNER
94
93
{
95
94
  THR_LOCK_INFO *info;
96
 
} THR_LOCK_OWNER;
97
 
 
98
 
 
99
 
typedef struct st_thr_lock_data {
 
95
 
 
96
  THR_LOCK_OWNER() :
 
97
    info(0)
 
98
  { }
 
99
 
 
100
};
 
101
 
 
102
struct THR_LOCK;
 
103
struct THR_LOCK_DATA;
 
104
 
 
105
struct THR_LOCK_DATA {
100
106
  THR_LOCK_OWNER *owner;
101
 
  struct st_thr_lock_data *next,**prev;
102
 
  struct st_thr_lock *lock;
 
107
  struct THR_LOCK_DATA *next,**prev;
 
108
  struct THR_LOCK *lock;
103
109
  pthread_cond_t *cond;
104
110
  enum thr_lock_type type;
105
111
  void *status_param;                   /* Param to status functions */
106
 
} THR_LOCK_DATA;
 
112
 
 
113
  THR_LOCK_DATA() :
 
114
    owner(0),
 
115
    next(0),
 
116
    prev(0),
 
117
    lock(0),
 
118
    cond(0),
 
119
    type(TL_UNLOCK),
 
120
    status_param(0)
 
121
  { }
 
122
};
107
123
 
108
124
struct st_lock_list {
109
125
  THR_LOCK_DATA *data,**last;
 
126
 
 
127
  st_lock_list() :
 
128
    data(0),
 
129
    last(0)
 
130
  { }
110
131
};
111
132
 
112
 
typedef struct st_thr_lock {
 
133
struct THR_LOCK {
113
134
  pthread_mutex_t mutex;
114
135
  struct st_lock_list read_wait;
115
136
  struct st_lock_list read;
118
139
  /* write_lock_count is incremented for write locks and reset on read locks */
119
140
  uint32_t write_lock_count;
120
141
  uint32_t read_no_write_count;
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 */
125
 
  bool (*check_status)(void *);
126
 
} THR_LOCK;
127
 
 
128
 
 
129
 
bool init_thr_lock(void);               /* Must be called once/thread */
 
142
 
 
143
  THR_LOCK() :
 
144
    write_lock_count(0),
 
145
    read_no_write_count(0)
 
146
  { }
 
147
 
 
148
  ~THR_LOCK()
 
149
  { }
 
150
 
 
151
  void abort_locks();
 
152
  bool abort_locks_for_thread(uint64_t thread);
 
153
 
 
154
  void lock()
 
155
  {
 
156
    pthread_mutex_lock(&mutex);
 
157
  }
 
158
 
 
159
  void unlock()
 
160
  {
 
161
    pthread_mutex_unlock(&mutex);
 
162
  }
 
163
 
 
164
  void init()
 
165
  {
 
166
    pthread_mutex_init(&mutex, NULL);
 
167
  }
 
168
 
 
169
  void deinit()
 
170
  {
 
171
    pthread_mutex_destroy(&mutex);
 
172
  }
 
173
 
 
174
  pthread_mutex_t *native_handle()
 
175
  {
 
176
    return &mutex;
 
177
  }
 
178
};
 
179
 
 
180
 
130
181
#define thr_lock_owner_init(owner, info_arg) (owner)->info= (info_arg)
131
182
void thr_lock_info_init(THR_LOCK_INFO *info);
132
183
void thr_lock_init(THR_LOCK *lock);
133
184
void thr_lock_delete(THR_LOCK *lock);
134
185
void thr_lock_data_init(THR_LOCK *lock,THR_LOCK_DATA *data,
135
 
                        void *status_param);
 
186
                        void *status_param= NULL);
136
187
enum enum_thr_lock_result thr_multi_lock(THR_LOCK_DATA **data,
137
188
                                         uint32_t count, THR_LOCK_OWNER *owner);
138
189
void thr_multi_unlock(THR_LOCK_DATA **data,uint32_t count);
139
 
void thr_abort_locks(THR_LOCK *lock);
140
 
bool thr_abort_locks_for_thread(THR_LOCK *lock, uint64_t thread);
141
190
 
142
191
} /* namespace drizzled */
143
192