]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: cpuset: make the API support negative CPU IDs
authorWilly Tarreau <w@1wt.eu>
Wed, 12 Mar 2025 17:46:25 +0000 (18:46 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 14 Mar 2025 17:30:30 +0000 (18:30 +0100)
Negative IDs are very convenient to mean "not set", so let's just make
the cpuset API robust against this, especially with ha_cpuset_isset()
so that we don't have to manually add this check everywhere when a
value is not known.

src/cpuset.c

index a20b81a25dfa64de8dff53961246576ddfbd2329..6104898ef9bcbf8bcdf034c3048e5a0b6b5b40b7 100644 (file)
@@ -21,7 +21,7 @@ void ha_cpuset_zero(struct hap_cpuset *set)
 
 int ha_cpuset_set(struct hap_cpuset *set, int cpu)
 {
-       if (cpu >= ha_cpuset_size())
+       if (cpu < 0 || cpu >= ha_cpuset_size())
                return 1;
 
 #if defined(CPUSET_USE_CPUSET) || defined(CPUSET_USE_FREEBSD_CPUSET)
@@ -36,7 +36,7 @@ int ha_cpuset_set(struct hap_cpuset *set, int cpu)
 
 int ha_cpuset_clr(struct hap_cpuset *set, int cpu)
 {
-       if (cpu >= ha_cpuset_size())
+       if (cpu < 0 || cpu >= ha_cpuset_size())
                return 1;
 
 #if defined(CPUSET_USE_CPUSET) || defined(CPUSET_USE_FREEBSD_CPUSET)
@@ -77,7 +77,7 @@ void ha_cpuset_or(struct hap_cpuset *dst, struct hap_cpuset *src)
 
 int ha_cpuset_isset(const struct hap_cpuset *set, int cpu)
 {
-       if (cpu >= ha_cpuset_size())
+       if (cpu < 0 || cpu >= ha_cpuset_size())
                return 0;
 
 #if defined(CPUSET_USE_CPUSET) || defined(CPUSET_USE_FREEBSD_CPUSET)