~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/thr_lock.cc

  • Committer: Stewart Smith
  • Date: 2009-08-20 17:15:54 UTC
  • mto: (1119.2.2 merge)
  • mto: This revision was merged to the branch mainline in revision 1124.
  • Revision ID: stewart@flamingspork.com-20090820171554-72eo1tqlc4n64rak
Valgrind 3.5 requires --alignment to be a power of 2 between 16 and 4096. The specifying --alignment is not important for us, so remove it.

Show diffs side-by-side

added added

removed removed

Lines of Context:
65
65
 
66
66
*/
67
67
 
68
 
#include "config.h"
69
 
#include "drizzled/internal/my_sys.h"
 
68
#include "mysys/mysys_priv.h"
70
69
 
71
70
#include "thr_lock.h"
72
 
#include "drizzled/internal/m_string.h"
 
71
#include <mystrings/m_string.h>
73
72
#include <errno.h>
74
73
#include <list>
75
74
 
88
87
 
89
88
using namespace std;
90
89
 
91
 
namespace drizzled
92
 
{
93
 
 
94
90
bool thr_lock_inited= false;
95
91
uint32_t locks_immediate = 0L, locks_waited = 0L;
96
92
uint64_t table_lock_wait_timeout;
97
 
static enum thr_lock_type thr_upgraded_concurrent_insert_lock = TL_WRITE;
 
93
enum thr_lock_type thr_upgraded_concurrent_insert_lock = TL_WRITE;
98
94
 
99
95
 
100
96
static list<THR_LOCK *> thr_lock_thread_list;          /* List of threads in use */
135
131
  lock->write_wait.last= &lock->write_wait.data;
136
132
  lock->write.last= &lock->write.data;
137
133
 
138
 
  pthread_mutex_lock(&internal::THR_LOCK_lock);         /* Add to locks in use */
 
134
  pthread_mutex_lock(&THR_LOCK_lock);           /* Add to locks in use */
139
135
  thr_lock_thread_list.push_front(lock);
140
 
  pthread_mutex_unlock(&internal::THR_LOCK_lock);
 
136
  pthread_mutex_unlock(&THR_LOCK_lock);
141
137
}
142
138
 
143
139
 
144
140
void thr_lock_delete(THR_LOCK *lock)
145
141
{
146
142
  pthread_mutex_destroy(&lock->mutex);
147
 
  pthread_mutex_lock(&internal::THR_LOCK_lock);
 
143
  pthread_mutex_lock(&THR_LOCK_lock);
148
144
  thr_lock_thread_list.remove(lock);
149
 
  pthread_mutex_unlock(&internal::THR_LOCK_lock);
 
145
  pthread_mutex_unlock(&THR_LOCK_lock);
150
146
}
151
147
 
152
148
 
153
149
void thr_lock_info_init(THR_LOCK_INFO *info)
154
150
{
155
 
  internal::st_my_thread_var *tmp= my_thread_var;
 
151
  struct st_my_thread_var *tmp= my_thread_var;
156
152
  info->thread= tmp->pthread_self;
157
153
  info->thread_id= tmp->id;
158
154
  info->n_cursors= 0;
188
184
wait_for_lock(struct st_lock_list *wait, THR_LOCK_DATA *data,
189
185
              bool in_wait_list)
190
186
{
191
 
  internal::st_my_thread_var *thread_var= my_thread_var;
 
187
  struct st_my_thread_var *thread_var= my_thread_var;
192
188
  pthread_cond_t *cond= &thread_var->suspend;
193
189
  struct timespec wait_timeout;
194
190
  enum enum_thr_lock_result result= THR_LOCK_ABORTED;
201
197
    wait->last= &data->next;
202
198
  }
203
199
 
204
 
  statistic_increment(locks_waited, &internal::THR_LOCK_lock);
 
200
  statistic_increment(locks_waited, &THR_LOCK_lock);
205
201
 
206
202
  /* Set up control struct to allow others to abort locks */
207
203
  thread_var->current_mutex= &data->lock->mutex;
235
231
    }
