~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/thr_lock.cc

  • Committer: Andrew Hutchings
  • Date: 2010-10-17 16:04:42 UTC
  • mto: This revision was merged to the branch mainline in revision 1861.
  • Revision ID: andrew@linuxjedi.co.uk-20101017160442-htkekkxyny0qrzfk
Add unit tests for libdrizzle utility functions
Fix drizzle_escape_string

Show diffs side-by-side

added added

removed removed

Lines of Context:
59
59
#include "drizzled/pthread_globals.h"
60
60
 
61
61
#include "drizzled/session.h"
 
62
#include "drizzled/current_session.h"
62
63
 
63
64
#include "thr_lock.h"
64
65
#include "drizzled/internal/m_string.h"
91
92
 
92
93
uint64_t max_write_lock_count= UINT64_MAX;
93
94
 
94
 
void thr_multi_unlock(THR_LOCK_DATA **data,uint32_t count);
95
 
 
96
95
/*
97
96
** For the future (now the thread specific cond is alloced by my_pthread.c)
98
97
*/
119
118
void THR_LOCK_INFO::init()
120
119
{
121
120
  internal::st_my_thread_var *tmp= my_thread_var;
 
121
  thread= tmp->pthread_self;
122
122
  thread_id= tmp->id;
123
123
  n_cursors= 0;
124
124
}
149
149
static void wake_up_waiters(THR_LOCK *lock);
150
150
 
151
151
 
152
 
static enum enum_thr_lock_result wait_for_lock(Session &session, struct st_lock_list *wait, THR_LOCK_DATA *data)
 
152
static enum enum_thr_lock_result wait_for_lock(struct st_lock_list *wait, THR_LOCK_DATA *data, bool in_wait_list)
153
153
{
154
 
  internal::st_my_thread_var *thread_var= session.getThreadVar();
 
154
  Session *session= current_session;
 
155
  internal::st_my_thread_var *thread_var= session->getThreadVar();
155
156
 
156
157
  boost::condition_variable_any *cond= &thread_var->suspend;
157
158
  enum enum_thr_lock_result result= THR_LOCK_ABORTED;
158
159
  bool can_deadlock= test(data->owner->info->n_cursors);
159
160
 
 
161
  if (!in_wait_list)
160
162
  {
161
163
    (*wait->last)=data;                         /* Wait for lock */
162
164
    data->prev= wait->last;
170
172
  thread_var->current_cond=  &thread_var->suspend;
171
173
  data->cond= &thread_var->suspend;;
172
174
 
173
 
  while (not thread_var->abort)
 
175
  while (!thread_var->abort || in_wait_list)
174
176
  {
175
177
    boost_unique_lock_t scoped(*data->lock->native_handle(), boost::adopt_lock_t());
176
178
 
236
238
}
237
239
 
238
240
 
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)
 
241
static enum enum_thr_lock_result thr_lock(THR_LOCK_DATA *data, THR_LOCK_OWNER *owner, enum thr_lock_type lock_type)
240
242
{
241
243
  THR_LOCK *lock= data->lock;
242
244
  enum enum_thr_lock_result result= THR_LOCK_SUCCESS;
384
386
  }
385
387
 
386
388
  /* Can't get lock yet;  Wait for it */
387
 
  return(wait_for_lock(session, wait_queue, data));
 
389
  return(wait_for_lock(wait_queue, data, 0));
388
390
end:
389
391
  lock->unlock();
390
392
 
591
593
 
592
594
 
593
595
enum enum_thr_lock_result
594
 
thr_multi_lock(Session &session, THR_LOCK_DATA **data, uint32_t count, THR_LOCK_OWNER *owner)
 
596
thr_multi_lock(THR_LOCK_DATA **data, uint32_t count, THR_LOCK_OWNER *owner)
595
597
{
596
598
  THR_LOCK_DATA **pos,**end;
597
599
  if (count > 1)
599
601
  /* lock everything */
600
602
  for (pos=data,end=data+count; pos < end ; pos++)
601
603
  {
602
 
    enum enum_thr_lock_result result= thr_lock(session, *pos, owner, (*pos)->type);
 
604
    enum enum_thr_lock_result result= thr_lock(*pos, owner, (*pos)->type);
603
605
    if (result != THR_LOCK_SUCCESS)
604
606
    {                                           /* Aborted */
605
607
      thr_multi_unlock(data,(uint32_t) (pos-data));
640
642
  return;
641
643
}
642
644
 
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
645
/*
655
646
  Abort all threads waiting for a lock. The lock will be upgraded to
656
647
  TL_WRITE_ONLY to abort any new accesses to the lock