Back to index

glibc  2.9
sched_getaffinity.c
Go to the documentation of this file.
00001 /* Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003 
00004    The GNU C Library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Lesser General Public
00006    License as published by the Free Software Foundation; either
00007    version 2.1 of the License, or (at your option) any later version.
00008 
00009    The GNU C Library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Lesser General Public License for more details.
00013 
00014    You should have received a copy of the GNU Lesser General Public
00015    License along with the GNU C Library; if not, write to the Free
00016    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00017    02111-1307 USA.  */
00018 
00019 #include <errno.h>
00020 #include <sched.h>
00021 #include <string.h>
00022 #include <sysdep.h>
00023 #include <sys/param.h>
00024 #include <sys/types.h>
00025 #include <shlib-compat.h>
00026 
00027 
00028 #ifdef __NR_sched_getaffinity
00029 int
00030 __sched_getaffinity_new (pid_t pid, size_t cpusetsize, cpu_set_t *cpuset)
00031 {
00032   int res = INLINE_SYSCALL (sched_getaffinity, 3, pid,
00033                          MIN (INT_MAX, cpusetsize), cpuset);
00034   if (res != -1)
00035     {
00036       /* Clean the rest of the memory the kernel didn't do.  */
00037       memset ((char *) cpuset + res, '\0', cpusetsize - res);
00038 
00039       res = 0;
00040     }
00041   return res;
00042 }
00043 versioned_symbol (libc, __sched_getaffinity_new, sched_getaffinity,
00044                 GLIBC_2_3_4);
00045 
00046 
00047 # if SHLIB_COMPAT (libc, GLIBC_2_3_3, GLIBC_2_3_4)
00048 int
00049 attribute_compat_text_section
00050 __sched_getaffinity_old (pid_t pid, cpu_set_t *cpuset)
00051 {
00052   /* The old interface by default assumed a 1024 processor bitmap.  */
00053   return __sched_getaffinity_new (pid, 128, cpuset);
00054 }
00055 compat_symbol (libc, __sched_getaffinity_old, sched_getaffinity, GLIBC_2_3_3);
00056 # endif
00057 #else
00058 # include <posix/sched_getaffinity.c>
00059 #endif