summaryrefslogtreecommitdiff
path: root/mysys/thr_lock.c
diff options
context:
space:
mode:
Diffstat (limited to 'mysys/thr_lock.c')
-rw-r--r--mysys/thr_lock.c150
1 files changed, 76 insertions, 74 deletions
diff --git a/mysys/thr_lock.c b/mysys/thr_lock.c
index a6bc128f32a..6d62476ecf3 100644
--- a/mysys/thr_lock.c
+++ b/mysys/thr_lock.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000 MySQL AB
+/* Copyright (C) 2000 MySQL AB, 2008-2009 Sun Microsystems, Inc
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -94,7 +94,7 @@ enum thr_lock_type thr_upgraded_concurrent_insert_lock = TL_WRITE;
LIST *thr_lock_thread_list; /* List of threads in use */
ulong max_write_lock_count= ~(ulong) 0L;
-static inline pthread_cond_t *get_cond(void)
+static inline mysql_cond_t *get_cond(void)
{
return &my_thread_var->suspend;
}
@@ -316,16 +316,16 @@ void thr_lock_init(THR_LOCK *lock)
{
DBUG_ENTER("thr_lock_init");
bzero((char*) lock,sizeof(*lock));
- pthread_mutex_init(&lock->mutex,MY_MUTEX_INIT_FAST);
+ mysql_mutex_init(key_THR_LOCK_mutex, &lock->mutex, MY_MUTEX_INIT_FAST);
lock->read.last= &lock->read.data;
lock->read_wait.last= &lock->read_wait.data;
lock->write_wait.last= &lock->write_wait.data;
lock->write.last= &lock->write.data;
- pthread_mutex_lock(&THR_LOCK_lock); /* Add to locks in use */
+ mysql_mutex_lock(&THR_LOCK_lock); /* Add to locks in use */
lock->list.data=(void*) lock;
thr_lock_thread_list=list_add(thr_lock_thread_list,&lock->list);
- pthread_mutex_unlock(&THR_LOCK_lock);
+ mysql_mutex_unlock(&THR_LOCK_lock);
DBUG_VOID_RETURN;
}
@@ -333,10 +333,10 @@ void thr_lock_init(THR_LOCK *lock)
void thr_lock_delete(THR_LOCK *lock)
{
DBUG_ENTER("thr_lock_delete");
- pthread_mutex_lock(&THR_LOCK_lock);
+ mysql_mutex_lock(&THR_LOCK_lock);
thr_lock_thread_list=list_delete(thr_lock_thread_list,&lock->list);
- pthread_mutex_unlock(&THR_LOCK_lock);
- pthread_mutex_destroy(&lock->mutex);
+ mysql_mutex_unlock(&THR_LOCK_lock);
+ mysql_mutex_destroy(&lock->mutex);
DBUG_VOID_RETURN;
}
@@ -392,7 +392,7 @@ wait_for_lock(struct st_lock_list *wait, THR_LOCK_DATA *data,
my_bool in_wait_list)
{
struct st_my_thread_var *thread_var= my_thread_var;
- pthread_cond_t *cond= &thread_var->suspend;
+ mysql_cond_t *cond= &thread_var->suspend;
struct timespec wait_timeout;
enum enum_thr_lock_result result= THR_LOCK_ABORTED;
my_bool can_deadlock= test(data->owner->info->n_cursors);
@@ -443,9 +443,9 @@ wait_for_lock(struct st_lock_list *wait, THR_LOCK_DATA *data,
while (!thread_var->abort || in_wait_list)
{
int rc= (can_deadlock ?
- pthread_cond_timedwait(cond, &data->lock->mutex,
- &wait_timeout) :
- pthread_cond_wait(cond, &data->lock->mutex));
+ mysql_cond_timedwait(cond, &data->lock->mutex,
+ &wait_timeout) :
+ mysql_cond_wait(cond, &data->lock->mutex));
/*
We must break the wait if one of the following occurs:
- the connection has been aborted (!thread_var->abort), but
@@ -501,13 +501,13 @@ wait_for_lock(struct st_lock_list *wait, THR_LOCK_DATA *data,
(*data->lock->get_status)(data->status_param, 0);
check_locks(data->lock,"got wait_for_lock",0);
}
- pthread_mutex_unlock(&data->lock->mutex);
+ mysql_mutex_unlock(&data->lock->mutex);
/* The following must be done after unlock of lock->mutex */
- pthread_mutex_lock(&thread_var->mutex);
+ mysql_mutex_lock(&thread_var->mutex);
thread_var->current_mutex= 0;
thread_var->current_cond= 0;
- pthread_mutex_unlock(&thread_var->mutex);
+ mysql_mutex_unlock(&thread_var->mutex);
proc_info_hook(NULL, old_proc_info, __func__, __FILE__, __LINE__);
@@ -529,7 +529,7 @@ thr_lock(THR_LOCK_DATA *data, THR_LOCK_OWNER *owner,
data->cond=0; /* safety */
data->type=lock_type;
data->owner= owner; /* Must be reset ! */
- pthread_mutex_lock(&lock->mutex);
+ mysql_mutex_lock(&lock->mutex);
DBUG_PRINT("lock",("data: 0x%lx thread: 0x%lx lock: 0x%lx type: %d",
(long) data, data->owner->info->thread_id,
(long) lock, (int) lock_type));
@@ -785,7 +785,7 @@ thr_lock(THR_LOCK_DATA *data, THR_LOCK_OWNER *owner,
/* Can't get lock yet; Wait for it */
DBUG_RETURN(wait_for_lock(wait_queue, data, 0));
end:
- pthread_mutex_unlock(&lock->mutex);
+ mysql_mutex_unlock(&lock->mutex);
DBUG_RETURN(result);
}
@@ -807,7 +807,7 @@ static inline void free_all_read_locks(THR_LOCK *lock,
do
{
- pthread_cond_t *cond=data->cond;
+ mysql_cond_t *cond= data->cond;
if ((int) data->type == (int) TL_READ_NO_INSERT)
{
if (using_concurrent_insert)
@@ -832,7 +832,7 @@ static inline void free_all_read_locks(THR_LOCK *lock,
data->owner->info->thread_id));
/* purecov: end */
data->cond=0; /* Mark thread free */
- pthread_cond_signal(cond);
+ mysql_cond_signal(cond);
} while ((data=data->next));
*lock->read_wait.last=0;
if (!lock->read_wait.data)
@@ -849,7 +849,7 @@ void thr_unlock(THR_LOCK_DATA *data)
DBUG_ENTER("thr_unlock");
DBUG_PRINT("lock",("data: 0x%lx thread: 0x%lx lock: 0x%lx",
(long) data, data->owner->info->thread_id, (long) lock));
- pthread_mutex_lock(&lock->mutex);
+ mysql_mutex_lock(&lock->mutex);
check_locks(lock,"start of release lock",0);
if (((*data->prev)=data->next)) /* remove from lock-list */
@@ -881,7 +881,7 @@ void thr_unlock(THR_LOCK_DATA *data)
data->type=TL_UNLOCK; /* Mark unlocked */
check_locks(lock,"after releasing lock",1);
wake_up_waiters(lock);
- pthread_mutex_unlock(&lock->mutex);
+ mysql_mutex_unlock(&lock->mutex);
DBUG_VOID_RETURN;
}
@@ -940,9 +940,9 @@ static void wake_up_waiters(THR_LOCK *lock)
data->type, data->owner->info->thread_id));
/* purecov: end */
{
- pthread_cond_t *cond=data->cond;
+ mysql_cond_t *cond= data->cond;
data->cond=0; /* Mark thread free */
- pthread_cond_signal(cond); /* Start waiting thread */
+ mysql_cond_signal(cond); /* Start waiting thread */
}
if (data->type != TL_WRITE_ALLOW_WRITE ||
!lock->write_wait.data ||
@@ -983,7 +983,7 @@ static void wake_up_waiters(THR_LOCK *lock)
goto end;
}
do {
- pthread_cond_t *cond=data->cond;
+ mysql_cond_t *cond= data->cond;
if (((*data->prev)=data->next)) /* remove from wait-list */
data->next->prev= data->prev;
else
@@ -993,7 +993,7 @@ static void wake_up_waiters(THR_LOCK *lock)
lock->write.last= &data->next;
data->next=0; /* Only one write lock */
data->cond=0; /* Mark thread free */
- pthread_cond_signal(cond); /* Start waiting thread */
+ mysql_cond_signal(cond); /* Start waiting thread */
} while (lock_type == TL_WRITE_ALLOW_WRITE &&
(data=lock->write_wait.data) &&
data->type == TL_WRITE_ALLOW_WRITE);
@@ -1180,19 +1180,19 @@ void thr_abort_locks(THR_LOCK *lock, my_bool upgrade_lock)
{
THR_LOCK_DATA *data;
DBUG_ENTER("thr_abort_locks");
- pthread_mutex_lock(&lock->mutex);
+ mysql_mutex_lock(&lock->mutex);
for (data=lock->read_wait.data; data ; data=data->next)
{
data->type=TL_UNLOCK; /* Mark killed */
/* It's safe to signal the cond first: we're still holding the mutex. */
- pthread_cond_signal(data->cond);
+ mysql_cond_signal(data->cond);
data->cond=0; /* Removed from list */
}
for (data=lock->write_wait.data; data ; data=data->next)
{
data->type=TL_UNLOCK;
- pthread_cond_signal(data->cond);
+ mysql_cond_signal(data->cond);
data->cond=0;
}
lock->read_wait.last= &lock->read_wait.data;
@@ -1200,7 +1200,7 @@ void thr_abort_locks(THR_LOCK *lock, my_bool upgrade_lock)
lock->read_wait.data=lock->write_wait.data=0;
if (upgrade_lock && lock->write.data)
lock->write.data->type=TL_WRITE_ONLY;
- pthread_mutex_unlock(&lock->mutex);
+ mysql_mutex_unlock(&lock->mutex);
DBUG_VOID_RETURN;
}
@@ -1217,7 +1217,7 @@ my_bool thr_abort_locks_for_thread(THR_LOCK *lock, my_thread_id thread_id)
my_bool found= FALSE;
DBUG_ENTER("thr_abort_locks_for_thread");
- pthread_mutex_lock(&lock->mutex);
+ mysql_mutex_lock(&lock->mutex);
for (data= lock->read_wait.data; data ; data= data->next)
{
if (data->owner->info->thread_id == thread_id) /* purecov: tested */
@@ -1226,7 +1226,7 @@ my_bool thr_abort_locks_for_thread(THR_LOCK *lock, my_thread_id thread_id)
data->type= TL_UNLOCK; /* Mark killed */
/* It's safe to signal the cond first: we're still holding the mutex. */
found= TRUE;
- pthread_cond_signal(data->cond);
+ mysql_cond_signal(data->cond);
data->cond= 0; /* Removed from list */
if (((*data->prev)= data->next))
@@ -1242,7 +1242,7 @@ my_bool thr_abort_locks_for_thread(THR_LOCK *lock, my_thread_id thread_id)
DBUG_PRINT("info",("Aborting write-wait lock"));
data->type= TL_UNLOCK;
found= TRUE;
- pthread_cond_signal(data->cond);
+ mysql_cond_signal(data->cond);
data->cond= 0;
if (((*data->prev)= data->next))
@@ -1252,7 +1252,7 @@ my_bool thr_abort_locks_for_thread(THR_LOCK *lock, my_thread_id thread_id)
}
}
wake_up_waiters(lock);
- pthread_mutex_unlock(&lock->mutex);
+ mysql_mutex_unlock(&lock->mutex);
DBUG_RETURN(found);
}
@@ -1301,7 +1301,7 @@ void thr_downgrade_write_lock(THR_LOCK_DATA *in_data,
#endif
DBUG_ENTER("thr_downgrade_write_only_lock");
- pthread_mutex_lock(&lock->mutex);
+ mysql_mutex_lock(&lock->mutex);
DBUG_ASSERT(old_lock_type == TL_WRITE_ONLY);
DBUG_ASSERT(old_lock_type > new_lock_type);
in_data->type= new_lock_type;
@@ -1393,7 +1393,7 @@ void thr_downgrade_write_lock(THR_LOCK_DATA *in_data,
next= data->next;
if (start_writers && data->type == new_lock_type)
{
- pthread_cond_t *cond= data->cond;
+ mysql_cond_t *cond= data->cond;
/*
It is ok to start this waiter.
Move from being first in wait queue to be last in write queue.
@@ -1407,7 +1407,7 @@ void thr_downgrade_write_lock(THR_LOCK_DATA *in_data,
data->next= 0;
check_locks(lock, "Started write lock after downgrade",0);
data->cond= 0;
- pthread_cond_signal(cond);
+ mysql_cond_signal(cond);
}
else
{
@@ -1447,7 +1447,7 @@ void thr_downgrade_write_lock(THR_LOCK_DATA *in_data,
if (new_lock_type != TL_WRITE_ALLOW_READ ||
data->type != TL_READ_NO_INSERT)
{
- pthread_cond_t *cond= data->cond;
+ mysql_cond_t *cond= data->cond;
if (((*data->prev)= data->next))
data->next->prev= data->prev;
else
@@ -1460,13 +1460,13 @@ void thr_downgrade_write_lock(THR_LOCK_DATA *in_data,
lock->read_no_write_count++;
check_locks(lock, "Started read lock after downgrade",0);
data->cond= 0;
- pthread_cond_signal(cond);
+ mysql_cond_signal(cond);
}
}
}
check_locks(lock,"after starting waiters after downgrading lock",0);
#endif
- pthread_mutex_unlock(&lock->mutex);
+ mysql_mutex_unlock(&lock->mutex);
DBUG_VOID_RETURN;
}
@@ -1478,10 +1478,10 @@ my_bool thr_upgrade_write_delay_lock(THR_LOCK_DATA *data,
THR_LOCK *lock=data->lock;
DBUG_ENTER("thr_upgrade_write_delay_lock");
- pthread_mutex_lock(&lock->mutex);
+ mysql_mutex_lock(&lock->mutex);
if (data->type == TL_UNLOCK || data->type >= TL_WRITE_LOW_PRIORITY)
{
- pthread_mutex_unlock(&lock->mutex);
+ mysql_mutex_unlock(&lock->mutex);
DBUG_RETURN(data->type == TL_UNLOCK); /* Test if Aborted */
}
check_locks(lock,"before upgrading lock",0);
@@ -1495,7 +1495,7 @@ my_bool thr_upgrade_write_delay_lock(THR_LOCK_DATA *data,
{ /* We have the lock */
if (data->lock->get_status)
(*data->lock->get_status)(data->status_param, 0);
- pthread_mutex_unlock(&lock->mutex);
+ mysql_mutex_unlock(&lock->mutex);
DBUG_RETURN(0);
}
@@ -1528,10 +1528,10 @@ my_bool thr_reschedule_write_lock(THR_LOCK_DATA *data)
enum thr_lock_type write_lock_type;
DBUG_ENTER("thr_reschedule_write_lock");
- pthread_mutex_lock(&lock->mutex);
+ mysql_mutex_lock(&lock->mutex);
if (!lock->read_wait.data) /* No waiting read locks */
{
- pthread_mutex_unlock(&lock->mutex);
+ mysql_mutex_unlock(&lock->mutex);
DBUG_RETURN(0);
}
@@ -1553,7 +1553,7 @@ my_bool thr_reschedule_write_lock(THR_LOCK_DATA *data)
lock->write_wait.data=data;
free_all_read_locks(lock,0);
- pthread_mutex_unlock(&lock->mutex);
+ mysql_mutex_unlock(&lock->mutex);
DBUG_RETURN(thr_upgrade_write_delay_lock(data, write_lock_type));
}
@@ -1588,13 +1588,13 @@ void thr_print_locks(void)
LIST *list;
uint count=0;
- pthread_mutex_lock(&THR_LOCK_lock);
+ mysql_mutex_lock(&THR_LOCK_lock);
puts("Current locks:");
for (list= thr_lock_thread_list; list && count++ < MAX_THREADS;
list= list_rest(list))
{
THR_LOCK *lock=(THR_LOCK*) list->data;
- pthread_mutex_lock(&lock->mutex);
+ mysql_mutex_lock(&lock->mutex);
printf("lock: 0x%lx:",(ulong) lock);
if ((lock->write_wait.data || lock->read_wait.data) &&
(! lock->read.data && ! lock->write.data))
@@ -1612,11 +1612,11 @@ void thr_print_locks(void)
thr_print_lock("write_wait",&lock->write_wait);
thr_print_lock("read",&lock->read);
thr_print_lock("read_wait",&lock->read_wait);
- pthread_mutex_unlock(&lock->mutex);
+ mysql_mutex_unlock(&lock->mutex);
puts("");
}
fflush(stdout);
- pthread_mutex_unlock(&THR_LOCK_lock);
+ mysql_mutex_unlock(&THR_LOCK_lock);
}
#endif /* THREAD */
@@ -1677,8 +1677,8 @@ int lock_counts[]= {sizeof(test_0)/sizeof(struct st_test),
};
-static pthread_cond_t COND_thread_count;
-static pthread_mutex_t LOCK_thread_count;
+static mysql_cond_t COND_thread_count;
+static mysql_mutex_t LOCK_thread_count;
static uint thread_count;
static ulong sum=0;
@@ -1730,7 +1730,7 @@ static void *test_thread(void *arg)
data[i].type= tests[param][i].lock_type;
}
thr_multi_lock(multi_locks, lock_counts[param], &owner);
- pthread_mutex_lock(&LOCK_thread_count);
+ mysql_mutex_lock(&LOCK_thread_count);
{
int tmp=rand() & 7; /* Do something from 0-2 sec */
if (tmp == 0)
@@ -1744,16 +1744,16 @@ static void *test_thread(void *arg)
sum+=k;
}
}
- pthread_mutex_unlock(&LOCK_thread_count);
+ mysql_mutex_unlock(&LOCK_thread_count);
thr_multi_unlock(multi_locks,lock_counts[param]);
}
printf("Thread %s (%d) ended\n",my_thread_name(),param); fflush(stdout);
thr_print_locks();
- pthread_mutex_lock(&LOCK_thread_count);
+ mysql_mutex_lock(&LOCK_thread_count);
thread_count--;
- pthread_cond_signal(&COND_thread_count); /* Tell main we are ready */
- pthread_mutex_unlock(&LOCK_thread_count);
+ mysql_cond_signal(&COND_thread_count); /* Tell main we are ready */
+ mysql_mutex_unlock(&LOCK_thread_count);
free((uchar*) arg);
return 0;
}
@@ -1770,15 +1770,15 @@ int main(int argc __attribute__((unused)),char **argv __attribute__((unused)))
printf("Main thread: %s\n",my_thread_name());
- if ((error=pthread_cond_init(&COND_thread_count,NULL)))
+ if ((error= mysql_cond_init(0, &COND_thread_count, NULL)))
{
- fprintf(stderr,"Got error: %d from pthread_cond_init (errno: %d)",
+ fprintf(stderr, "Got error: %d from mysql_cond_init (errno: %d)",
error,errno);
exit(1);
}
- if ((error=pthread_mutex_init(&LOCK_thread_count,MY_MUTEX_INIT_FAST)))
+ if ((error= mysql_mutex_init(0, &LOCK_thread_count, MY_MUTEX_INIT_FAST)))
{
- fprintf(stderr,"Got error: %d from pthread_cond_init (errno: %d)",
+ fprintf(stderr, "Got error: %d from mysql_cond_init (errno: %d)",
error,errno);
exit(1);
}
@@ -1820,33 +1820,35 @@ int main(int argc __attribute__((unused)),char **argv __attribute__((unused)))
param=(int*) malloc(sizeof(int));
*param=i;
- if ((error=pthread_mutex_lock(&LOCK_thread_count)))
+ if ((error= mysql_mutex_lock(&LOCK_thread_count)))
{
- fprintf(stderr,"Got error: %d from pthread_mutex_lock (errno: %d)",
- error,errno);
+ fprintf(stderr, "Got error: %d from mysql_mutex_lock (errno: %d)",
+ error, errno);
exit(1);
}
- if ((error=pthread_create(&tid,&thr_attr,test_thread,(void*) param)))
+ if ((error= mysql_thread_create(0,
+ &tid, &thr_attr, test_thread,
+ (void*) param)))
{
- fprintf(stderr,"Got error: %d from pthread_create (errno: %d)\n",
- error,errno);
- pthread_mutex_unlock(&LOCK_thread_count);
+ fprintf(stderr, "Got error: %d from mysql_thread_create (errno: %d)\n",
+ error, errno);
+ mysql_mutex_unlock(&LOCK_thread_count);
exit(1);
}
thread_count++;
- pthread_mutex_unlock(&LOCK_thread_count);
+ mysql_mutex_unlock(&LOCK_thread_count);
}
pthread_attr_destroy(&thr_attr);
- if ((error=pthread_mutex_lock(&LOCK_thread_count)))
- fprintf(stderr,"Got error: %d from pthread_mutex_lock\n",error);
+ if ((error= mysql_mutex_lock(&LOCK_thread_count)))
+ fprintf(stderr, "Got error: %d from mysql_mutex_lock\n", error);
while (thread_count)
{
- if ((error=pthread_cond_wait(&COND_thread_count,&LOCK_thread_count)))
- fprintf(stderr,"Got error: %d from pthread_cond_wait\n",error);
+ if ((error= mysql_cond_wait(&COND_thread_count, &LOCK_thread_count)))
+ fprintf(stderr, "Got error: %d from mysql_cond_wait\n", error);
}
- if ((error=pthread_mutex_unlock(&LOCK_thread_count)))
- fprintf(stderr,"Got error: %d from pthread_mutex_unlock\n",error);
+ if ((error= mysql_mutex_unlock(&LOCK_thread_count)))
+ fprintf(stderr, "Got error: %d from mysql_mutex_unlock\n", error);
for (i=0 ; i < (int) array_elements(locks) ; i++)
thr_lock_delete(locks+i);
#ifdef EXTRA_DEBUG