~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/thr_lock.cc

  • Committer: Monty Taylor
  • Date: 2010-10-08 17:32:00 UTC
  • mto: This revision was merged to the branch mainline in revision 1833.
  • Revision ID: mordred@inaugust.com-20101008173200-iq22jo2nic48noa3
Updated pandora-build files to version 0.157

Show diffs side-by-side

added added

removed removed

Lines of Context:
56
56
#include "drizzled/internal/my_sys.h"
57
57
#include "drizzled/internal/thread_var.h"
58
58
#include "drizzled/statistics_variables.h"
59
 
#include "drizzled/pthread_globals.h"
60
59
 
61
60
#include "drizzled/session.h"
 
61
#include "drizzled/current_session.h"
62
62
 
63
63
#include "thr_lock.h"
64
64
#include "drizzled/internal/m_string.h"
91
91
 
92
92
uint64_t max_write_lock_count= UINT64_MAX;
93
93
 
94
 
void thr_multi_unlock(THR_LOCK_DATA **data,uint32_t count);
95
 
 
96
94
/*
97
95
** For the future (now the thread specific cond is alloced by my_pthread.c)
98
96
*/
119
117
void THR_LOCK_INFO::init()
120
118
{
121
119
  internal::st_my_thread_var *tmp= my_thread_var;
 
120
  thread= tmp->pthread_self;
122
121
  thread_id= tmp->id;
123
122
  n_cursors= 0;
124
123
}
149
148
static void wake_up_waiters(THR_LOCK *lock);
150
149
 
151
150
 
152
 
static enum enum_thr_lock_result wait_for_lock(Session &session, struct st_lock_list *wait, THR_LOCK_DATA *data)
 
