summaryrefslogtreecommitdiff
path: root/mysys/thr_rwlock.c
diff options
context:
space:
mode:
authorKonstantin Osipov <kostja@sun.com>2010-08-11 01:12:01 +0400
committerKonstantin Osipov <kostja@sun.com>2010-08-11 01:12:01 +0400
commit265a6edd23cfdb69c6ac072bf01887f7aed1168c (patch)
tree963c21bfca01bc89ae96c0574759e4e82383c83f /mysys/thr_rwlock.c
parent64cc044e33632b6805e13bc04cbaf7e079c66d32 (diff)
downloadmariadb-git-265a6edd23cfdb69c6ac072bf01887f7aed1168c.tar.gz
A pre-requisite patch for the fix for Bug#52044.
Implement a few simple asserts in my_rwlock_t locks. include/my_pthread.h: Declare two simple assert functions. include/mysql/psi/mysql_thread.h: Add wrappers for new assert functions. mysys/thr_rwlock.c: Add asserts. sql/sql_base.cc: Silence a compiler warning for the case when SAFE_MUTEX is not ON.
Diffstat (limited to 'mysys/thr_rwlock.c')
-rw-r--r--mysys/thr_rwlock.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/mysys/thr_rwlock.c b/mysys/thr_rwlock.c
index 2ac4a00695e..ba5fe86f1d7 100644
--- a/mysys/thr_rwlock.c
+++ b/mysys/thr_rwlock.c
@@ -71,6 +71,9 @@ int my_rw_init(my_rw_lock_t *rwp, my_bool *prefer_readers_attr)
rwp->state = 0;
rwp->waiters = 0;
+#ifdef SAFE_MUTEX
+ rwp->write_thread = 0;
+#endif
/* If attribute argument is NULL use default value - prefer writers. */
rwp->prefer_readers= prefer_readers_attr ? *prefer_readers_attr : FALSE;
@@ -80,6 +83,7 @@ int my_rw_init(my_rw_lock_t *rwp, my_bool *prefer_readers_attr)
int my_rw_destroy(my_rw_lock_t *rwp)
{
+ DBUG_ASSERT(rwp->state == 0);
pthread_mutex_destroy( &rwp->lock );
pthread_cond_destroy( &rwp->readers );
pthread_cond_destroy( &rwp->writers );
@@ -123,10 +127,15 @@ int my_rw_wrlock(my_rw_lock_t *rwp)
pthread_mutex_lock(&rwp->lock);
rwp->waiters++; /* another writer queued */
+ my_rw_lock_assert_not_owner(rwp);
+
while (rwp->state)
pthread_cond_wait(&rwp->writers, &rwp->lock);
rwp->state = -1;
rwp->waiters--;
+#ifdef SAFE_MUTEX
+ rwp->write_thread= pthread_self();
+#endif
pthread_mutex_unlock(&rwp->lock);
return(0);
}
@@ -142,6 +151,9 @@ int my_rw_trywrlock(my_rw_lock_t *rwp)
{
res=0;
rwp->state = -1;
+#ifdef SAFE_MUTEX
+ rwp->write_thread= pthread_self();
+#endif
}
pthread_mutex_unlock(&rwp->lock);
return(res);
@@ -154,9 +166,15 @@ int my_rw_unlock(my_rw_lock_t *rwp)
("state: %d waiters: %d", rwp->state, rwp->waiters));
pthread_mutex_lock(&rwp->lock);
+ DBUG_ASSERT(rwp->state != 0);
+
if (rwp->state == -1) /* writer releasing */
{
+ my_rw_lock_assert_write_owner(rwp);
rwp->state= 0; /* mark as available */
+#ifdef SAFE_MUTEX
+ rwp->write_thread= 0;
+#endif
if ( rwp->waiters ) /* writers queued */
pthread_cond_signal( &rwp->writers );