diff mbox series

[12/19] nptl: Use __pthread_getattr_default_np in pthread_create

Message ID c8087865726645761dd188439b106f25a9a49637.1589884403.git.fweimer@redhat.com
State Committed
Headers show
Series Signal mask for timer helper thread | expand

Commit Message

Florian Weimer May 19, 2020, 10:44 a.m. UTC
This removes another instance of custom attribute copying code.
---
 nptl/pthread_create.c | 32 +++++++-------------------------
 1 file changed, 7 insertions(+), 25 deletions(-)

Comments

Carlos O'Donell June 2, 2020, 3:34 a.m. UTC | #1
On 5/19/20 6:44 AM, Florian Weimer via Libc-alpha wrote:
> This removes another instance of custom attribute copying code.

OK for master.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>

> ---
>  nptl/pthread_create.c | 32 +++++++-------------------------
>  1 file changed, 7 insertions(+), 25 deletions(-)
> 
> diff --git a/nptl/pthread_create.c b/nptl/pthread_create.c
> index a43089065c..347d510707 100644
> --- a/nptl/pthread_create.c
> +++ b/nptl/pthread_create.c
> @@ -613,32 +613,14 @@ __pthread_create_2_1 (pthread_t *newthread, const pthread_attr_t *attr,
>  
>    const struct pthread_attr *iattr = (struct pthread_attr *) attr;
>    struct pthread_attr default_attr;
> -  bool free_cpuset = false;
> +  bool destroy_default_attr = false;

OK.

>    bool c11 = (attr == ATTR_C11_THREAD);
>    if (iattr == NULL || c11)
>      {
> -      lll_lock (__default_pthread_attr_lock, LLL_PRIVATE);
> -      default_attr = __default_pthread_attr;
> -      size_t cpusetsize = default_attr.cpusetsize;
> -      if (cpusetsize > 0)
> -	{
> -	  cpu_set_t *cpuset;
> -	  if (__glibc_likely (__libc_use_alloca (cpusetsize)))
> -	    cpuset = __alloca (cpusetsize);
> -	  else
> -	    {
> -	      cpuset = malloc (cpusetsize);
> -	      if (cpuset == NULL)
> -		{
> -		  lll_unlock (__default_pthread_attr_lock, LLL_PRIVATE);
> -		  return ENOMEM;
> -		}
> -	      free_cpuset = true;
> -	    }
> -	  memcpy (cpuset, default_attr.cpuset, cpusetsize);
> -	  default_attr.cpuset = cpuset;
> -	}
> -      lll_unlock (__default_pthread_attr_lock, LLL_PRIVATE);
> +      int ret = __pthread_getattr_default_np ((pthread_attr_t *) &default_attr);

OK. Call internally to get the default attributes.

> +      if (ret != 0)
> +	return ret;
> +      destroy_default_attr = true;
>        iattr = &default_attr;
>      }
>  
> @@ -869,8 +851,8 @@ __pthread_create_2_1 (pthread_t *newthread, const pthread_attr_t *attr,
>      }
>  
>   out:
> -  if (__glibc_unlikely (free_cpuset))
> -    free (default_attr.cpuset);
> +  if (destroy_default_attr)
> +    __pthread_attr_destroy ((pthread_attr_t *) &default_attr);

OK.

>  
>    return retval;
>  }
>
diff mbox series

Patch

diff --git a/nptl/pthread_create.c b/nptl/pthread_create.c
index a43089065c..347d510707 100644
--- a/nptl/pthread_create.c
+++ b/nptl/pthread_create.c
@@ -613,32 +613,14 @@  __pthread_create_2_1 (pthread_t *newthread, const pthread_attr_t *attr,
 
   const struct pthread_attr *iattr = (struct pthread_attr *) attr;
   struct pthread_attr default_attr;
-  bool free_cpuset = false;
+  bool destroy_default_attr = false;
   bool c11 = (attr == ATTR_C11_THREAD);
   if (iattr == NULL || c11)
     {
-      lll_lock (__default_pthread_attr_lock, LLL_PRIVATE);
-      default_attr = __default_pthread_attr;
-      size_t cpusetsize = default_attr.cpusetsize;
-      if (cpusetsize > 0)
-	{
-	  cpu_set_t *cpuset;
-	  if (__glibc_likely (__libc_use_alloca (cpusetsize)))
-	    cpuset = __alloca (cpusetsize);
-	  else
-	    {
-	      cpuset = malloc (cpusetsize);
-	      if (cpuset == NULL)
-		{
-		  lll_unlock (__default_pthread_attr_lock, LLL_PRIVATE);
-		  return ENOMEM;
-		}
-	      free_cpuset = true;
-	    }
-	  memcpy (cpuset, default_attr.cpuset, cpusetsize);
-	  default_attr.cpuset = cpuset;
-	}
-      lll_unlock (__default_pthread_attr_lock, LLL_PRIVATE);
+      int ret = __pthread_getattr_default_np ((pthread_attr_t *) &default_attr);
+      if (ret != 0)
+	return ret;
+      destroy_default_attr = true;
       iattr = &default_attr;
     }
 
@@ -869,8 +851,8 @@  __pthread_create_2_1 (pthread_t *newthread, const pthread_attr_t *attr,
     }
 
  out:
-  if (__glibc_unlikely (free_cpuset))
-    free (default_attr.cpuset);
+  if (destroy_default_attr)
+    __pthread_attr_destroy ((pthread_attr_t *) &default_attr);
 
   return retval;
 }