diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 1bdcdd9b5..28f7c3861 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,15 @@ +2013-01-07 Christopher Faylor + + * thread.cc (pthread_rwlock::lookup_reader): Remove parameter: always + assume that we're looking for the current thread. + (pthread_rwlock::tryrdlock): Eliminate self variable. Accommodate + change in lookup_reader(). + (pthread_rwlock::unlock): Ditto. + (pthread_rwlock::rdlock): Ditto. Move add_reader call after writer + tests to more closely mimic old behavior. + (pthread_rwlock::wrlock): Accommodate change in lookup_reader(). + * thread.h ((pthread_rwlock::lookup_reader): Eliminate argument. + 2013-01-07 Christopher Faylor * thread.cc (pthread_rwlock::add_reader): Perform new operation here diff --git a/winsup/cygwin/thread.cc b/winsup/cygwin/thread.cc index 3dd0255e5..5b0977385 100644 --- a/winsup/cygwin/thread.cc +++ b/winsup/cygwin/thread.cc @@ -1,7 +1,7 @@ /* thread.cc: Locking and threading module functions Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, - 2006, 2007, 2008, 2009, 2010, 2011, 2012 Red Hat, Inc. + 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Red Hat, Inc. This file is part of Cygwin. @@ -1377,11 +1377,10 @@ pthread_rwlock::rdlock () { int result = 0; struct RWLOCK_READER *reader; - pthread_t self = pthread::self (); mtx.lock (); - reader = lookup_reader (self); + reader = lookup_reader (); if (reader) { if (reader->n < ULONG_MAX) @@ -1391,14 +1390,6 @@ pthread_rwlock::rdlock () goto DONE; } - if ((reader = add_reader ())) - ++reader->n; - else - { - result = EAGAIN; - goto DONE; - } - while (writer || waiting_writers) { pthread_cleanup_push (pthread_rwlock::rdlock_cleanup, this); @@ -1410,6 +1401,13 @@ pthread_rwlock::rdlock () pthread_cleanup_pop (0); } + if ((reader = add_reader ())) + ++reader->n; + else + { + result = EAGAIN; + goto DONE; + } DONE: mtx.unlock (); @@ -1421,7 +1419,6 @@ int pthread_rwlock::tryrdlock () { int result = 0; - pthread_t self = pthread::self (); mtx.lock (); @@ -1429,7 +1426,7 @@ pthread_rwlock::tryrdlock () result = EBUSY; else { - RWLOCK_READER *reader = lookup_reader (self); + RWLOCK_READER *reader = lookup_reader (); if (!reader) reader = add_reader (); if (reader && reader->n < ULONG_MAX) @@ -1451,7 +1448,7 @@ pthread_rwlock::wrlock () mtx.lock (); - if (writer == self || lookup_reader (self)) + if (writer == self || lookup_reader ()) { result = EDEADLK; goto DONE; @@ -1498,13 +1495,12 @@ int pthread_rwlock::unlock () { int result = 0; - pthread_t self = pthread::self (); mtx.lock (); if (writer) { - if (writer != self) + if (writer != pthread::self ()) { result = EPERM; goto DONE; @@ -1514,7 +1510,7 @@ pthread_rwlock::unlock () } else { - struct RWLOCK_READER *reader = lookup_reader (self); + struct RWLOCK_READER *reader = lookup_reader (); if (!reader) { @@ -1552,9 +1548,10 @@ pthread_rwlock::remove_reader (struct RWLOCK_READER *rd) } struct pthread_rwlock::RWLOCK_READER * -pthread_rwlock::lookup_reader (pthread_t thread) +pthread_rwlock::lookup_reader () { readers_mx.lock (); + pthread_t thread = pthread::self (); struct RWLOCK_READER *cur = readers; diff --git a/winsup/cygwin/thread.h b/winsup/cygwin/thread.h index 1c7b7c62a..c5f4db3c7 100644 --- a/winsup/cygwin/thread.h +++ b/winsup/cygwin/thread.h @@ -1,7 +1,7 @@ /* thread.h: Locking and threading module definitions Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, - 2008, 2009, 2010, 2011, 2012 Red Hat, Inc. + 2008, 2009, 2010, 2011, 2012, 2013 Red Hat, Inc. This file is part of Cygwin. @@ -586,7 +586,7 @@ private: RWLOCK_READER *add_reader (); void remove_reader (struct RWLOCK_READER *rd); - struct RWLOCK_READER *lookup_reader (pthread_t thread); + struct RWLOCK_READER *lookup_reader (); void release () {