236
232
    if (rc == ETIMEDOUT || rc == ETIME)
237
233
    {
 
234
      /* purecov: begin inspected */
238
235
      result= THR_LOCK_WAIT_TIMEOUT;
239
236
      break;
 
237
      /* purecov: end */
240
238
    }
241
239
  }
242
240
  if (data->cond || data->type == TL_UNLOCK)
268
266
}
269
267
 
270
268
 
271
 
static enum enum_thr_lock_result
 
269
enum enum_thr_lock_result
272
270
thr_lock(THR_LOCK_DATA *data, THR_LOCK_OWNER *owner,
273
271
         enum thr_lock_type lock_type)
274
272
{
309
307
          lock->read_no_write_count++;
310
308
        if (lock->get_status)
311
309
          (*lock->get_status)(data->status_param, 0);
312
 
        statistic_increment(locks_immediate,&internal::THR_LOCK_lock);
 
310
        statistic_increment(locks_immediate,&THR_LOCK_lock);
313
311
        goto end;
314
312
      }
315
313
      if (lock->write.data->type == TL_WRITE_ONLY)
331
329
        (*lock->get_status)(data->status_param, 0);
332
330
      if (lock_type == TL_READ_NO_INSERT)
333
331
        lock->read_no_write_count++;
334
 
      statistic_increment(locks_immediate,&internal::THR_LOCK_lock);
 
332
      statistic_increment(locks_immediate,&THR_LOCK_lock);
335
333
      goto end;
336
334
    }
337
335
    /*
380
378
        lock->write.last= &data->next;
381
379
        if (data->lock->get_status)
382
380
          (*data->lock->get_status)(data->status_param, 0);
383
 
        statistic_increment(locks_immediate,&internal::THR_LOCK_lock);
 
381
        statistic_increment(locks_immediate,&THR_LOCK_lock);
384
382
        goto end;
385
383
      }
386
384
    }
410
408
          lock->write.last= &data->next;
411
409
          if (data->lock->get_status)
412
410
            (*data->lock->get_status)(data->status_param, concurrent_insert);
413
 
          statistic_increment(locks_immediate,&internal::THR_LOCK_lock);
 
411
          statistic_increment(locks_immediate,&THR_LOCK_lock);
414
412
          goto end;
415
413
        }
416
414
      }
481
479
 
482
480
        /* Unlock lock and free next thread on same lock */
483
481
 
484
 
static void thr_unlock(THR_LOCK_DATA *data)
 
482
void thr_unlock(THR_LOCK_DATA *data)
485
483
{
486
484
  THR_LOCK *lock=data->lock;
487
485
  enum thr_lock_type lock_type=data->type;
773
771
  This is used to abort all locks for a specific thread
774
772
*/
775
773
 
776
 
bool thr_abort_locks_for_thread(THR_LOCK *lock, uint64_t thread_id)
 
774
bool thr_abort_locks_for_thread(THR_LOCK *lock, my_thread_id thread_id)
777
775
{
778
776
  THR_LOCK_DATA *data;
779
777
  bool found= false;
781
779
  pthread_mutex_lock(&lock->mutex);
782
780
  for (data= lock->read_wait.data; data ; data= data->next)
783
781
  {
784
 
    if (data->owner->info->thread_id == thread_id)
 
782
    if (data->owner->info->thread_id == thread_id)    /* purecov: tested */
785
783
    {
786
784
      data->type= TL_UNLOCK;                    /* Mark killed */
787
785
      /* It's safe to signal the cond first: we're still holding the mutex. */
797
795
  }
798
796
  for (data= lock->write_wait.data; data ; data= data->next)
799
797
  {
800
 
    if (data->owner->info->thread_id == thread_id)
 
798
    if (data->owner->info->thread_id == thread_id) /* purecov: tested */
801
799
    {
802
800
      data->type= TL_UNLOCK;
803
801
      found= true;
814
812
  pthread_mutex_unlock(&lock->mutex);
815
813
  return(found);
816
814
}
817
 
 
818
 
} /* namespace drizzled */