From 3955f151b1fab153de6b7a6310ec2f391ec2392e Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Mon, 31 Mar 2025 15:14:53 +0200 Subject: [PATCH] MINOR: cpu-set: compare two cpu sets with ha_cpuset_isequal() This function returns true if two CPU sets are equal. --- include/haproxy/cpuset.h | 3 +++ src/cpuset.c | 14 ++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/include/haproxy/cpuset.h b/include/haproxy/cpuset.h index 842f09f0d..14c669c25 100644 --- a/include/haproxy/cpuset.h +++ b/include/haproxy/cpuset.h @@ -44,6 +44,9 @@ int ha_cpuset_ffs(const struct hap_cpuset *set); */ void ha_cpuset_assign(struct hap_cpuset *dst, struct hap_cpuset *src); +/* returns true if the sets are equal */ +int ha_cpuset_isequal(const struct hap_cpuset *dst, const struct hap_cpuset *src); + /* Returns the biggest index plus one usable on the platform. */ int ha_cpuset_size(void); diff --git a/src/cpuset.c b/src/cpuset.c index 6b5c6d9ca..b102d11d1 100644 --- a/src/cpuset.c +++ b/src/cpuset.c @@ -134,6 +134,20 @@ void ha_cpuset_assign(struct hap_cpuset *dst, struct hap_cpuset *src) #endif } +/* returns true if the sets are equal */ +int ha_cpuset_isequal(const struct hap_cpuset *dst, const struct hap_cpuset *src) +{ +#if defined(CPUSET_USE_CPUSET) + return CPU_EQUAL(&dst->cpuset, &src->cpuset); + +#elif defined(CPUSET_USE_FREEBSD_CPUSET) + return !CPU_CMP(&src->cpuset, &dst->cpuset); + +#elif defined(CPUSET_USE_ULONG) + return dst->cpuset == src->cpuset; +#endif +} + int ha_cpuset_size() { #if defined(CPUSET_USE_CPUSET) || defined(CPUSET_USE_FREEBSD_CPUSET)