~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/thr_lock.h

  • Committer: lbieber
  • Date: 2010-01-21 18:21:39 UTC
  • mto: This revision was merged to the branch mainline in revision 1277.
  • Revision ID: lbieber@orisndriz08-20100121182139-h549us3gsysyyl0e
clean up japanese tests, remove tests that no longer apply.  In test-run.pl change mysql_version_id to drizzle_version_id

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 
12
12
   You should have received a copy of the GNU General Public License
13
13
   along with this program; if not, write to the Free Software
14
 
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
16
/* For use with thr_locks */
17
17
 
18
18
#ifndef DRIZZLED_THR_LOCK_H
19
19
#define DRIZZLED_THR_LOCK_H
20
20
 
21
 
#include <boost/thread/mutex.hpp>
22
 
#include <boost/thread/shared_mutex.hpp>
23
 
#include <boost/thread/condition_variable.hpp>
24
 
 
25
 
namespace drizzled
26
 
{
 
21
#include <pthread.h>
 
22
 
 
23
#ifdef  __cplusplus
 
24
extern "C" {
 
25
#endif
 
26
 
 
27
struct st_thr_lock;
 
28
extern uint32_t locks_immediate,locks_waited ;
 
29
extern pthread_mutex_t THR_LOCK_lock;
 
30
 
27
31
 
28
32
extern uint64_t max_write_lock_count;
29
33
extern uint64_t table_lock_wait_timeout;
 
34
extern bool thr_lock_inited;
30
35
 
31
36
 
32
37
enum thr_lock_type { TL_IGNORE=-1,
71
76
  of an instance of this structure is used to uniquely identify the thread.
72
77
*/
73
78
 
74
 
struct THR_LOCK_INFO
 
79
typedef struct st_thr_lock_info
75
80
{
 
81
  pthread_t thread;
76
82
  uint64_t thread_id;
77
83
  uint32_t n_cursors;
78
 
 
79
 
  THR_LOCK_INFO() : 
80
 
    thread_id(0),
81
 
    n_cursors(0)
82
 
  { }
83
 
 
84
 
  void init();
85
 
 
86
 
};
 
84
} THR_LOCK_INFO;
87
85
 
88
86
/*
89
87
  Lock owner identifier. Globally identifies the lock owner within the
91
89
  structure is used as id.
92
90
*/
93
91
 
94
 
struct THR_LOCK_OWNER
 
92
typedef struct st_thr_lock_owner
95
93
{
96
94
  THR_LOCK_INFO *info;
97
 
 
98
 
  THR_LOCK_OWNER() :
99
 
    info(0)
100
 
  { }
101
 
 
102
 
};
103
 
 
104
 
struct THR_LOCK;
105
 
struct THR_LOCK_DATA;
106
 
 
107
 
struct THR_LOCK_DATA {
 
95
} THR_LOCK_OWNER;
 
96
 
 
97
 
 
98
typedef struct st_thr_lock_data {
108
99
  THR_LOCK_OWNER *owner;
109
 
  struct THR_LOCK_DATA *next,**prev;
110
 
  struct THR_LOCK *lock;
111
 
  boost::condition_variable_any *cond;
 
100
  struct st_thr_lock_data *next,**prev;
 
101
  struct st_thr_lock *lock;
 
102
  pthread_cond_t *cond;
112
103
  enum thr_lock_type type;
113
104
  void *status_param;                   /* Param to status functions */
114
 
 
115
 
  THR_LOCK_DATA() :
116
 
    owner(0),
117
 
    next(0),
118
 
    prev(0),
119
 
    lock(0),
120
 
    cond(0),
121
 
    type(TL_UNLOCK),
122
 
    status_param(0)
123
 
  { }
124
 
 
125
 
  void init(THR_LOCK *lock,
126
 
            void *status_param= NULL);
127
 
};
 
105
} THR_LOCK_DATA;
128
106
 
129
107
struct st_lock_list {
130
108
  THR_LOCK_DATA *data,**last;
131
 
 
132
 
  st_lock_list() :
133
 
    data(0),
134
 
    last(0)
135
 
  { }
136
109
};
137
110
 
138
 
struct THR_LOCK {
139
 
private:
140
 
  boost::mutex mutex;
141
 
public:
 
111
typedef struct st_thr_lock {
 
112
  pthread_mutex_t mutex;
142
113
  struct st_lock_list read_wait;
143
114
  struct st_lock_list read;
144
115
  struct st_lock_list write_wait;
146
117
  /* write_lock_count is incremented for write locks and reset on read locks */
147
118
  uint32_t write_lock_count;
148
119
  uint32_t read_no_write_count;
149
 
 
150
 
  THR_LOCK() :
151
 
    write_lock_count(0),
152
 
    read_no_write_count(0)
153
 
  { }
154
 
 
155
 
  ~THR_LOCK()
156
 
  { }
157
 
 
158
 
  void abort_locks();
159
 
  bool abort_locks_for_thread(uint64_t thread);
160
 
 
161
 
  void lock()
162
 
  {
163
 
    mutex.lock();
164
 
  }
165
 
 
166
 
  void unlock()
167
 
  {
168
 
    mutex.unlock();
169
 
  }
170
 
 
171
 
  void init()
172
 
  {
173
 
  }
174
 
 
175
 
  void deinit()
176
 
  {
177
 
  }
178
 
 
179
 
  boost::mutex *native_handle()
180
 
  {
181
 
    return &mutex;
182
 
  }
183
 
};
184
 
 
185
 
class Session; 
186
 
 
 
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 */
 
124
  bool (*check_status)(void *);
 
125
} THR_LOCK;
 
126
 
 
127
 
 
128
bool init_thr_lock(void);               /* Must be called once/thread */
187
129
#define thr_lock_owner_init(owner, info_arg) (owner)->info= (info_arg)
 
130
void thr_lock_info_init(THR_LOCK_INFO *info);
188
131
void thr_lock_init(THR_LOCK *lock);
189
 
enum enum_thr_lock_result thr_multi_lock(Session &session, THR_LOCK_DATA **data,
 
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,
190
136
                                         uint32_t count, THR_LOCK_OWNER *owner);
191
137
void thr_multi_unlock(THR_LOCK_DATA **data,uint32_t count);
192
 
 
193
 
} /* namespace drizzled */
194
 
 
 
138
void thr_abort_locks(THR_LOCK *lock);
 
139
bool thr_abort_locks_for_thread(THR_LOCK *lock, uint64_t thread);
 
140
#ifdef  __cplusplus
 
141
}
 
142
#endif
195
143
#endif /* DRIZZLED_THR_LOCK_H */