List:Commits« Previous MessageNext Message »
From:Dmitry Lenev Date:September 17 2010 8:56am
Subject:bzr commit into mysql-5.5-runtime branch (dlenev:3139)
View as plain text  
#At file:///home/dlenev/src/bzr/mysql-5.5-rt-pr-fixed/ based on revid:dlenev@stripped

 3139 Dmitry Lenev	2010-09-17
      Follow-up for draft patch with new rw_pr_lock_t
      implementation.
      
      Do not call pthread_cond_signal unless necessary
      when releasing wr-lock (Kudos to Wlad for pointing
      out this issue!).

    modified:
      include/my_pthread.h
      mysys/thr_rwlock.c
=== modified file 'include/my_pthread.h'
--- a/include/my_pthread.h	2010-09-15 20:22:43 +0000
+++ b/include/my_pthread.h	2010-09-17 08:56:34 +0000
@@ -617,6 +617,7 @@ typedef struct st_rw_pr_lock_t {
   pthread_cond_t no_active_readers;
   int active_writer;
   int active_readers;
+  int writers_waiting_readers;
 } rw_pr_lock_t;
 
 extern int rw_pr_init(rw_pr_lock_t *);

=== modified file 'mysys/thr_rwlock.c'
--- a/mysys/thr_rwlock.c	2010-09-15 20:22:43 +0000
+++ b/mysys/thr_rwlock.c	2010-09-17 08:56:34 +0000
@@ -199,7 +199,9 @@ int rw_pr_init(rw_pr_lock_t *rwlock)
 {
   pthread_mutex_init(&rwlock->lock, NULL);
   pthread_cond_init(&rwlock->no_active_readers, NULL);
-  rwlock->active_writer= rwlock->active_readers= 0;
+  rwlock->active_writer= 0;
+  rwlock->active_readers= 0;
+  rwlock->writers_waiting_readers= 0;
   return 0;
 }
 
@@ -225,8 +227,15 @@ int rw_pr_wrlock(rw_pr_lock_t *rwlock)
 {
   pthread_mutex_lock(&rwlock->lock);
 
-  while (rwlock->active_readers != 0)
-    pthread_cond_wait(&rwlock->no_active_readers, &rwlock->lock);
+  if (rwlock->active_readers != 0)
+  {
+    rwlock->writers_waiting_readers++;
+
+    while (rwlock->active_readers != 0)
+      pthread_cond_wait(&rwlock->no_active_readers, &rwlock->lock);
+
+    rwlock->writers_waiting_readers--;
+  }
 
   rwlock->active_writer= 1;
   return 0;
@@ -238,14 +247,16 @@ int rw_pr_unlock(rw_pr_lock_t *rwlock)
   if (rwlock->active_writer)
   {
     rwlock->active_writer= 0;
-    pthread_cond_signal(&rwlock->no_active_readers);
+    if (rwlock->writers_waiting_readers)
+      pthread_cond_signal(&rwlock->no_active_readers);
     pthread_mutex_unlock(&rwlock->lock);
   }
   else
   {
     pthread_mutex_lock(&rwlock->lock);
     rwlock->active_readers--;
-    if (rwlock->active_readers == 0)
+    if (rwlock->active_readers == 0 &&
+        rwlock->writers_waiting_readers)
       pthread_cond_signal(&rwlock->no_active_readers);
     pthread_mutex_unlock(&rwlock->lock);
   }


Attachment: [text/bzr-bundle] bzr/dlenev@mysql.com-20100917085634-eno6g9ga7bu17uo1.bundle
Thread
bzr commit into mysql-5.5-runtime branch (dlenev:3139)Dmitry Lenev17 Sep