Commit Graph

6 Commits

Author SHA1 Message Date
Mike Makonnen
32eaa7dddd There are consumers of rwlocks, inluding our own libc, that depend on
a PTHREAD_RWLOCK_INITIALIZER to do for rwlocks what
a similarly named symbol does for statically initialized mutexes.
This symbol was dropped in The Open Group Base Specifications Issue 6
and does not exist in IEEE Std 1003.1, 2003, but it should still be
supported for backwards compatibility.

Pointy hat: mtm
2004-02-18 15:30:10 +00:00
Mike Makonnen
1baa64733c I update the rwlock code in libthr to be more standards compliant and
what do I get for my troubles? libc breaks offcourse!

Reimplement a hack (in libthr) that allows libc to use
rwlocks without initializing them first. The hack was reimplemented
so that only a private libc version of the rwlock locking functions
initializes an uninitialized rwlock. The application version will
correctly fail.
2004-01-29 12:03:17 +00:00
Mike Makonnen
c40bafac85 Implement reference counting of read-write locks. This uses
a list in the thread structure to keep track of the locks and
how many times they have been locked. This list is checked
on every lock and unlock. The traversal through the list is
O(n). Most applications don't hold so many locks at once that
this will become a problem. However, if it does become a problem
it might be a good idea to review this once libthr is
off probation and in the optimization cycle.
This fixes:
	o deadlock when a thread tries to recursively acquire a
	  read lock when a writer is waiting on the lock.
	o a thread could previously successfully unlock a lock it did not own
	o deadlock when a thread tries to acquire a write lock on
	  a lock it already owns for reading or writing [ this is admittedly
	  not required by POSIX, but is nice to have ]
2004-01-19 14:51:45 +00:00
Mike Makonnen
104ff764e5 Add an implementation of pthread_rwlock_timed{rd,wr}lock() to libthr with
attendant documentation.
2004-01-16 10:52:10 +00:00
Mike Makonnen
14f8ddcd08 o We are not required to initialize an invalid rwlock. So axe all that
code and simply return EINVAL (which is allowed by the standard) in
  all those pthread functions that previously initialized it.

o Refactor the pthread_rwlock_[try]rdlock() and pthread_rwlock_[try]wrlock()
  functions. They are now completeley condensed into rwlock_rdlock_common()
  and rwlock_wrlock_common(), respectively.

o If the application tries to destroy an rwlock that is currently
  held by a thread return EBUSY where it previously went ahead and
  freed all resources associated with the lock.

o Refactor _pthread_rwlock_init() to make it look (relatively) sane.

o When obtaining a read lock on an rwlock the check for whether it
  would exceed the maximum allowed read locks should happen *before*
  we obtain the lock.

o The pthread_rwlock_* functions shall *never* return EINTR, so make
  sure to requeue/resuspend the thread if it encounters such an error.

o Make a note that pthread_rwlock_unlock() needs to ensure it holds a
  lock on an rwlock it tries to unlock. It will be implemented in a
  separate commit because it requires some additional rwlock infrastructure.
2004-01-16 07:10:30 +00:00
Jeff Roberson
bb535300dd - Add libthr but don't hook it up to the regular build yet. This is an
adaptation of libc_r for the thr system call interface.  This is beta
   quality code.
2003-04-01 03:46:29 +00:00