151
static enum enum_thr_lock_result wait_for_lock(struct st_lock_list *wait, THR_LOCK_DATA *data, bool in_wait_list)
153
152
{
154
 
  internal::st_my_thread_var *thread_var= session.getThreadVar();
 
153
  Session *session= current_session;
 
154
  internal::st_my_thread_var *thread_var= session->getThreadVar();
155
155
 
156
 
  boost::condition_variable_any *cond= &thread_var->suspend;
 
156
  boost::condition_variable *cond= &thread_var->suspend;
157
157
  enum enum_thr_lock_result result= THR_LOCK_ABORTED;
158
158
  bool can_deadlock= test(data->owner->info->n_cursors);
159
159
 
 
160
  if (!in_wait_list)
160
161
  {
161
162
    (*wait->last)=data;                         /* Wait for lock */
162
163
    data->prev= wait->last;
170
171
  thread_var->current_cond=  &thread_var->suspend;
171
172
  data->cond= &thread_var->suspend;;
172
173
 
173
 
  while (not thread_var->abort)
 
174
  while (!thread_var->abort || in_wait_list)
174
175
  {
175
 
    boost_unique_lock_t scoped(*data->lock->native_handle(), boost::adopt_lock_t());
 
176
    boost::mutex::scoped_lock scoped(*data->lock->native_handle(), boost::adopt_lock_t());
176
177
 
177
178
    if (can_deadlock)
178
179
    {
229
230
  data->lock->unlock();
230
231
 
231
232
  /* The following must be done after unlock of lock->mutex */
232
 
  boost_unique_lock_t scopedLock(thread_var->mutex);
 
233
  boost::mutex::scoped_lock scopedLock(thread_var->mutex);
233
234
  thread_var->current_mutex= NULL;
234
235
  thread_var->current_cond= NULL;
235
236
  return(result);
236
237
}
237
238
 
238
239
 
239
 
static enum enum_thr_lock_result thr_lock(Session &session, THR_LOCK_DATA *data, THR_LOCK_OWNER *owner, enum thr_lock_type lock_type)
 
240
static enum enum_thr_lock_result thr_lock(THR_LOCK_DATA *data, THR_LOCK_OWNER *owner, enum thr_lock_type lock_type)
240
241
{
241
242
  THR_LOCK *lock= data->lock;
242
243
  enum enum_thr_lock_result result= THR_LOCK_SUCCESS;
384
385
  }
385
386
 
386
387
  /* Can't get lock yet;  Wait for it */
387
 
  return(wait_for_lock(session, wait_queue, data));
 
388
  return(wait_for_lock(wait_queue, data, 0));
388
389
end:
389
390
  lock->unlock();
390
391
 
406
407
 
407
408
  do
408
409
  {
409
 
    boost::condition_variable_any *cond= data->cond;
 
410
    boost::condition_variable *cond= data->cond;
410
411
    if ((int) data->type == (int) TL_READ_NO_INSERT)
411
412
    {
412
413
      if (using_concurrent_insert)
504
505
          lock->write.last= &data->next;
505
506
 
506
507
          {
507
 
            boost::condition_variable_any *cond= data->cond;
 
508
            boost::condition_variable *cond= data->cond;
508
509
            data->cond= NULL;                           /* Mark thread free */
509
510
            cond->notify_one(); /* Start waiting thred */
510
511
          }
531
532
              !lock->read_no_write_count))
532
533
    {
533
534
      do {
534
 
        boost::condition_variable_any *cond= data->cond;
 
535
        boost::condition_variable *cond= data->cond;
535
536
        if (((*data->prev)=data->next))         /* remove from wait-list */
536
537
          data->next->prev= data->prev;
537
538
        else
591
592
 
592
593
 
593
594
enum enum_thr_lock_result
594
 
thr_multi_lock(Session &session, THR_LOCK_DATA **data, uint32_t count, THR_LOCK_OWNER *owner)
 
595
thr_multi_lock(THR_LOCK_DATA **data, uint32_t count, THR_LOCK_OWNER *owner)
595
596
{
596
597
  THR_LOCK_DATA **pos,**end;
597
598
  if (count > 1)
599
600
  /* lock everything */
600
601
  for (pos=data,end=data+count; pos < end ; pos++)
601
602
  {
602
 
    enum enum_thr_lock_result result= thr_lock(session, *pos, owner, (*pos)->type);
 
603
    enum enum_thr_lock_result result= thr_lock(*pos, owner, (*pos)->type);
603
604
    if (result != THR_LOCK_SUCCESS)
604
605
    {                                           /* Aborted */
605
606
      thr_multi_unlock(data,(uint32_t) (pos-data));
640
641
  return;
641
642
}
642
643
 
643
 
void DrizzleLock::unlock(uint32_t count)
644
 
{
645
 
  THR_LOCK_DATA **pos,**end;
646
 
 
647
 
  for (pos= getLocks(),end= getLocks()+count; pos < end ; pos++)
648
 
  {
649
 
    if ((*pos)->type != TL_UNLOCK)
650
 
      thr_unlock(*pos);
651
 
  }
652
 
}
653
 
 
654
644
/*
655
645
  Abort all threads waiting for a lock. The lock will be upgraded to
656
646
  TL_WRITE_ONLY to abort any new accesses to the lock
658
648
 
659
649
void THR_LOCK::abort_locks()
660
650
{
661
 
  boost_unique_lock_t scopedLock(mutex);
 
651
  boost::mutex::scoped_lock scopedLock(mutex);
662
652
 
663
653
  for (THR_LOCK_DATA *local_data= read_wait.data; local_data ; local_data= local_data->next)
664
654
  {
691
681
{
692
682
  bool found= false;
693
683
 
694
 
  boost_unique_lock_t scopedLock(mutex);
 
684
  boost::mutex::scoped_lock scopedLock(mutex);
695
685
  for (THR_LOCK_DATA *local_data= read_wait.data; local_data ; local_data= local_data->next)
696
686
  {
697
687
    if (local_data->owner->info->thread_id == thread_id_arg)