* 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.
This commit is contained in:
Christopher Faylor 2013-01-07 19:34:44 +00:00
parent d5446858b5
commit 98f16610ca
3 changed files with 29 additions and 20 deletions

View File

@ -1,3 +1,15 @@
2013-01-07 Christopher Faylor <me.cygwin2013@cgf.cx>
* 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 <me.cygwin2013@cgf.cx>
* thread.cc (pthread_rwlock::add_reader): Perform new operation here

View File

@ -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;

View File

@ -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 ()
{