about summary refs log tree commit diff
path: root/nptl/pthread_attr_setaffinity.c
diff options
context:
space:
mode:
authorFlorian Weimer <fweimer@redhat.com>2020-06-02 10:33:30 +0200
committerFlorian Weimer <fweimer@redhat.com>2020-06-02 11:54:58 +0200
commit7538d461134bf306e31b40e4032f0c225bb40d51 (patch)
tree34c4ceb7c6565864dfc62d8e23dd8f37e24944af /nptl/pthread_attr_setaffinity.c
parent6993670b52daa413717e840dfb17b5322e7f4a88 (diff)
downloadglibc-7538d461134bf306e31b40e4032f0c225bb40d51.tar.gz
glibc-7538d461134bf306e31b40e4032f0c225bb40d51.tar.xz
glibc-7538d461134bf306e31b40e4032f0c225bb40d51.zip
nptl: Make pthread_attr_t dynamically extensible
This introduces the function __pthread_attr_extension to allocate the
extension space, which is freed by pthread_attr_destroy.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Diffstat (limited to 'nptl/pthread_attr_setaffinity.c')
-rw-r--r--nptl/pthread_attr_setaffinity.c23
1 files changed, 15 insertions, 8 deletions
diff --git a/nptl/pthread_attr_setaffinity.c b/nptl/pthread_attr_setaffinity.c
index a42ffd92f4..9f9a70dee0 100644
--- a/nptl/pthread_attr_setaffinity.c
+++ b/nptl/pthread_attr_setaffinity.c
@@ -34,23 +34,30 @@ __pthread_attr_setaffinity_np (pthread_attr_t *attr, size_t cpusetsize,
 
   if (cpuset == NULL || cpusetsize == 0)
     {
-      free (iattr->cpuset);
-      iattr->cpuset = NULL;
-      iattr->cpusetsize = 0;
+      if (iattr->extension != NULL)
+	{
+	  free (iattr->extension->cpuset);
+	  iattr->extension->cpuset = NULL;
+	  iattr->extension->cpusetsize = 0;
+	}
     }
   else
     {
-      if (iattr->cpusetsize != cpusetsize)
+      int ret = __pthread_attr_extension (iattr);
+      if (ret != 0)
+	return ret;
+
+      if (iattr->extension->cpusetsize != cpusetsize)
 	{
-	  void *newp = (cpu_set_t *) realloc (iattr->cpuset, cpusetsize);
+	  void *newp = realloc (iattr->extension->cpuset, cpusetsize);
 	  if (newp == NULL)
 	    return ENOMEM;
 
-	  iattr->cpuset = newp;
-	  iattr->cpusetsize = cpusetsize;
+	  iattr->extension->cpuset = newp;
+	  iattr->extension->cpusetsize = cpusetsize;
 	}
 
-      memcpy (iattr->cpuset, cpuset, cpusetsize);
+      memcpy (iattr->extension->cpuset, cpuset, cpusetsize);
     }
 
   return 0;