about summary refs log tree commit diff
path: root/linuxthreads/rwlock.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>1998-06-25 19:36:00 +0000
committerUlrich Drepper <drepper@redhat.com>1998-06-25 19:36:00 +0000
commit3387a425e65b839b68bd2973f6bc5ab22315cc5d (patch)
tree375713a0b865b10b9eddd9c9877ad68cf0bdc851 /linuxthreads/rwlock.c
parentd47aac39992cb1dd705d8c584f4d3979d7ce4602 (diff)
downloadglibc-3387a425e65b839b68bd2973f6bc5ab22315cc5d.tar.gz
glibc-3387a425e65b839b68bd2973f6bc5ab22315cc5d.tar.xz
glibc-3387a425e65b839b68bd2973f6bc5ab22315cc5d.zip
Finish user stack support. Change locking code to be safe in situations with different priorities.
1998-06-25 19:27  Ulrich Drepper  <drepper@cygnus.com>

	* attr.c: Finish user stack support.  Change locking code to be safe
	in situations with different priorities.
	* cancel.c: Likewise.
	* condvar.c: Likewise.
	* internals.h: Likewise.
	* join.c: Likewise.
	* manager.c: Likewise.
	* mutex.c: Likewise.
	* pthread.c: Likewise.
	* ptlongjmp.c: Likewise.
	* queue.h: Likewise.
	* rwlock.c: Likewise.
	* semaphore.c: Likewise.
	* semaphore.h: Likewise.
	* signals.c: Likewise.
	* spinlock.c: Likewise.
	* spinlock.h: Likewise.
	Patches by Xavier leroy.

1998-06-25  Ulrich Drepper  <drepper@cygnus.com>

	* sysdeps/pthread/pthread.h: Make [sg]et_stacksize and
	[sg]et_stackaddr prototypes always available.

	* sysdeps/unix/sysv/linux/bits/posix_opt.h: Define
	_POSIX_THREAD_ATTR_STACKSIZE and _POSIX_THREAD_ATTR_STACKADDR.
Diffstat (limited to 'linuxthreads/rwlock.c')
-rw-r--r--linuxthreads/rwlock.c47
1 files changed, 23 insertions, 24 deletions
diff --git a/linuxthreads/rwlock.c b/linuxthreads/rwlock.c
index c6b281551a..99209f75da 100644
--- a/linuxthreads/rwlock.c
+++ b/linuxthreads/rwlock.c
@@ -30,12 +30,11 @@ int
 pthread_rwlock_init (pthread_rwlock_t *rwlock,
 		     const pthread_rwlockattr_t *attr)
 {
-  rwlock->rw_spinlock = 0;
+  __pthread_init_lock(&rwlock->rw_lock);
   rwlock->rw_readers = 0;
   rwlock->rw_writer = NULL;
-
-  queue_init(&rwlock->rw_read_waiting);
-  queue_init(&rwlock->rw_write_waiting);
+  rwlock->rw_read_waiting = NULL;
+  rwlock->rw_write_waiting = NULL;
 
   if (attr == NULL)
     {
@@ -58,10 +57,10 @@ pthread_rwlock_destroy (pthread_rwlock_t *rwlock)
   int readers;
   _pthread_descr writer;
 
-  acquire (&rwlock->rw_spinlock);
+  __pthread_lock (&rwlock->rw_lock);
   readers = rwlock->rw_readers;
   writer = rwlock->rw_writer;
-  release (&rwlock->rw_spinlock);
+  __pthread_unlock (&rwlock->rw_lock);
 
   if (readers > 0 || writer != NULL)
     return EBUSY;
@@ -77,7 +76,7 @@ pthread_rwlock_rdlock (pthread_rwlock_t *rwlock)
 
   while (1)
     {
-      acquire (&rwlock->rw_spinlock);
+      __pthread_lock (&rwlock->rw_lock);
       if (rwlock->rw_writer == NULL
 	  || (rwlock->rw_kind == PTHREAD_RWLOCK_PREFER_READER_NP
 	      && rwlock->rw_readers != 0))
@@ -87,12 +86,12 @@ pthread_rwlock_rdlock (pthread_rwlock_t *rwlock)
       /* Suspend ourselves, then try again */
       self = thread_self ();
       enqueue (&rwlock->rw_read_waiting, self);
-      release (&rwlock->rw_spinlock);
+      __pthread_unlock (&rwlock->rw_lock);
       suspend (self); /* This is not a cancellation point */
     }
 
   ++rwlock->rw_readers;
-  release (&rwlock->rw_spinlock);
+  __pthread_unlock (&rwlock->rw_lock);
 
   return 0;
 }
@@ -103,7 +102,7 @@ pthread_rwlock_tryrdlock (pthread_rwlock_t *rwlock)
 {
   int result = EBUSY;
 
-  acquire (&rwlock->rw_spinlock);
+  __pthread_lock (&rwlock->rw_lock);
   if (rwlock->rw_writer == NULL
       || (rwlock->rw_kind == PTHREAD_RWLOCK_PREFER_READER_NP
 	  && rwlock->rw_readers != 0))
@@ -111,7 +110,7 @@ pthread_rwlock_tryrdlock (pthread_rwlock_t *rwlock)
       ++rwlock->rw_readers;
       result = 0;
     }
-  release (&rwlock->rw_spinlock);
+  __pthread_unlock (&rwlock->rw_lock);
 
   return result;
 }
