1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-30 16:24:05 +03:00

Added support for rw_tryrdlock() and rw_trywrlock()

include/my_sys.h:
  Removed not needed macro (SAFE_MUTEX can handle this case better).
sql/log.cc:
  Simple optimization
sql/log_event.cc:
  Fix problem in LOAD DATA if table_name is NULL (unlikely event)
sql/log_event.h:
  cleanup
sql/slave.cc:
  remove unnecessary assert
This commit is contained in:
unknown
2002-06-29 20:26:33 +03:00
parent 6e5952d087
commit 10d282f632
7 changed files with 74 additions and 43 deletions

View File

@ -19,11 +19,13 @@
#include "mysys_priv.h"
#include <my_pthread.h>
#if defined(THREAD) && !defined(HAVE_PTHREAD_RWLOCK_RDLOCK) && !defined(HAVE_RWLOCK_INIT)
#include <errno.h>
/*
* Source base from Sun Microsystems SPILT, simplified
* for MySQL use -- Joshua Chamas
*/
Source base from Sun Microsystems SPILT, simplified for MySQL use
-- Joshua Chamas
Some cleanup and additional code by Monty
*/
/*
* Multithreaded Demo Source
@ -71,7 +73,7 @@ int my_rwlock_init(rw_lock_t *rwp, void *arg __attribute__((unused)))
rwp->state = 0;
rwp->waiters = 0;
return( 0 );
return(0);
}
@ -80,8 +82,7 @@ int my_rwlock_destroy(rw_lock_t *rwp)
pthread_mutex_destroy( &rwp->lock );
pthread_cond_destroy( &rwp->readers );
pthread_cond_destroy( &rwp->writers );
return( 0 );
return(0);
}
@ -89,54 +90,84 @@ int my_rw_rdlock(rw_lock_t *rwp)
{
pthread_mutex_lock(&rwp->lock);
/* active or queued writers */
/* active or queued writers */
while (( rwp->state < 0 ) || rwp->waiters)
pthread_cond_wait( &rwp->readers, &rwp->lock);
rwp->state++;
pthread_mutex_unlock(&rwp->lock);
return( 0 );
return(0);
}
int my_rw_tryrdlock(rw_lock_t *rwp)
{
int res;
pthread_mutex_lock(&rwp->lock);
if ((rwp->state < 0 ) || rwp->waiters)
res= EBUSY; /* Can't get lock */
else
{
res=0;
rwp->state++;
}
pthread_mutex_unlock(&rwp->lock);
return(res);
}
int my_rw_wrlock(rw_lock_t *rwp)
{
pthread_mutex_lock(&rwp->lock);
rwp->waiters++; /* another writer queued */
rwp->waiters++; /* another writer queued */
while ( rwp->state )
pthread_cond_wait( &rwp->writers, &rwp->lock);
while (rwp->state)
pthread_cond_wait(&rwp->writers, &rwp->lock);
rwp->state = -1;
--rwp->waiters;
pthread_mutex_unlock( &rwp->lock );
rwp->waiters--;
pthread_mutex_unlock(&rwp->lock);
return(0);
}
int my_rw_trywrlock(rw_lock_t *rwp)
{
int res;
pthread_mutex_lock(&rwp->lock);
if (rwp->state)
res= EBUSY; /* Can't get lock */
else
{
res=0;
rwp->state = -1;
}
pthread_mutex_unlock(&rwp->lock);
return(res);
}
int my_rw_unlock(rw_lock_t *rwp)
{
DBUG_PRINT("rw_unlock",
("state: %d waiters: %d", rwp->state, rwp->waiters));
pthread_mutex_lock(&rwp->lock);
if ( rwp->state == -1 ) { /* writer releasing */
rwp->state = 0; /* mark as available */
if (rwp->state == -1) /* writer releasing */
{
rwp->state= 0; /* mark as available */
if ( rwp->waiters ) /* writers queued */
if ( rwp->waiters ) /* writers queued */
pthread_cond_signal( &rwp->writers );
else
pthread_cond_broadcast( &rwp->readers );
}
else
{
if ( --rwp->state == 0 ) /* no more readers */
if ( --rwp->state == 0 ) /* no more readers */
pthread_cond_signal( &rwp->writers );
}
pthread_mutex_unlock( &rwp->lock );
return( 0 );
return(0);
}
#endif