cleanup: use an enum for the error states of nr_cpus_mask
authorMichael Jeanson <mjeanson@efficios.com>
Wed, 27 Jul 2022 15:28:58 +0000 (11:28 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 19 Oct 2023 20:44:50 +0000 (16:44 -0400)
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 <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
src/rculfhash.c

index a453326a4124f11ac06aeb14697214d99b3c020d..02c7f0f6dc3564fc4f10348a24ea89deee6a8a3d 100644 (file)
@@ -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;
 
This page took 0.026983 seconds and 4 git commands to generate.