From 008a71ef213f23c8d403e086563155121b286c0c Mon Sep 17 00:00:00 2001 From: Michael Jeanson Date: Wed, 27 Jul 2022 11:28:58 -0400 Subject: [PATCH] cleanup: use an enum for the error states of nr_cpus_mask Using an enum with labels for error states instead of literal values will make the code easier to read and understand. Change-Id: I4558e17ccb45ab40515bb516af840b2852ee8fc3 Signed-off-by: Michael Jeanson Signed-off-by: Mathieu Desnoyers --- src/rculfhash.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/rculfhash.c b/src/rculfhash.c index a453326..02c7f0f 100644 --- a/src/rculfhash.c +++ b/src/rculfhash.c @@ -347,6 +347,11 @@ struct partition_resize_work { unsigned long start, unsigned long len); }; +enum nr_cpus_mask_state { + NR_CPUS_MASK_INIT_FAILED = -2, + NR_CPUS_MASK_UNINITIALIZED = -1, +}; + static struct urcu_workqueue *cds_lfht_workqueue; /* @@ -624,7 +629,7 @@ static void mutex_unlock(pthread_mutex_t *mutex) urcu_die(ret); } -static long nr_cpus_mask = -1; +static long nr_cpus_mask = NR_CPUS_MASK_UNINITIALIZED; static long split_count_mask = -1; static int split_count_order = -1; @@ -634,7 +639,7 @@ static void ht_init_nr_cpus_mask(void) maxcpus = get_possible_cpus_array_len(); if (maxcpus <= 0) { - nr_cpus_mask = -2; + nr_cpus_mask = NR_CPUS_MASK_INIT_FAILED; return; } /* @@ -648,7 +653,7 @@ static void ht_init_nr_cpus_mask(void) static void alloc_split_items_count(struct cds_lfht *ht) { - if (nr_cpus_mask == -1) { + if (nr_cpus_mask == NR_CPUS_MASK_UNINITIALIZED) { ht_init_nr_cpus_mask(); if (nr_cpus_mask < 0) split_count_mask = DEFAULT_SPLIT_COUNT_MASK; @@ -1241,7 +1246,7 @@ void partition_resize_helper(struct cds_lfht *ht, unsigned long i, unsigned long thread, nr_threads; sigset_t newmask, oldmask; - urcu_posix_assert(nr_cpus_mask != -1); + urcu_posix_assert(nr_cpus_mask != NR_CPUS_MASK_UNINITIALIZED); if (nr_cpus_mask < 0 || len < 2 * MIN_PARTITION_PER_THREAD) goto fallback; -- 2.34.1