~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/thr_lock.c

  • Committer: Monty Taylor
  • Date: 2008-09-15 17:24:04 UTC
  • Revision ID: monty@inaugust.com-20080915172404-ygh6hiyu0q7qpa9x
Removed strndup calls.

Show diffs side-by-side

added added

removed removed

Lines of Context:
76
76
#include <mystrings/m_string.h>
77
77
#include <errno.h>
78
78
 
79
 
#if TIME_WITH_SYS_TIME
80
 
# include <sys/time.h>
81
 
# include <time.h>
82
 
#else
83
 
# if HAVE_SYS_TIME_H
84
 
#  include <sys/time.h>
85
 
# else
86
 
#  include <time.h>
87
 
# endif
88
 
#endif  
89
 
 
90
 
#include <drizzled/util/test.h>
91
 
 
92
79
bool thr_lock_inited=0;
93
80
uint32_t locks_immediate = 0L, locks_waited = 0L;
94
81
ulong table_lock_wait_timeout;
95
82
enum thr_lock_type thr_upgraded_concurrent_insert_lock = TL_WRITE;
96
83
 
 
84
/* The following constants are only for debug output */
 
85
#define MAX_THREADS 100
 
86
#define MAX_LOCKS   100
 
87
 
97
88
 
98
89
LIST *thr_lock_thread_list;                     /* List of threads in use */
99
90
ulong max_write_lock_count= ~(ulong) 0L;
120
111
}
121
112
 
122
113
#ifdef EXTRA_DEBUG
123
 
 
124
 
#define MAX_THREADS 100
125
 
#define MAX_LOCKS   100
126
114
#define MAX_FOUND_ERRORS        10              /* Report 10 first errors */
127
 
static uint32_t found_errors=0;
 
115
static uint found_errors=0;
128
116
 
129
117
static int check_lock(struct st_lock_list *list, const char* lock_type,
130
118
                      const char *where, bool same_owner, bool no_cond)
