From: Willy Tarreau Date: Thu, 6 Jul 2023 14:39:08 +0000 (+0200) Subject: MINOR: cpuset: add ha_cpuset_isset() to check for the presence of a CPU in a set X-Git-Tag: v2.9-dev5~58 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=eb105672547e64825fb00513c031d7d5cde1b564;p=thirdparty%2Fhaproxy.git MINOR: cpuset: add ha_cpuset_isset() to check for the presence of a CPU in a set This function will be convenient to test for the presence of a given CPU in a set. --- diff --git a/include/haproxy/cpuset.h b/include/haproxy/cpuset.h index 4f795f2643..dd1043ef55 100644 --- a/include/haproxy/cpuset.h +++ b/include/haproxy/cpuset.h @@ -23,6 +23,9 @@ int ha_cpuset_clr(struct hap_cpuset *set, int cpu); */ void ha_cpuset_and(struct hap_cpuset *dst, struct hap_cpuset *src); +/* returns non-zero if CPU index is set in , otherwise 0. */ +int ha_cpuset_isset(const struct hap_cpuset *set, int cpu); + /* Returns the count of set index in . */ int ha_cpuset_count(const struct hap_cpuset *set); diff --git a/src/cpuset.c b/src/cpuset.c index 4e1c537620..b89433a4d0 100644 --- a/src/cpuset.c +++ b/src/cpuset.c @@ -60,6 +60,21 @@ void ha_cpuset_and(struct hap_cpuset *dst, struct hap_cpuset *src) #endif } +int ha_cpuset_isset(const struct hap_cpuset *set, int cpu) +{ + if (cpu >= ha_cpuset_size()) + return 0; + +#if defined(CPUSET_USE_CPUSET) || defined(CPUSET_USE_FREEBSD_CPUSET) + return CPU_ISSET(cpu, &set->cpuset); + +#elif defined(CPUSET_USE_ULONG) + return !!(set->cpuset & (0x1 << cpu)); +#else + return 0; +#endif +} + int ha_cpuset_count(const struct hap_cpuset *set) { #if defined(CPUSET_USE_CPUSET) || defined(CPUSET_USE_FREEBSD_CPUSET)