]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
hurd: Add __pthread_spin_wait and use it
authorSamuel Thibault <samuel.thibault@ens-lyon.org>
Mon, 10 Feb 2020 22:06:33 +0000 (23:06 +0100)
committerSamuel Thibault <samuel.thibault@ens-lyon.org>
Mon, 10 Feb 2020 23:32:44 +0000 (00:32 +0100)
900778283ac3 ("htl: make pthread_spin_lock really spin") made
pthread_spin_lock really spin and not block, but the current users of
__pthread_spin_lock were assuming that it blocks, i.e. they use it as a
lightweight mutex fitting in just one int.

__pthread_spin_wait provides that support back.

17 files changed:
sysdeps/htl/pt-barrier-wait.c
sysdeps/htl/pt-cond-brdcast.c
sysdeps/htl/pt-cond-destroy.c
sysdeps/htl/pt-cond-signal.c
sysdeps/htl/pt-cond-timedwait.c
sysdeps/htl/pt-once.c
sysdeps/htl/pt-rwlock-timedrdlock.c
sysdeps/htl/pt-rwlock-timedwrlock.c
sysdeps/htl/pt-rwlock-tryrdlock.c
sysdeps/htl/pt-rwlock-trywrlock.c
sysdeps/htl/pt-rwlock-unlock.c
sysdeps/htl/sem-getvalue.c
sysdeps/htl/sem-post.c
sysdeps/htl/sem-timedwait.c
sysdeps/htl/sem-trywait.c
sysdeps/mach/htl/bits/spin-lock-inline.h
sysdeps/mach/hurd/htl/pt-hurd-cond-timedwait.c

