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.
This commit is contained in:
Willy Tarreau 2023-07-06 16:39:08 +02:00
parent fca3fc0d90
commit eb10567254
2 changed files with 18 additions and 0 deletions

View File

@ -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 <cpu> is set in <set>, otherwise 0. */
int ha_cpuset_isset(const struct hap_cpuset *set, int cpu);
/* Returns the count of set index in <set>.
*/
int ha_cpuset_count(const struct hap_cpuset *set);

View File

@ -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)