~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/thr_mutex.c

MergingĀ mainline

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 
16
16
/* This makes a wrapper for mutex handling to make it easier to debug mutex */
17
17
 
18
 
#include "mysys_priv.h"
19
 
 
 
18
#include <my_global.h>
20
19
#if defined(TARGET_OS_LINUX) && !defined (__USE_UNIX98)
21
20
#define __USE_UNIX98                    /* To get rw locks under Linux */
22
21
#endif
41
40
#endif /* DO_NOT_REMOVE_THREAD_WRAPPERS */
42
41
 
43
42
static pthread_mutex_t THR_LOCK_mutex;
44
 
static uint32_t safe_mutex_count= 0;            /* Number of mutexes created */
 
43
static ulong safe_mutex_count= 0;               /* Number of mutexes created */
45
44
#ifdef SAFE_MUTEX_DETECT_DESTROY
46
45
static struct st_safe_mutex_info_t *safe_mutex_root= NULL;
47
46
#endif
55
54
int safe_mutex_init(safe_mutex_t *mp,
56
55
                    const pthread_mutexattr_t *attr __attribute__((unused)),
57
56
                    const char *file,
58
 
                    uint32_t line)
 
57
                    uint line)
59
58
{
60
 
  memset(mp, 0, sizeof(*mp));
 
59
  bzero((char*) mp,sizeof(*mp));
61
60
  pthread_mutex_init(&mp->global,MY_MUTEX_INIT_ERRCHK);
62
61
  pthread_mutex_init(&mp->mutex,attr);
63
62
  /* Mark that mutex is initialized */
92
91
}
93
92
 
94
93
 
95
 
int safe_mutex_lock(safe_mutex_t *mp, bool try_lock, const char *file, uint32_t line)
 
94
int safe_mutex_lock(safe_mutex_t *mp, my_bool try_lock, const char *file, uint line)
96
95
{
97
96
  int error;
98
97
  if (!mp->file)
171
170
}
172
171
 
173
172
 
174
 
int safe_mutex_unlock(safe_mutex_t *mp,const char *file, uint32_t line)
 
173
int safe_mutex_unlock(safe_mutex_t *mp,const char *file, uint line)
175
174
{
176
175
  int error;
177
176
  pthread_mutex_lock(&mp->global);
204
203
 
205
204
 
206
205
int safe_cond_wait(pthread_cond_t *cond, safe_mutex_t *mp, const char *file,
207
 
                   uint32_t line)
 
206
                   uint line)
208
207
{
209
208
  int error;
210
209
  pthread_mutex_lock(&mp->global);
256
255
 
257
256
int safe_cond_timedwait(pthread_cond_t *cond, safe_mutex_t *mp,
258
257
                        struct timespec *abstime,
259
 
                        const char *file, uint32_t line)
 
258
                        const char *file, uint line)
260
259
{
261
260
  int error;
262
261
  pthread_mutex_lock(&mp->global);
292
291
}
293
292
 
294
293
 
295
 
int safe_mutex_destroy(safe_mutex_t *mp, const char *file, uint32_t line)
 
294
int safe_mutex_destroy(safe_mutex_t *mp, const char *file, uint line)
296
295
{
297
296
  int error=0;
298
297
  if (!mp->file)
349
348
    file                Print errors on this file
350
349
 
351
350
  NOTES
 
351
    We can't use DBUG_PRINT() here as we have in my_end() disabled
 
352
    DBUG handling before calling this function.
352
353
 
353
354
   In MySQL one may get one warning for a mutex created in my_thr_init.c
354
355
   This is ok, as this thread may not yet have been exited.
402
403
#undef pthread_cond_wait
403
404
#undef pthread_cond_timedwait
404
405
 
405
 
uint32_t mutex_delay(uint32_t delayloops)
 
406
ulong mutex_delay(ulong delayloops)
406
407
{
407
 
  uint32_t      i;
408
 
  volatile uint32_t j;
 
408
  ulong i;
 
409
  volatile ulong j;
409
410
 
410
411
  j = 0;
411
412
 
433
434
int my_pthread_fastmutex_lock(my_pthread_fastmutex_t *mp)
434
435
{
435
436
  int   res;
436
 
  uint32_t  i;
437
 
  uint32_t  maxdelay= MY_PTHREAD_FASTMUTEX_DELAY;
 
437
  uint  i;
 
438
  uint  maxdelay= MY_PTHREAD_FASTMUTEX_DELAY;
438
439
 
439
440
  for (i= 0; i < mp->spins; i++)
440
441
  {