@@ -124,17 +123,17 @@ pthread_rwlock_wrlock (pthread_rwlock_t *rwlock)
 
   while(1)
     {
-      acquire (&rwlock->rw_spinlock);
+      __pthread_lock (&rwlock->rw_lock);
       if (rwlock->rw_readers == 0 && rwlock->rw_writer == NULL)
 	{
 	  rwlock->rw_writer = self;
-	  release (&rwlock->rw_spinlock);
+	  __pthread_unlock (&rwlock->rw_lock);
 	  return 0;
 	}
 
       /* Suspend ourselves, then try again */
       enqueue (&rwlock->rw_write_waiting, self);
-      release (&rwlock->rw_spinlock);
+      __pthread_unlock (&rwlock->rw_lock);
       suspend (self); /* This is not a cancellation point */
     }
 }
@@ -145,13 +144,13 @@ pthread_rwlock_trywrlock (pthread_rwlock_t *rwlock)
 {
   int result = EBUSY;
 
-  acquire (&rwlock->rw_spinlock);
+  __pthread_lock (&rwlock->rw_lock);
   if (rwlock->rw_readers == 0 && rwlock->rw_writer == NULL)
     {
       rwlock->rw_writer = thread_self ();
       result = 0;
     }
-  release (&rwlock->rw_spinlock);
+  __pthread_unlock (&rwlock->rw_lock);
 
   return result;
 }
@@ -160,16 +159,16 @@ pthread_rwlock_trywrlock (pthread_rwlock_t *rwlock)
 int
 pthread_rwlock_unlock (pthread_rwlock_t *rwlock)
 {
-  struct _pthread_queue torestart;
+  pthread_descr torestart;
   pthread_descr th;
 
-  acquire (&rwlock->rw_spinlock);
+  __pthread_lock (&rwlock->rw_lock);
   if (rwlock->rw_writer != NULL)
     {
       /* Unlocking a write lock.  */
       if (rwlock->rw_writer != thread_self ())
 	{
-	  release (&rwlock->rw_spinlock);
+	  __pthread_unlock (&rwlock->rw_lock);
 	  return EPERM;
 	}
       rwlock->rw_writer = NULL;
@@ -179,15 +178,15 @@ pthread_rwlock_unlock (pthread_rwlock_t *rwlock)
 	{
 	  /* Restart all waiting readers.  */
 	  torestart = rwlock->rw_read_waiting;
-	  queue_init (&rwlock->rw_read_waiting);
-	  release (&rwlock->rw_spinlock);
+	  rwlock->rw_read_waiting = NULL;
+	  __pthread_unlock (&rwlock->rw_lock);
 	  while ((th = dequeue (&torestart)) != NULL)
 	    restart (th);
 	}
       else
 	{
 	  /* Restart one waiting writer.  */
-	  release (&rwlock->rw_spinlock);
+	  __pthread_unlock (&rwlock->rw_lock);
 	  restart (th);
 	}
     }
@@ -196,7 +195,7 @@ pthread_rwlock_unlock (pthread_rwlock_t *rwlock)
       /* Unlocking a read lock.  */
       if (rwlock->rw_readers == 0)
 	{
-	  release (&rwlock->rw_spinlock);
+	  __pthread_unlock (&rwlock->rw_lock);
 	  return EPERM;
 	}
 
@@ -207,7 +206,7 @@ pthread_rwlock_unlock (pthread_rwlock_t *rwlock)
       else
 	th = NULL;
 
-      release (&rwlock->rw_spinlock);
+      __pthread_unlock (&rwlock->rw_lock);
       if (th != NULL)
 	restart (th);
     }