[v2,13/19] nptl: Use tidlock when accessing TID on pthread_getschedparam
Checks
Context |
Check |
Description |
dj/TryBot-apply_patch |
success
|
Patch applied to master at the time it was sent
|
Commit Message
Checked on x86_64-linux-gnu.
---
nptl/pthread_getschedparam.c | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
Comments
* Adhemerval Zanella:
> Checked on x86_64-linux-gnu.
> ---
> nptl/pthread_getschedparam.c | 16 +++++++++++++---
> 1 file changed, 13 insertions(+), 3 deletions(-)
>
> diff --git a/nptl/pthread_getschedparam.c b/nptl/pthread_getschedparam.c
> index 94316cf897..c41d2a8341 100644
> --- a/nptl/pthread_getschedparam.c
> +++ b/nptl/pthread_getschedparam.c
> @@ -29,12 +29,18 @@ __pthread_getschedparam (pthread_t threadid, int *policy,
> 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;
> + }
We can avoid returning ESRCH by storing the parameters unconditionally
in the TCB. That should also simplify the implementation, potentially
at the cost of a few extra system calls.
Thanks,
Florian
@@ -29,12 +29,18 @@ __pthread_getschedparam (pthread_t threadid, int *policy,
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;
+ }
+
/* See CREATE THREAD NOTES in nptl/pthread_create.c. */
lll_lock (pd->lock, LLL_PRIVATE);
@@ -68,6 +74,10 @@ __pthread_getschedparam (pthread_t threadid, int *policy,
lll_unlock (pd->lock, LLL_PRIVATE);
+out:
+ lll_unlock (pd->tidlock, LLL_PRIVATE);
+ __libc_signal_restore_set (&oldmask);
+
return result;
}
libc_hidden_def (__pthread_getschedparam)