Home | History | Annotate | Line # | Download | only in compat
      1 /*
      2  * cpuset.c -- CPU affinity.
      3  *
      4  * Copyright (c) 2020, NLnet Labs. All rights reserved.
      5  *
      6  * See LICENSE for the license.
      7  *
      8  */
      9 #include "config.h"
     10 #include "cpuset.h"
     11 
     12 #include <stdlib.h>
     13 #include <sys/types.h>
     14 #include <unistd.h>
     15 
     16 #ifndef HAVE_CPUSET_CREATE
     17 cpuset_t *cpuset_create(void)
     18 {
     19   cpuset_t *set = calloc(1, sizeof(*set));
     20   return set;
     21 }
     22 #endif /* !HAVE_CPUSET_CREATE */
     23 
     24 #ifndef HAVE_CPUSET_DESTROY
     25 void cpuset_destroy(cpuset_t *set)
     26 {
     27   free(set);
     28 }
     29 #endif /* !HAVE_CPUSET_DESTROY */
     30 
     31 #ifndef HAVE_CPUSET_ZERO
     32 void cpuset_zero(cpuset_t *set)
     33 {
     34   CPU_ZERO(set);
     35 }
     36 #endif /* !HAVE_CPUSET_ZERO */
     37 
     38 #ifndef HAVE_CPUSET_SET
     39 int cpuset_set(cpuid_t cpu, cpuset_t *set)
     40 {
     41   CPU_SET(cpu, set);
     42   return 0;
     43 }
     44 #endif /* !HAVE_CPUSET_SET */
     45 
     46 #ifndef HAVE_CPUSET_CLR
     47 int cpuset_clr(cpuid_t cpu, cpuset_t *set)
     48 {
     49   CPU_CLR(cpu, set);
     50   return 0;
     51 }
     52 #endif /* !HAVE_CPUSET_CLR */
     53 
     54 #ifndef HAVE_CPUSET_ISSET
     55 int cpuset_isset(cpuid_t cpu, const cpuset_t *set)
     56 {
     57   return CPU_ISSET(cpu, set);
     58 }
     59 #endif /* !HAVE_CPUSET_ISSET */
     60 
     61 #ifndef HAVE_CPUSET_SIZE
     62 size_t cpuset_size(const cpuset_t *set)
     63 {
     64   return sizeof(*set);
     65 }
     66 #endif /* !HAVE_CPUSET_SIZE */
     67 
     68 #ifdef CPU_OR_THREE_ARGS
     69 /* for Linux, use three arguments */
     70 void cpuset_or(cpuset_t *destset, const cpuset_t *srcset)
     71 {
     72   CPU_OR(destset, destset, srcset);
     73 }
     74 #else
     75 /* for FreeBSD, use two arguments */
     76 void cpuset_or(cpuset_t *destset, const cpuset_t *srcset)
     77 {
     78   CPU_OR(destset, srcset);
     79 }
     80 #endif
     81