131
119
{
132
120
  THR_LOCK_DATA *data,**prev;
133
 
  uint32_t count=0;
 
121
  uint count=0;
134
122
  THR_LOCK_OWNER *first_owner;
135
123
 
136
124
  prev= &list->data;
189
177
static void check_locks(THR_LOCK *lock, const char *where,
190
178
                        bool allow_no_locks)
191
179
{
192
 
  uint32_t old_found_errors=found_errors;
 
180
  uint old_found_errors=found_errors;
193
181
 
194
182
  if (found_errors < MAX_FOUND_ERRORS)
195
183
  {
201
189
 
202
190
    if (found_errors < MAX_FOUND_ERRORS)
203
191
    {
204
 
      uint32_t count=0;
 
192
      uint count=0;
205
193
      THR_LOCK_DATA *data;
206
194
      for (data=lock->read.data ; data ; data=data->next)
207
195
      {
312
300
void thr_lock_init(THR_LOCK *lock)
313
301
{
314
302
  memset(lock, 0, sizeof(*lock));
315
 
  pthread_mutex_init(&lock->mutex,MY_MUTEX_INIT_FAST);
 
303
  VOID(pthread_mutex_init(&lock->mutex,MY_MUTEX_INIT_FAST));
316
304
  lock->read.last= &lock->read.data;
317
305
  lock->read_wait.last= &lock->read_wait.data;
318
306
  lock->write_wait.last= &lock->write_wait.data;
328
316
 
329
317
void thr_lock_delete(THR_LOCK *lock)
330
318
{
331
 
  pthread_mutex_destroy(&lock->mutex);
 
319
  VOID(pthread_mutex_destroy(&lock->mutex));
332
320
  pthread_mutex_lock(&THR_LOCK_lock);
333
321
  thr_lock_thread_list=list_delete(thr_lock_thread_list,&lock->list);
334
322
  pthread_mutex_unlock(&THR_LOCK_lock);
487
475
  data->cond=0;                                 /* safety */
488
476
  data->type=lock_type;
489
477
  data->owner= owner;                           /* Must be reset ! */
490
 
  pthread_mutex_lock(&lock->mutex);
 
478
  VOID(pthread_mutex_lock(&lock->mutex));
491
479
  check_locks(lock,(uint) lock_type <= (uint) TL_READ_NO_INSERT ?
492
480
              "enter read_lock" : "enter write_lock",0);
493
481
  if ((int) lock_type <= (int) TL_READ_NO_INSERT)
718
706
      lock->read_no_write_count++;
719
707
    }      
720
708
    data->cond=0;                               /* Mark thread free */
721
 
    pthread_cond_signal(cond);
 
709
    VOID(pthread_cond_signal(cond));
722
710
  } while ((data=data->next));
723
711
  *lock->read_wait.last=0;
724
712
  if (!lock->read_wait.data)
818
806
          {
819
807
            pthread_cond_t *cond=data->cond;
820
808
            data->cond=0;                               /* Mark thread free */
821
 
            pthread_cond_signal(cond);  /* Start waiting thread */
 
809
            VOID(pthread_cond_signal(cond));    /* Start waiting thread */
822
810
          }
823
811
          if (data->type != TL_WRITE_ALLOW_WRITE ||
824
812
              !lock->write_wait.data ||
865
853
        lock->write.last= &data->next;
866
854
        data->next=0;                           /* Only one write lock */
867
855
        data->cond=0;                           /* Mark thread free */
868
 
        pthread_cond_signal(cond);      /* Start waiting thread */
 
856
        VOID(pthread_cond_signal(cond));        /* Start waiting thread */
869
857
      } while (lock_type == TL_WRITE_ALLOW_WRITE &&
870
858
               (data=lock->write_wait.data) &&
871
859
               data->type == TL_WRITE_ALLOW_WRITE);
890
878
*/
891
879
 
892
880
 
893
 
#define LOCK_CMP(A,B) ((unsigned char*) (A->lock) - (uint) ((A)->type) < (unsigned char*) (B->lock)- (uint) ((B)->type))
 
881
#define LOCK_CMP(A,B) ((uchar*) (A->lock) - (uint) ((A)->type) < (uchar*) (B->lock)- (uint) ((B)->type))
894
882
 
895
 
static void sort_locks(THR_LOCK_DATA **data,uint32_t count)
 
883
static void sort_locks(THR_LOCK_DATA **data,uint count)
896
884
{
897
885
  THR_LOCK_DATA **pos,**end,**prev,*tmp;
898
886
 
914
902
 
915
903
 
916
904
enum enum_thr_lock_result
917
 
thr_multi_lock(THR_LOCK_DATA **data, uint32_t count, THR_LOCK_OWNER *owner)
 
905
thr_multi_lock(THR_LOCK_DATA **data, uint count, THR_LOCK_OWNER *owner)
918
906
{
919
907
  THR_LOCK_DATA **pos,**end;
920
908
  if (count > 1)
985
973
 
986
974
  /* free all locks */
987
975
 
988
 
void thr_multi_unlock(THR_LOCK_DATA **data,uint32_t count)
 
976
void thr_multi_unlock(THR_LOCK_DATA **data,uint count)
989
977
{
990
978
  THR_LOCK_DATA **pos,**end;
991
979
 
1219
1207
#ifdef MAIN
1220
1208
 
1221
1209
struct st_test {
1222
 
  uint32_t lock_nr;
 
1210
  uint lock_nr;
1223
1211
  enum thr_lock_type lock_type;
1224
1212
};
1225
1213
 
1268
1256
 
1269
1257
static pthread_cond_t COND_thread_count;
1270
1258
static pthread_mutex_t LOCK_thread_count;
1271
 
static uint32_t thread_count;
 
1259
static uint thread_count;
1272
1260
static uint32_t sum=0;
1273
1261
 
1274
1262
#define MAX_LOCK_COUNT 8
1341
1329
  thr_print_locks();
1342
1330
  pthread_mutex_lock(&LOCK_thread_count);
1343
1331
  thread_count--;
1344
 
  pthread_cond_signal(&COND_thread_count); /* Tell main we are ready */
 
1332
  VOID(pthread_cond_signal(&COND_thread_count)); /* Tell main we are ready */
1345
1333
  pthread_mutex_unlock(&LOCK_thread_count);
1346
 
  free((unsigned char*) arg);
 
1334
  free((uchar*) arg);
1347
1335
  return 0;
1348
1336
}
1349
1337
 
1400
1388
  }
1401
1389
#endif
1402
1390
#ifdef HAVE_THR_SETCONCURRENCY
1403
 
  thr_setconcurrency(2);
 
1391
  VOID(thr_setconcurrency(2));
1404
1392
#endif
1405
1393
  for (i=0 ; i < (int) array_elements(lock_counts) ; i++)
1406
1394
  {