~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/thr_mutex.cc

enable remaining subselect tests, merge with latest from the trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
#endif
23
23
#if defined(SAFE_MUTEX)
24
24
#undef SAFE_MUTEX                       /* Avoid safe_mutex redefinitions */
25
 
#include "mysys_priv.h"
26
 
#include "my_static.h"
27
 
#include <m_string.h>
 
25
#include <mysys/my_static.h>
 
26
#include <mystrings/m_string.h>
28
27
 
29
28
#ifndef DO_NOT_REMOVE_THREAD_WRAPPERS
30
29
/* Remove wrappers */
53
52
 
54
53
 
55
54
int safe_mutex_init(safe_mutex_t *mp,
56
 
                    const pthread_mutexattr_t *attr __attribute__((unused)),
57
 
                    const char *file,
58
 
                    uint line)
 
55
                    const pthread_mutexattr_t *, const char *file, uint32_t line)
59
56
{
60
57
  memset(mp, 0, sizeof(*mp));
61
58
  pthread_mutex_init(&mp->global,MY_MUTEX_INIT_ERRCHK);
92
89
}
93
90
 
94
91
 
95
 
int safe_mutex_lock(safe_mutex_t *mp, bool try_lock, const char *file, uint line)
 
92
int safe_mutex_lock(safe_mutex_t *mp, bool try_lock, const char *file, uint32_t line)
96
93
{
97
94
  int error;
98
95
  if (!mp->file)
171
168
}
172
169
 
173
170
 
174
 
int safe_mutex_unlock(safe_mutex_t *mp,const char *file, uint line)
 
171
int safe_mutex_unlock(safe_mutex_t *mp,const char *file, uint32_t line)
175
172
{
176
173
  int error;
177
174
  pthread_mutex_lock(&mp->global);
204
201
 
205
202
 
206
203
int safe_cond_wait(pthread_cond_t *cond, safe_mutex_t *mp, const char *file,
207
 
                   uint line)
 
204
                   uint32_t line)
208
205
{
209
206
  int error;
210
207
  pthread_mutex_lock(&mp->global);
256
253
 
257
254
int safe_cond_timedwait(pthread_cond_t *cond, safe_mutex_t *mp,
258
255
                        struct timespec *abstime,
259
 
                        const char *file, uint line)
 
256
                        const char *file, uint32_t line)
260
257
{
261
258
  int error;
262
259
  pthread_mutex_lock(&mp->global);
292
289
}
293
290
 
294
291
 
295
 
int safe_mutex_destroy(safe_mutex_t *mp, const char *file, uint line)
 
292
int safe_mutex_destroy(safe_mutex_t *mp, const char *file, uint32_t line)
296
293
{
297
294
  int error=0;
298
295
  if (!mp->file)
354
351
   This is ok, as this thread may not yet have been exited.
355
352
*/
356
353
 
357
 
void safe_mutex_end(FILE *file __attribute__((unused)))
 
354
void safe_mutex_end(int *)
358
355
{
359
356
  if (!safe_mutex_count)                        /* safetly */
360
357
    pthread_mutex_destroy(&THR_LOCK_mutex);
381
378
 
382
379
#endif /* THREAD && SAFE_MUTEX */
383
380
 
384
 
#if defined(MY_PTHREAD_FASTMUTEX) && !defined(SAFE_MUTEX)
385
 
 
386
 
#include "mysys_priv.h"
387
 
#include "my_static.h"
388
 
#include <m_string.h>
389
 
 
390
 
#include <m_ctype.h>
391
 
#include <hash.h>
392
 
#include <myisampack.h>
393
 
#include <mysys_err.h>
394
 
#include <my_sys.h>
395
 
 
396
 
#undef pthread_mutex_t
397
 
#undef pthread_mutex_init
398
 
#undef pthread_mutex_lock
399
 
#undef pthread_mutex_trylock
400
 
#undef pthread_mutex_unlock
401
 
#undef pthread_mutex_destroy
402
 
#undef pthread_cond_wait
403
 
#undef pthread_cond_timedwait
404
 
 
405
 
uint32_t mutex_delay(uint32_t delayloops)
406
 
{
407
 
  uint32_t      i;
408
 
  volatile uint32_t j;
409
 
 
410
 
  j = 0;
411
 
 
412
 
  for (i = 0; i < delayloops * 50; i++)
413
 
    j += i;
414
 
 
415
 
  return(j); 
416
 
}       
417
 
 
418
 
#define MY_PTHREAD_FASTMUTEX_SPINS 8
419
 
#define MY_PTHREAD_FASTMUTEX_DELAY 4
420
 
 
421
 
static int cpu_count= 0;
422
 
 
423
 
int my_pthread_fastmutex_init(my_pthread_fastmutex_t *mp,
424
 
                              const pthread_mutexattr_t *attr)
425
 
{
426
 
  if ((cpu_count > 1) && (attr == MY_MUTEX_INIT_FAST))
427
 
    mp->spins= MY_PTHREAD_FASTMUTEX_SPINS; 
428
 
  else
429
 
    mp->spins= 0;
430
 
  return pthread_mutex_init(&mp->mutex, attr); 
431
 
}
432
 
 
433
 
int my_pthread_fastmutex_lock(my_pthread_fastmutex_t *mp)
434
 
{
435
 
  int   res;
436
 
  uint  i;
437
 
  uint  maxdelay= MY_PTHREAD_FASTMUTEX_DELAY;
438
 
 
439
 
  for (i= 0; i < mp->spins; i++)
440
 
  {
441
 
    res= pthread_mutex_trylock(&mp->mutex);
442
 
 
443
 
    if (res == 0)
444
 
      return 0;
445
 
 
446
 
    if (res != EBUSY)
447
 
      return res;
448
 
 
449
 
    mutex_delay(maxdelay);
450
 
    maxdelay += ((double) random() / (double) RAND_MAX) * 
451
 
                MY_PTHREAD_FASTMUTEX_DELAY + 1;
452
 
  }
453
 
  return pthread_mutex_lock(&mp->mutex);
454
 
}
455
 
 
456
 
 
457
 
void fastmutex_global_init(void)
458
 
{
459
 
#ifdef _SC_NPROCESSORS_CONF
460
 
  cpu_count= sysconf(_SC_NPROCESSORS_CONF);
461
 
#endif
462
 
}
463
 
  
464
 
#endif /* defined(MY_PTHREAD_FASTMUTEX) && !defined(SAFE_MUTEX) */