~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/thr_lock.h

  • Committer: Brian Aker
  • Date: 2010-06-03 22:55:32 UTC
  • mto: (1578.6.9 explain-drizzle)
  • mto: This revision was merged to the branch mainline in revision 1591.
  • Revision ID: brian@gir-2.local-20100603225532-5yuc8um41i4owavf
Additional pass through to remove raw field access.

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>
 
21
#include <pthread.h>
24
22
 
25
23
namespace drizzled
26
24
{
27
25
 
 
26
struct st_thr_lock;
 
27
 
 
28
namespace internal
 
29
{
 
30
extern pthread_mutex_t THR_LOCK_lock;
 
31
}
 
32
 
28
33
extern uint64_t max_write_lock_count;
29
34
extern uint64_t table_lock_wait_timeout;
 
35
extern bool thr_lock_inited;
30
36
 
31
37
 
32
38
enum thr_lock_type { TL_IGNORE=-1,
71
77
  of an instance of this structure is used to uniquely identify the thread.
72
78
*/
73
79
 
74
 
struct THR_LOCK_INFO
 
80
typedef struct st_thr_lock_info
75
81
{
 
82
  pthread_t thread;
76
83
  uint64_t thread_id;
77
84
  uint32_t n_cursors;
78
 
 
79
 
  THR_LOCK_INFO() : 
80
 
    thread_id(0),
81
 
    n_cursors(0)
82
 
  { }
83
 
 
84
 
  void init();
85
 
 
86
 
};
 
85
} THR_LOCK_INFO;
87
86
 
88
87
/*
89
88
  Lock owner identifier. Globally identifies the lock owner within the
91
90
  structure is used as id.
92
91
*/
93
92
 
94
 
struct THR_LOCK_OWNER
 
93
typedef struct st_thr_lock_owner
95
94
{
96
95
  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 {
 
96
} THR_LOCK_OWNER;
 
97
 
 
98
 
 
99
typedef struct st_thr_lock_data {
108
100
  THR_LOCK_OWNER *owner;
109
 
  struct THR_LOCK_DATA *next,**prev;
110
 
  struct THR_LOCK *lock;
111
 
  boost::condition_variable_any *cond;
 
101
  struct st_thr_lock_data *next,**prev;
 
102
  struct st_thr_lock *lock;
 
103
  pthread_cond_t *cond;
112
104
  enum thr_lock_type type;
113
105
  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
 
};
 
106
} THR_LOCK_DATA;
128
107
 
129
108
struct st_lock_list {
130
109
  THR_LOCK_DATA *data,**last;
131
 
 
132
 
  st_lock_list() :
133
 
    data(0),
134
 
    last(0)
135
 
  { }
136
110
};
137
111
 
138
 
struct THR_LOCK {
139
 
private:
140
 
  boost::mutex mutex;
141
 
public:
 
112
typedef struct st_thr_lock {
 
113
  pthread_mutex_t mutex;
142
114
  struct st_lock_list read_wait;
143
115
  struct st_lock_list read;
144
116
  struct st_lock_list write_wait;
146
118
  /* write_lock_count is incremented for write locks and reset on read locks */
147
119
  uint32_t write_lock_count;
148
120
  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
 
 
 
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 */
187
130
#define thr_lock_owner_init(owner, info_arg) (owner)->info= (info_arg)
 
131
void thr_lock_info_init(THR_LOCK_INFO *info);
188
132
void thr_lock_init(THR_LOCK *lock);
189
 
enum enum_thr_lock_result thr_multi_lock(Session &session, THR_LOCK_DATA **data,
 
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,
190
137
                                         uint32_t count, THR_LOCK_OWNER *owner);
191
138
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);
192
141
 
193
142
} /* namespace drizzled */
194
143