fix: sysconf(_SC_NPROCESSORS_CONF) can be less than max cpu id
[urcu.git] / src / rculfhash.c
index 51972c8d1b318c618776a8d0b4b26e5373b9dbae..95b13a2b39676cac0eb7ee6025696794273bbdc0 100644 (file)
 #include "workqueue.h"
 #include "urcu-die.h"
 #include "urcu-utils.h"
+#include "compat-smp.h"
 
 /*
  * Split-counters lazily update the global counter each 1024
@@ -395,7 +396,8 @@ void cds_lfht_iter_debug_set_ht(struct cds_lfht *ht, struct cds_lfht_iter *iter)
 #else
 
 static
-void cds_lfht_iter_debug_set_ht(struct cds_lfht *ht, struct cds_lfht_iter *iter)
+void cds_lfht_iter_debug_set_ht(struct cds_lfht *ht __attribute__((unused)),
+               struct cds_lfht_iter *iter __attribute__((unused)))
 {
 }
 
@@ -581,6 +583,7 @@ unsigned int cds_lfht_fls_ulong(unsigned long x)
  * Return the minimum order for which x <= (1UL << order).
  * Return -1 if x is 0.
  */
+static
 int cds_lfht_get_count_order_u32(uint32_t x)
 {
        if (!x)
@@ -643,12 +646,11 @@ static long nr_cpus_mask = -1;
 static long split_count_mask = -1;
 static int split_count_order = -1;
 
-#if defined(HAVE_SYSCONF)
 static void ht_init_nr_cpus_mask(void)
 {
        long maxcpus;
 
-       maxcpus = sysconf(_SC_NPROCESSORS_CONF);
+       maxcpus = get_possible_cpus_array_len();
        if (maxcpus <= 0) {
                nr_cpus_mask = -2;
                return;
@@ -660,12 +662,6 @@ static void ht_init_nr_cpus_mask(void)
        maxcpus = 1UL << cds_lfht_get_count_order_ulong(maxcpus);
        nr_cpus_mask = maxcpus - 1;
 }
-#else /* #if defined(HAVE_SYSCONF) */
-static void ht_init_nr_cpus_mask(void)
-{
-       nr_cpus_mask = -2;
-}
-#endif /* #else #if defined(HAVE_SYSCONF) */
 
 static
 void alloc_split_items_count(struct cds_lfht *ht)
@@ -761,7 +757,7 @@ void ht_count_del(struct cds_lfht *ht, unsigned long size, unsigned long hash)
 
        if ((count >> CHAIN_LEN_RESIZE_THRESHOLD) >= size)
                return;
-       dbg_printf("del set global %ld\n", count);
+       dbg_printf("del set global %lu\n", count);
        /*
         * Don't shrink table if the number of nodes is below a
         * certain threshold.
@@ -1569,7 +1565,8 @@ const struct cds_lfht_mm_type *get_mm_type(unsigned long max_nr_buckets)
  * For 32-bit architectures, use the order allocator.
  */
 static
-const struct cds_lfht_mm_type *get_mm_type(unsigned long max_nr_buckets)
+const struct cds_lfht_mm_type *get_mm_type(
+               unsigned long max_nr_buckets __attribute__((unused)))
 {
        return &cds_lfht_mm_order;
 }
@@ -1674,7 +1671,8 @@ void cds_lfht_lookup(struct cds_lfht *ht, unsigned long hash,
        iter->next = next;
 }
 
-void cds_lfht_next_duplicate(struct cds_lfht *ht, cds_lfht_match_fct match,
+void cds_lfht_next_duplicate(struct cds_lfht *ht __attribute__((unused)),
+               cds_lfht_match_fct match,
                const void *key, struct cds_lfht_iter *iter)
 {
        struct cds_lfht_node *node, *next;
@@ -1708,7 +1706,8 @@ void cds_lfht_next_duplicate(struct cds_lfht *ht, cds_lfht_match_fct match,
        iter->next = next;
 }
 
-void cds_lfht_next(struct cds_lfht *ht, struct cds_lfht_iter *iter)
+void cds_lfht_next(struct cds_lfht *ht __attribute__((unused)),
+               struct cds_lfht_iter *iter)
 {
        struct cds_lfht_node *node, *next;
 
@@ -2114,7 +2113,7 @@ void cds_lfht_resize_lazy_count(struct cds_lfht *ht, unsigned long size,
        __cds_lfht_resize_lazy_launch(ht);
 }
 
-static void cds_lfht_before_fork(void *priv)
+static void cds_lfht_before_fork(void *priv __attribute__((unused)))
 {
        if (cds_lfht_workqueue_atfork_nesting++)
                return;
@@ -2124,7 +2123,7 @@ static void cds_lfht_before_fork(void *priv)
        urcu_workqueue_pause_worker(cds_lfht_workqueue);
 }
 
-static void cds_lfht_after_fork_parent(void *priv)
+static void cds_lfht_after_fork_parent(void *priv __attribute__((unused)))
 {
        if (--cds_lfht_workqueue_atfork_nesting)
                return;
@@ -2135,7 +2134,7 @@ end:
        mutex_unlock(&cds_lfht_fork_mutex);
 }
 
-static void cds_lfht_after_fork_child(void *priv)
+static void cds_lfht_after_fork_child(void *priv __attribute__((unused)))
 {
        if (--cds_lfht_workqueue_atfork_nesting)
                return;
@@ -2157,8 +2156,9 @@ static struct urcu_atfork cds_lfht_atfork = {
  * disturb the application. The SIGRCU signal needs to be unblocked for
  * the urcu-signal flavor.
  */
-static void cds_lfht_worker_init(struct urcu_workqueue *workqueue,
-               void *priv)
+static void cds_lfht_worker_init(
+               struct urcu_workqueue *workqueue __attribute__((unused)),
+               void *priv __attribute__((unused)))
 {
        int ret;
        sigset_t mask;
This page took 0.025834 seconds and 4 git commands to generate.