(root)/
glibc-2.38/
nptl/
pthread_setaffinity.c
       1  /* Copyright (C) 2003-2023 Free Software Foundation, Inc.
       2     This file is part of the GNU C Library.
       3  
       4     The GNU C Library is free software; you can redistribute it and/or
       5     modify it under the terms of the GNU Lesser General Public
       6     License as published by the Free Software Foundation; either
       7     version 2.1 of the License, or (at your option) any later version.
       8  
       9     The GNU C Library is distributed in the hope that it will be useful,
      10     but WITHOUT ANY WARRANTY; without even the implied warranty of
      11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      12     Lesser General Public License for more details.
      13  
      14     You should have received a copy of the GNU Lesser General Public
      15     License along with the GNU C Library; if not, see
      16     <https://www.gnu.org/licenses/>.  */
      17  
      18  #include <errno.h>
      19  #include <pthreadP.h>
      20  #include <sysdep.h>
      21  #include <sys/types.h>
      22  #include <shlib-compat.h>
      23  
      24  
      25  int
      26  __pthread_setaffinity_new (pthread_t th, size_t cpusetsize,
      27  			   const cpu_set_t *cpuset)
      28  {
      29    const struct pthread *pd = (const struct pthread *) th;
      30    int res;
      31  
      32    res = INTERNAL_SYSCALL_CALL (sched_setaffinity, pd->tid, cpusetsize,
      33  			       cpuset);
      34  
      35    return (INTERNAL_SYSCALL_ERROR_P (res)
      36  	  ? INTERNAL_SYSCALL_ERRNO (res)
      37  	  : 0);
      38  }
      39  versioned_symbol (libc, __pthread_setaffinity_new,
      40  		  pthread_setaffinity_np, GLIBC_2_34);
      41  
      42  #if OTHER_SHLIB_COMPAT (libpthread, GLIBC_2_3_4, GLIBC_2_34)
      43  compat_symbol (libpthread, __pthread_setaffinity_new,
      44  	       pthread_setaffinity_np, GLIBC_2_3_4);
      45  #endif
      46  
      47  #if OTHER_SHLIB_COMPAT (libpthread, GLIBC_2_3_3, GLIBC_2_3_4)
      48  int
      49  __pthread_setaffinity_old (pthread_t th, cpu_set_t *cpuset)
      50  {
      51    /* The old interface by default assumed a 1024 processor bitmap.  */
      52    return __pthread_setaffinity_new (th, 128, cpuset);
      53  }
      54  compat_symbol (libpthread, __pthread_setaffinity_old, pthread_setaffinity_np,
      55  	       GLIBC_2_3_3);
      56  #endif