diff options
author | Christopher Faylor <me@cgf.cx> | 2013-01-07 23:34:44 +0400 |
---|---|---|
committer | Christopher Faylor <me@cgf.cx> | 2013-01-07 23:34:44 +0400 |
commit | 98f16610ca0e56d63679b8a2c079e9d8761649cb (patch) | |
tree | 418ead307f33fb824a15f3341bfc6ed984ba62a8 /winsup/cygwin/thread.cc | |
parent | d5446858b5e2324f8b8e3d4ebc2e0ecc7a417d77 (diff) |
* 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.
Diffstat (limited to 'winsup/cygwin/thread.cc')
-rw-r--r-- | winsup/cygwin/thread.cc | 33 |
1 files changed, 15 insertions, 18 deletions
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; |