sched_setaffinity.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* Copyright (C) 2002-2019 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, see
  13. <http://www.gnu.org/licenses/>. */
  14. #include <errno.h>
  15. #include <sched.h>
  16. #include <string.h>
  17. #include <sysdep.h>
  18. #include <unistd.h>
  19. #include <sys/types.h>
  20. #include <shlib-compat.h>
  21. #ifdef __NR_sched_setaffinity
  22. extern int __sched_setaffinity_new (pid_t, size_t, const cpu_set_t *);
  23. libc_hidden_proto (__sched_setaffinity_new)
  24. int
  25. __sched_setaffinity_new (pid_t pid, size_t cpusetsize, const cpu_set_t *cpuset)
  26. {
  27. int result = INLINE_SYSCALL (sched_setaffinity, 3, pid, cpusetsize, cpuset);
  28. #ifdef RESET_VGETCPU_CACHE
  29. if (result != -1)
  30. RESET_VGETCPU_CACHE ();
  31. #endif
  32. return result;
  33. }
  34. libc_hidden_def (__sched_setaffinity_new)
  35. versioned_symbol (libc, __sched_setaffinity_new, sched_setaffinity,
  36. GLIBC_2_3_4);
  37. # if SHLIB_COMPAT (libc, GLIBC_2_3_3, GLIBC_2_3_4)
  38. int
  39. attribute_compat_text_section
  40. __sched_setaffinity_old (pid_t pid, const cpu_set_t *cpuset)
  41. {
  42. /* The old interface by default assumed a 1024 processor bitmap. */
  43. return __sched_setaffinity_new (pid, 128, cpuset);
  44. }
  45. compat_symbol (libc, __sched_setaffinity_old, sched_setaffinity, GLIBC_2_3_3);
  46. # endif
  47. #else
  48. # include <posix/sched_setaffinity.c>
  49. #endif