index 146605abd8757d2006a0ecebd0ba2ede9e3d4773..46a36f7ca6d2c6d4ad977b0542e6d0fc7ba05d76 100644 (file)
@@ -24,7 +24,7 @@
 int
 pthread_barrier_wait (pthread_barrier_t *barrier)
 {
-  __pthread_spin_lock (&barrier->__lock);
+  __pthread_spin_wait (&barrier->__lock);
   if (--barrier->__pending == 0)
     {
       barrier->__pending = barrier->__count;
index 37dec0a31bc5a58666a669cd782c9587049d885d..816d183ab46106489b65f25471f5954afc1dcf5f 100644 (file)
@@ -26,7 +26,7 @@ __pthread_cond_broadcast (pthread_cond_t *cond)
 {
   struct __pthread *wakeup;
 
-  __pthread_spin_lock (&cond->__lock);
+  __pthread_spin_wait (&cond->__lock);
   while ((wakeup = cond->__queue))
     {
       __pthread_dequeue (wakeup);
@@ -34,7 +34,7 @@ __pthread_cond_broadcast (pthread_cond_t *cond)
       /* Wake it up without spin held, so it may have a chance to really
          preempt us */
       __pthread_wakeup (wakeup);
-      __pthread_spin_lock (&cond->__lock);
+      __pthread_spin_wait (&cond->__lock);
     }
   __pthread_spin_unlock (&cond->__lock);
 
index b28e7e1ada350271a0e486ed65b9bb808e8f1938..57c268248470cd8a8eba518367faa01ec5ff2356 100644 (file)
@@ -24,7 +24,7 @@ __pthread_cond_destroy (pthread_cond_t *cond)
 {
   int ret = 0;
 
-  __pthread_spin_lock (&cond->__lock);
+  __pthread_spin_wait (&cond->__lock);
   if (cond->__queue)
     ret = EBUSY;
   __pthread_spin_unlock (&cond->__lock);
index bbf23011e3bc7951768ff7baf3cf1db5e70fbf4e..30f21cc6b5fe733b8b9daa365e03335a066c3517 100644 (file)
@@ -27,7 +27,7 @@ __pthread_cond_signal (pthread_cond_t *cond)
 {
   struct __pthread *wakeup;
 
-  __pthread_spin_lock (&cond->__lock);
+  __pthread_spin_wait (&cond->__lock);
   wakeup = cond->__queue;
   if (wakeup != NULL)
     __pthread_dequeue (wakeup);
index 3a11e016d73522fd083dab60ad8397fff716dc59..b5ce2f023edf8ff0ba103752c22eac234ecde873 100644 (file)
@@ -50,7 +50,7 @@ cancel_hook (void *arg)
   pthread_cond_t *cond = ctx->cond;
   int unblock;
 
-  __pthread_spin_lock (&cond->__lock);
+  __pthread_spin_wait (&cond->__lock);
   /* The thread only needs to be awaken if it's blocking or about to block.
      If it was already unblocked, it's not queued any more.  */
   unblock = wakeup->prevp != NULL;
@@ -112,7 +112,7 @@ __pthread_cond_timedwait_internal (pthread_cond_t *cond,
          the cancellation hook to simplify the cancellation procedure, i.e.
          if the thread is queued, it can be cancelled, otherwise it is
          already unblocked, progressing on the return path.  */
-      __pthread_spin_lock (&cond->__lock);
+      __pthread_spin_wait (&cond->__lock);
       __pthread_enqueue (&cond->__queue, self);
       if (cond->__attr != NULL)
        clock_id = cond->__attr->__clock;
@@ -135,7 +135,7 @@ __pthread_cond_timedwait_internal (pthread_cond_t *cond,
       __pthread_block (self);
     }
 
-  __pthread_spin_lock (&cond->__lock);
+  __pthread_spin_wait (&cond->__lock);
   if (self->prevp == NULL)
     {
       /* Another thread removed us from the list of waiters, which means a
index 7f86e28006bb7f4b347bf98eb28c2393d1811417..0104eebd3e00579fce72f9713a087db3a21d7dd0 100644 (file)
@@ -36,7 +36,7 @@ __pthread_once (pthread_once_t *once_control, void (*init_routine) (void))
   atomic_full_barrier ();
   if (once_control->__run == 0)
     {
-      __pthread_spin_lock (&once_control->__lock);
+      __pthread_spin_wait (&once_control->__lock);
 
       if (once_control->__run == 0)
        {
index 9dab8deb77d06ac8a9c955f5ff827b97c02b3f38..c2827662fd27b9d98e05b67b5da730767ca85426 100644 (file)
@@ -33,7 +33,7 @@ __pthread_rwlock_timedrdlock_internal (struct __pthread_rwlock *rwlock,
   int drain;
   struct __pthread *self;
 
-  __pthread_spin_lock (&rwlock->__lock);
+  __pthread_spin_wait (&rwlock->__lock);
   if (__pthread_spin_trylock (&rwlock->__held) == 0)
     /* Successfully acquired the lock.  */
     {
@@ -79,7 +79,7 @@ __pthread_rwlock_timedrdlock_internal (struct __pthread_rwlock *rwlock,
       __pthread_block (self);
     }
 
-  __pthread_spin_lock (&rwlock->__lock);
+  __pthread_spin_wait (&rwlock->__lock);
   if (self->prevp == NULL)
     /* Another thread removed us from the queue, which means a wakeup message
        has been sent.  It was either consumed while we were blocking, or
index 57c46dccca9b810152d8080fec88836a545142c5..d0293c1e962f21bce6a812f07a10d9241edd65fe 100644 (file)
@@ -33,7 +33,7 @@ __pthread_rwlock_timedwrlock_internal (struct __pthread_rwlock *rwlock,
   int drain;
   struct __pthread *self;
 
-  __pthread_spin_lock (&rwlock->__lock);
+  __pthread_spin_wait (&rwlock->__lock);
   if (__pthread_spin_trylock (&rwlock->__held) == 0)
     /* Successfully acquired the lock.  */
     {
@@ -65,7 +65,7 @@ __pthread_rwlock_timedwrlock_internal (struct __pthread_rwlock *rwlock,
       __pthread_block (self);
     }
 
-  __pthread_spin_lock (&rwlock->__lock);
+  __pthread_spin_wait (&rwlock->__lock);
   if (self->prevp == NULL)
     /* Another thread removed us from the queue, which means a wakeup message
        has been sent.  It was either consumed while we were blocking, or
index 7baef3cccb0a6f0927c9e4437f3b5782c975a756..897528f24c78f189eb49d88e1c37eb2d407f7b97 100644 (file)
@@ -25,7 +25,7 @@
 int
 pthread_rwlock_tryrdlock (struct __pthread_rwlock *rwlock)
 {
-  __pthread_spin_lock (&rwlock->__lock);
+  __pthread_spin_wait (&rwlock->__lock);
   if (__pthread_spin_trylock (&rwlock->__held) == 0)
     /* Successfully acquired the lock.  */
     {
index 95593a97b96c7dd7e16c204ffafef074d1f380dd..423f7faf0fcb2b45dca96a9737d669bfa54aa1a4 100644 (file)
@@ -25,7 +25,7 @@
 int
 pthread_rwlock_trywrlock (struct __pthread_rwlock *rwlock)
 {
-  __pthread_spin_lock (&rwlock->__lock);
+  __pthread_spin_wait (&rwlock->__lock);
   if (__pthread_spin_trylock (&rwlock->__held) == 0)
     /* Successfully acquired the lock.  */
     {
index 49ed4ee51156167f38bd1489db5b24b81607fb7e..5be6a9e6781ed36f8481a8ba7d37abf75704efd4 100644 (file)
@@ -28,7 +28,7 @@ __pthread_rwlock_unlock (pthread_rwlock_t *rwlock)
 {
   struct __pthread *wakeup;
 
-  __pthread_spin_lock (&rwlock->__lock);
+  __pthread_spin_wait (&rwlock->__lock);
 
   assert (__pthread_spin_trylock (&rwlock->__held) == EBUSY);
 
index 9c8188e8662499eef0b4d97c94d5e0194f1291f5..2d72a63824b8d3f85b27f3e47b68523d00cde7b8 100644 (file)
@@ -22,7 +22,7 @@
 int
 __sem_getvalue (sem_t *restrict sem, int *restrict value)
 {
-  __pthread_spin_lock (&sem->__lock);
+  __pthread_spin_wait (&sem->__lock);
   *value = sem->__value;
   __pthread_spin_unlock (&sem->__lock);
 
index 2e0be8fc4950c89088ccd4cce50e5d9753c5cf58..fd0c6338c68ccc319258ac0c9b58afe833d2859e 100644 (file)
@@ -26,7 +26,7 @@ __sem_post (sem_t *sem)
 {
   struct __pthread *wakeup;
 
-  __pthread_spin_lock (&sem->__lock);
+  __pthread_spin_wait (&sem->__lock);
   if (sem->__value > 0)
     /* Do a quick up.  */
     {
index a61acfd43f6af4f3824d80b378a369bb02b2cdf5..2d8cf253287c9e047fb80c3a23f1ae0f7773bc14 100644 (file)
@@ -32,7 +32,7 @@ __sem_timedwait_internal (sem_t *restrict sem,
   struct __pthread *self;
   clockid_t clock_id = CLOCK_REALTIME;
 
-  __pthread_spin_lock (&sem->__lock);
+  __pthread_spin_wait (&sem->__lock);
   if (sem->__value > 0)
     /* Successful down.  */
     {
@@ -59,7 +59,7 @@ __sem_timedwait_internal (sem_t *restrict sem,
   else
     err = __pthread_block_intr (self);
 
-  __pthread_spin_lock (&sem->__lock);
+  __pthread_spin_wait (&sem->__lock);
   if (self->prevp == NULL)
     /* Another thread removed us from the queue, which means a wakeup message
        has been sent.  It was either consumed while we were blocking, or
index bf8cd6056e43feef59c036042b3a36ce302a6aec..6a0633bfefb747a48b82eac4484f69363440cec9 100644 (file)
@@ -24,7 +24,7 @@
 int
 __sem_trywait (sem_t *sem)
 {
-  __pthread_spin_lock (&sem->__lock);
+  __pthread_spin_wait (&sem->__lock);
   if (sem->__value > 0)
     /* Successful down.  */
     {
index 556bdd4c28b17b1be12e8a8de49503df1778ccba..006b6fd5f24dec25199d82446a1b1906a2bc049b 100644 (file)
@@ -71,6 +71,15 @@ __pthread_spin_lock (__pthread_spinlock_t *__lock)
   return 0;
 }
 
+__PT_SPIN_INLINE int __pthread_spin_wait (__pthread_spinlock_t *__lock);
+
+__PT_SPIN_INLINE int
+__pthread_spin_wait (__pthread_spinlock_t *__lock)
+{
+  __spin_lock ((__spin_lock_t *) __lock);
+  return 0;
+}
+
 __PT_SPIN_INLINE int __pthread_spin_unlock (__pthread_spinlock_t *__lock);
 
 __PT_SPIN_INLINE int
index 12dd8634d47c9051ec42dea0e093269ea795ef1f..939ed568ba7dead06a5380ac074495fc7dc35b3f 100644 (file)
@@ -56,7 +56,7 @@ __pthread_hurd_cond_timedwait_internal (pthread_cond_t *cond,
   {
     int unblock;
 
-    __pthread_spin_lock (&cond->__lock);
+    __pthread_spin_wait (&cond->__lock);
     /* The thread only needs to be awaken if it's blocking or about to block.
        If it was already unblocked, it's not queued any more.  */
     unblock = self->prevp != NULL;
@@ -81,7 +81,7 @@ __pthread_hurd_cond_timedwait_internal (pthread_cond_t *cond,
      the condition variable's lock.  */
 
   __spin_lock (&ss->lock);
-  __pthread_spin_lock (&cond->__lock);
+  __pthread_spin_wait (&cond->__lock);
   cancel = ss->cancel;
   if (cancel)
     /* We were cancelled before doing anything.  Don't block at all.  */
@@ -123,7 +123,7 @@ __pthread_hurd_cond_timedwait_internal (pthread_cond_t *cond,
       /* As it was done when enqueueing, prevent hurd_thread_cancel from
          suspending us while the condition lock is held.  */
       __spin_lock (&ss->lock);
-      __pthread_spin_lock (&cond->__lock);
+      __pthread_spin_wait (&cond->__lock);
       if (self->prevp == NULL)
        /* Another thread removed us from the list of waiters, which means
           a wakeup message has been sent.  It was either consumed while