mirror of
https://sourceware.org/git/glibc.git
synced 2024-12-23 03:10:05 +00:00
pthread_setaffinity (Linux variant): Rewrite to use VLA instead of alloca
extend_alloca was used to emulate VLA deallocation. The new version also handles the res == 0 corner case more explicitly, by returning 0 instead of the (potentially undefined, but usually zero) system call error.
This commit is contained in:
parent
2b028564f1
commit
98734cc501
@ -1,3 +1,9 @@
|
|||||||
|
2015-03-23 Florian Weimer <fweimer@redhat.com>
|
||||||
|
|
||||||
|
* sysdeps/unix/sysv/linux/pthread_setaffinity.c
|
||||||
|
(__determine_cpumask_size): Replace extend_alloca with a
|
||||||
|
variable-length array. Do not treat res == 0 as an error.
|
||||||
|
|
||||||
2015-03-23 Florian Weimer <fweimer@redhat.com>
|
2015-03-23 Florian Weimer <fweimer@redhat.com>
|
||||||
|
|
||||||
[BZ #18100]
|
[BZ #18100]
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
License along with the GNU C Library; if not, see
|
License along with the GNU C Library; if not, see
|
||||||
<http://www.gnu.org/licenses/>. */
|
<http://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
#include <alloca.h>
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <pthreadP.h>
|
#include <pthreadP.h>
|
||||||
#include <sysdep.h>
|
#include <sysdep.h>
|
||||||
@ -27,25 +26,29 @@
|
|||||||
size_t __kernel_cpumask_size attribute_hidden;
|
size_t __kernel_cpumask_size attribute_hidden;
|
||||||
|
|
||||||
|
|
||||||
/* Determine the current affinity. As a side affect we learn
|
/* Determine the size of cpumask_t in the kernel. */
|
||||||
about the size of the cpumask_t in the kernel. */
|
|
||||||
int
|
int
|
||||||
__determine_cpumask_size (pid_t tid)
|
__determine_cpumask_size (pid_t tid)
|
||||||
{
|
{
|
||||||
INTERNAL_SYSCALL_DECL (err);
|
size_t psize;
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
size_t psize = 128;
|
for (psize = 128; ; psize *= 2)
|
||||||
void *p = alloca (psize);
|
{
|
||||||
|
char buf[psize];
|
||||||
|
INTERNAL_SYSCALL_DECL (err);
|
||||||
|
|
||||||
while (res = INTERNAL_SYSCALL (sched_getaffinity, err, 3, tid, psize, p),
|
res = INTERNAL_SYSCALL (sched_getaffinity, err, 3, tid, psize, buf);
|
||||||
INTERNAL_SYSCALL_ERROR_P (res, err)
|
if (INTERNAL_SYSCALL_ERROR_P (res, err))
|
||||||
&& INTERNAL_SYSCALL_ERRNO (res, err) == EINVAL)
|
{
|
||||||
p = extend_alloca (p, psize, 2 * psize);
|
if (INTERNAL_SYSCALL_ERRNO (res, err) != EINVAL)
|
||||||
|
|
||||||
if (res == 0 || INTERNAL_SYSCALL_ERROR_P (res, err))
|
|
||||||
return INTERNAL_SYSCALL_ERRNO (res, err);
|
return INTERNAL_SYSCALL_ERRNO (res, err);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (res != 0)
|
||||||
__kernel_cpumask_size = res;
|
__kernel_cpumask_size = res;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user