~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/thr_lock.cc

  • Committer: Brian Aker
  • Date: 2010-11-26 22:40:33 UTC
  • mto: This revision was merged to the branch mainline in revision 1958.
  • Revision ID: brian@tangent.org-20101126224033-yt9a3o82w2rhaihp
Adding select for update test with flush locks engaged.

Show diffs side-by-side

added added

removed removed

Lines of Context:
52
52
 
53
53
*/
54
54
 
55
 
#include <config.h>
56
 
#include <drizzled/internal/my_sys.h>
57
 
#include <drizzled/internal/thread_var.h>
58
 
#include <drizzled/statistics_variables.h>
59
 
#include <drizzled/pthread_globals.h>
 
55
#include "config.h"
 
56
#include "drizzled/internal/my_sys.h"
 
57
#include "drizzled/internal/thread_var.h"
 
58
#include "drizzled/statistics_variables.h"
 
59
#include "drizzled/pthread_globals.h"
60
60
 
61
 
#include <drizzled/session.h>
 
61
#include "drizzled/session.h"
 
62
#include "drizzled/current_session.h"
62
63
 
63
64
#include "thr_lock.h"
64
 
#include <drizzled/internal/m_string.h>
 
65
#include "drizzled/internal/m_string.h"
65
66
#include <errno.h>
66
67
#include <list>
67
68
 
91
92
 
92
93
uint64_t max_write_lock_count= UINT64_MAX;
93
94
 
 
95
void thr_multi_unlock(THR_LOCK_DATA **data,uint32_t count);
 
96
 
94
97
/*
95
98
** For the future (now the thread specific cond is alloced by my_pthread.c)
96
99
*/
117
120
void THR_LOCK_INFO::init()
118
121
{
119
122
  internal::st_my_thread_var *tmp= my_thread_var;
 
123
  thread= tmp->pthread_self;
120
124
  thread_id= tmp->id;
121
125
  n_cursors= 0;
122
126
}
147
151
static void wake_up_waiters(THR_LOCK *lock);
148
152
 
149
153
 
150
 
static enum enum_thr_lock_result wait_for_lock(Session &session, struct st_lock_list *wait, THR_LOCK_DATA *data)
 
154
static enum enum_thr_lock_result wait_for_lock(struct st_lock_list *wait, THR_LOCK_DATA *data, bool in_wait_list)
151
155
{
152
 
  internal::st_my_thread_var *thread_var= session.getThreadVar();
 
156
  Session *session= current_session;
 
157
  internal::st_my_thread_var *thread_var= session->getThreadVar();
153
158
 
154
159
  boost::condition_variable_any *cond= &thread_var->suspend;
155
160
  enum enum_thr_lock_result result= THR_LOCK_ABORTED;
156
161
  bool can_deadlock= test(data->owner->info->n_cursors);
157
162
 
 
163
  if (!in_wait_list)
158
164
  {
159
165
    (*wait->last)=data;                         /* Wait for lock */
160
166
    data->prev= wait->last;
168
174
  thread_var->current_cond=  &thread_var->suspend;
169
175
  data->cond= &thread_var->suspend;;
170
176
 
171
 
  while (not thread_var->abort)
 
177
  while (!thread_var->abort || in_wait_list)
172
178
  {
173
179
    boost_unique_lock_t scoped(*data->lock->native_handle(), boost::adopt_lock_t());
174
180
 
234
240
}
235
241
 
236
242
 
237
 
static enum enum_thr_lock_result thr_lock(Session &session, THR_LOCK_DATA *data, THR_LOCK_OWNER *owner, enum thr_lock_type lock_type)
 
243
static enum enum_thr_lock_result thr_lock(THR_LOCK_DATA *data, THR_LOCK_OWNER *owner, enum thr_lock_type lock_type)
238
244
{
239
245
  THR_LOCK *lock= data->lock;
240
246
  enum enum_thr_lock_result result= THR_LOCK_SUCCESS;
382
388
  }
383
389
 
384
390
  /* Can't get lock yet;  Wait for it */
385
 
  return(wait_for_lock(session, wait_queue, data));
 
391
  return(wait_for_lock(wait_queue, data, 0));
386
392
end:
387
393
  lock->unlock();
388
394
 
589
595
 
590
596
 
591
597
enum enum_thr_lock_result
592
 
thr_multi_lock(Session &session, THR_LOCK_DATA **data, uint32_t count, THR_LOCK_OWNER *owner)
 
598
thr_multi_lock(THR_LOCK_DATA **data, uint32_t count, THR_LOCK_OWNER *owner)
593
599
{
594
600
  THR_LOCK_DATA **pos,**end;
595
601
  if (count > 1)
597
603
  /* lock everything */
598
604
  for (pos=data,end=data+count; pos < end ; pos++)
599
605
  {
600
 
    enum enum_thr_lock_result result= thr_lock(session, *pos, owner, (*pos)->type);
 
606
    enum enum_thr_lock_result result= thr_lock(*pos, owner, (*pos)->type);
601
607
    if (result != THR_LOCK_SUCCESS)
602
608
    {                                           /* Aborted */
603
609
      thr_multi_unlock(data,(uint32_t) (pos-data));