]> sourceware.org Git - newlib-cygwin.git/commitdiff
* thread.h (struct pthread_rwlock::RWLOCK_READER): Add counter n.
authorCorinna Vinschen <corinna@vinschen.de>
Tue, 20 Jan 2009 12:40:31 +0000 (12:40 +0000)
committerCorinna Vinschen <corinna@vinschen.de>
Tue, 20 Jan 2009 12:40:31 +0000 (12:40 +0000)
* thread.cc (pthread_rwlock::rdlock): If a thread already owns a
read lock, just count the number of locks for it, per SUSv4.
(pthread_rwlock::tryrdlock): Ditto.
(pthread_rwlock::unlock): If a thread has more than one concurrent
read locks, just count down.

winsup/cygwin/ChangeLog
winsup/cygwin/thread.cc
winsup/cygwin/thread.h

index efbaffb9f696ea35ff153c10809cae7329b95c27..022a251037ffb913bf7e7af62bc2a0903e58c562 100644 (file)
@@ -1,3 +1,12 @@
+2009-01-20  Corinna Vinschen  <corinna@vinschen.de>
+
+       * thread.h (struct pthread_rwlock::RWLOCK_READER): Add counter n.
+       * thread.cc (pthread_rwlock::rdlock): If a thread already owns a
+       read lock, just count the number of locks for it, per SUSv4.
+       (pthread_rwlock::tryrdlock): Ditto.
+       (pthread_rwlock::unlock): If a thread has more than one concurrent
+       read locks, just count down.
+
 2009-01-20  Corinna Vinschen  <corinna@vinschen.de>
 
        * autoload.cc (WSAIoctl): Reintroduce.
index ecf9287845531819d981ebdc0cdc8b3e4abcf70f..8bb68703e718a15467e4b0a4387a6f3c6f45e18a 100644 (file)
@@ -1227,9 +1227,13 @@ pthread_rwlock::rdlock ()
 
   mtx.lock ();
 
-  if (lookup_reader (self))
+  reader = lookup_reader (self);
+  if (reader)
     {
-      result = EDEADLK;
+      if (reader->n < ULONG_MAX)
+       ++reader->n;
+      else
+       errno = EAGAIN;
       goto DONE;
     }
 
@@ -1252,6 +1256,7 @@ pthread_rwlock::rdlock ()
     }
 
   reader->thread = self;
+  reader->n = 1;
   add_reader (reader);
 
  DONE:
@@ -1272,10 +1277,15 @@ pthread_rwlock::tryrdlock ()
     result = EBUSY;
   else
     {
-      struct RWLOCK_READER *reader = new struct RWLOCK_READER;
-      if (reader)
+      struct RWLOCK_READER *reader;
+
+      reader = lookup_reader (self);
+      if (reader && reader->n < ULONG_MAX)
+       ++reader->n;
+      else if ((reader = new struct RWLOCK_READER))
        {
          reader->thread = self;
+         reader->n = 1;
          add_reader (reader);
        }
       else
@@ -1365,6 +1375,8 @@ pthread_rwlock::unlock ()
          result = EPERM;
          goto DONE;
        }
+      if (--reader->n > 0)
+       goto DONE;
 
       remove_reader (reader);
       delete reader;
index db94fd2c25ba36e49a72074dd8c1f45a6986310e..c2a1be8f14a07e7eb4701b91a1da882a9b89ce85 100644 (file)
@@ -556,6 +556,7 @@ public:
   {
     struct RWLOCK_READER *next;
     pthread_t thread;
+    unsigned long n;
   } *readers;
   fast_mutex readers_mx;
 
This page took 0.034319 seconds and 5 git commands to generate.