From 439ff07be06e9354151f984c7d0d2fb05917e8be Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Fri, 19 Mar 2004 00:14:42 +0000 Subject: Update. 2004-03-18 Ulrich Drepper * posix/sched.h: Change sched_getaffinity and sched_setaffinity interfaces: add new second parameter. * sysdeps/generic/sched_getaffinity.c: Implement interface change. * sysdeps/generic/sched_setaffinity.c: Likewise. * sysdeps/unix/sysv/linux/sched_getaffinity.c: Likewise. Add compatibility interface. * sysdeps/unix/sysv/linux/sched_setaffinity.c: Likewise. * sysdeps/unix/sysv/linux/Versions: Add versions for changed interfaces. --- nptl/pthread_getattr_np.c | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) (limited to 'nptl/pthread_getattr_np.c') diff --git a/nptl/pthread_getattr_np.c b/nptl/pthread_getattr_np.c index 0925ced37f..df11b1ff1d 100644 --- a/nptl/pthread_getattr_np.c +++ b/nptl/pthread_getattr_np.c @@ -135,18 +135,35 @@ pthread_getattr_np (thread_id, attr) if (ret == 0) { - iattr->cpuset = (cpu_set_t *) malloc (sizeof (cpu_set_t)); - if (iattr->cpuset == NULL) - ret = ENOMEM; - else + size_t size = 32; + cpu_set_t *cpuset = NULL; + + do { - ret = pthread_getaffinity_np (thread_id, iattr->cpuset); - if (ret == ENOSYS) + void *newp = realloc (cpuset, size); + if (newp == NULL) { - free (iattr->cpuset); - iattr->cpuset = NULL; - ret = 0; + free (cpuset); + ret = ENOMEM; } + cpuset = (cpu_set_t *) newp; + + ret = __pthread_getaffinity_np (thread_id, size, cpuset); + } + /* Pick some ridiculous upper limit. Is 8 million CPUs enough? */ + while (ret == EINVAL && size < 1024 * 1024); + + if (ret == 0) + { + iattr->cpuset = cpuset; + iattr->cpusetsize = size; + } + else + { + free (cpuset); + if (ret == ENOSYS) + /* There is no such functionality. */ + ret = 0; } } -- cgit v1.2.3