diff mbox series

[v2,18/19] nptl: Use tidlock when accessing TID on pthread_setschedprio

Message ID 20210823195047.543237-19-adhemerval.zanella@linaro.org
State Superseded
Headers show
Series Fix various NPTL synchronization issues | expand

Checks

Context Check Description
dj/TryBot-apply_patch success Patch applied to master at the time it was sent

Commit Message

Adhemerval Zanella Aug. 23, 2021, 7:50 p.m. UTC
Checked on x86_64-linux-gnu.
---
 nptl/pthread_setschedprio.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/nptl/pthread_setschedprio.c b/nptl/pthread_setschedprio.c
index 7bb68d3231..f6efdcad8e 100644
--- a/nptl/pthread_setschedprio.c
+++ b/nptl/pthread_setschedprio.c
@@ -30,11 +30,18 @@  __pthread_setschedprio (pthread_t threadid, int prio)
   struct pthread *pd = (struct pthread *) threadid;
 
   /* Make sure the descriptor is valid.  */
-  if (INVALID_TD_P (pd))
-    /* Not a valid thread handle.  */
-    return ESRCH;
+  sigset_t oldmask;
+  __libc_signal_block_all (&oldmask);
+  lll_lock (pd->tidlock, LLL_PRIVATE);
 
   int result = 0;
+
+  if (pd->tid == 0)
+    {
+      result = ESRCH;
+      goto out;
+    }
+
   struct sched_param param;
   param.sched_priority = prio;
 
@@ -60,6 +67,10 @@  __pthread_setschedprio (pthread_t threadid, int prio)
 
   lll_unlock (pd->lock, LLL_PRIVATE);
 
+out:
+  lll_unlock (pd->tidlock, LLL_PRIVATE);
+  __libc_signal_restore_set (&oldmask);
+
   return result;
 }
 versioned_symbol (libc, __pthread_setschedprio, pthread_setschedprio,