summaryrefslogtreecommitdiff
path: root/nptl/sysdeps
diff options
context:
space:
mode:
Diffstat (limited to 'nptl/sysdeps')
-rw-r--r--nptl/sysdeps/pthread/pthread.h4
-rw-r--r--nptl/sysdeps/unix/sysv/linux/pthread_attr_setaffinity.c18
2 files changed, 16 insertions, 6 deletions
diff --git a/nptl/sysdeps/pthread/pthread.h b/nptl/sysdeps/pthread/pthread.h
index af0a22a111..6e8da67753 100644
--- a/nptl/sysdeps/pthread/pthread.h
+++ b/nptl/sysdeps/pthread/pthread.h
@@ -334,7 +334,9 @@ extern int pthread_attr_getaffinity_np (__const pthread_attr_t *__attr,
cpu_set_t *__cpuset) __THROW;
-/* Get thread attributes corresponding to the already running thread TH. */
+/* Initialize thread attribute *ATTR with attributes corresponding to the
+ already running thread TH. It shall be called on unitialized ATTR
+ and destroyed with pthread_attr_destroy when no longer needed. */
extern int pthread_getattr_np (pthread_t __th, pthread_attr_t *__attr) __THROW;
#endif
diff --git a/nptl/sysdeps/unix/sysv/linux/pthread_attr_setaffinity.c b/nptl/sysdeps/unix/sysv/linux/pthread_attr_setaffinity.c
index f25ccb213e..de8f54fb97 100644
--- a/nptl/sysdeps/unix/sysv/linux/pthread_attr_setaffinity.c
+++ b/nptl/sysdeps/unix/sysv/linux/pthread_attr_setaffinity.c
@@ -34,14 +34,22 @@ pthread_attr_setaffinity_np (attr, cpuset)
assert (sizeof (*attr) >= sizeof (struct pthread_attr));
iattr = (struct pthread_attr *) attr;
- if (iattr->cpuset == NULL)
+ if (cpuset == NULL)
{
- iattr->cpuset = (cpu_set_t *) malloc (sizeof (cpu_set_t));
- if (iattr->cpuset == NULL)
- return ENOMEM;
+ free (iattr->cpuset);
+ iattr->cpuset = NULL;
}
+ else
+ {
+ if (iattr->cpuset == NULL)
+ {
+ iattr->cpuset = (cpu_set_t *) malloc (sizeof (cpu_set_t));
+ if (iattr->cpuset == NULL)
+ return ENOMEM;
+ }
- memcpy (iattr->cpuset, cpuset, sizeof (cpu_set_t));
+ memcpy (iattr->cpuset, cpuset, sizeof (cpu_set_t));
+ }
return 0;
}