configure: enable extended compiler warnings
[urcu.git] / src / rculfhash.c
index 8942c80ba8c6e8eb5f155cd49e10c22d8455ee23..9106a745ff29a24dcefef9a1e671ee28fd68b7e1 100644 (file)
 #include <urcu/uatomic.h>
 #include <urcu/compiler.h>
 #include <urcu/rculfhash.h>
+#include <urcu/static/urcu-signal-nr.h>
 #include <rculfhash-internal.h>
 #include <stdio.h>
 #include <pthread.h>
 #include <signal.h>
 #include "workqueue.h"
 #include "urcu-die.h"
+#include "urcu-utils.h"
 
 /*
  * Split-counters lazily update the global counter each 1024
@@ -393,7 +395,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)))
 {
 }
 
@@ -465,7 +468,7 @@ unsigned long bit_reverse_ulong(unsigned long v)
  * Returns 0 if no bit is set, else returns the position of the most
  * significant bit (from 1 to 32 on 32-bit, from 1 to 64 on 64-bit).
  */
-#if defined(__i386) || defined(__x86_64)
+#if defined(URCU_ARCH_X86)
 static inline
 unsigned int fls_u32(uint32_t x)
 {
@@ -481,7 +484,7 @@ unsigned int fls_u32(uint32_t x)
 #define HAS_FLS_U32
 #endif
 
-#if defined(__x86_64)
+#if defined(URCU_ARCH_AMD64)
 static inline
 unsigned int fls_u64(uint64_t x)
 {
@@ -579,6 +582,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)
@@ -711,9 +715,8 @@ int ht_get_split_count_index(unsigned long hash)
 static
 void ht_count_add(struct cds_lfht *ht, unsigned long size, unsigned long hash)
 {
-       unsigned long split_count;
+       unsigned long split_count, count;
        int index;
-       long count;
 
        if (caa_unlikely(!ht->split_count))
                return;
@@ -732,7 +735,7 @@ void ht_count_add(struct cds_lfht *ht, unsigned long size, unsigned long hash)
 
        if ((count >> CHAIN_LEN_RESIZE_THRESHOLD) < size)
                return;
-       dbg_printf("add set global %ld\n", count);
+       dbg_printf("add set global %lu\n", count);
        cds_lfht_resize_lazy_count(ht, size,
                count >> (CHAIN_LEN_TARGET - 1));
 }
@@ -740,9 +743,8 @@ void ht_count_add(struct cds_lfht *ht, unsigned long size, unsigned long hash)
 static
 void ht_count_del(struct cds_lfht *ht, unsigned long size, unsigned long hash)
 {
-       unsigned long split_count;
+       unsigned long split_count, count;
        int index;
-       long count;
 
        if (caa_unlikely(!ht->split_count))
                return;
@@ -826,7 +828,7 @@ struct cds_lfht_node *clear_flag(struct cds_lfht_node *node)
 }
 
 static
-int is_removed(struct cds_lfht_node *node)
+int is_removed(const struct cds_lfht_node *node)
 {
        return ((unsigned long) node) & REMOVED_FLAG;
 }
@@ -1247,8 +1249,8 @@ void partition_resize_helper(struct cds_lfht *ht, unsigned long i,
 {
        unsigned long partition_len, start = 0;
        struct partition_resize_work *work;
-       int thread, ret;
-       unsigned long nr_threads;
+       int ret;
+       unsigned long thread, nr_threads;
 
        assert(nr_cpus_mask != -1);
        if (nr_cpus_mask < 0 || len < 2 * MIN_PARTITION_PER_THREAD)
@@ -1260,7 +1262,7 @@ void partition_resize_helper(struct cds_lfht *ht, unsigned long i,
         * partition size, up to the number of CPUs in the system.
         */
        if (nr_cpus_mask > 0) {
-               nr_threads = min(nr_cpus_mask + 1,
+               nr_threads = min_t(unsigned long, nr_cpus_mask + 1,
                                 len >> MIN_PARTITION_PER_THREAD_ORDER);
        } else {
                nr_threads = 1;
@@ -1449,8 +1451,7 @@ static
 void fini_table(struct cds_lfht *ht,
                unsigned long first_order, unsigned long last_order)
 {
-       long i;
-       unsigned long free_by_rcu_order = 0;
+       unsigned long free_by_rcu_order = 0, i;
 
        dbg_printf("fini table: first_order %lu last_order %lu\n",
                   first_order, last_order);
@@ -1499,11 +1500,15 @@ void fini_table(struct cds_lfht *ht,
        }
 }
 
+/*
+ * Never called with size < 1.
+ */
 static
 void cds_lfht_create_bucket(struct cds_lfht *ht, unsigned long size)
 {
        struct cds_lfht_node *prev, *node;
        unsigned long order, len, i;
+       int bucket_order;
 
        cds_lfht_alloc_bucket_table(ht, 0);
 
@@ -1512,7 +1517,10 @@ void cds_lfht_create_bucket(struct cds_lfht *ht, unsigned long size)
        node->next = flag_bucket(get_end());
        node->reverse_hash = 0;
 
-       for (order = 1; order < cds_lfht_get_count_order_ulong(size) + 1; order++) {
+       bucket_order = cds_lfht_get_count_order_ulong(size);
+       assert(bucket_order >= 0);
+
+       for (order = 1; order < (unsigned long) bucket_order + 1; order++) {
                len = 1UL << (order - 1);
                cds_lfht_alloc_bucket_table(ht, order);
 
@@ -1543,6 +1551,33 @@ void cds_lfht_create_bucket(struct cds_lfht *ht, unsigned long size)
        }
 }
 
+#if (CAA_BITS_PER_LONG > 32)
+/*
+ * For 64-bit architectures, with max number of buckets small enough not to
+ * use the entire 64-bit memory mapping space (and allowing a fair number of
+ * hash table instances), use the mmap allocator, which is faster. Otherwise,
+ * fallback to the order allocator.
+ */
+static
+const struct cds_lfht_mm_type *get_mm_type(unsigned long max_nr_buckets)
+{
+       if (max_nr_buckets && max_nr_buckets <= (1ULL << 32))
+               return &cds_lfht_mm_mmap;
+       else
+               return &cds_lfht_mm_order;
+}
+#else
+/*
+ * For 32-bit architectures, use the order allocator.
+ */
+static
+const struct cds_lfht_mm_type *get_mm_type(
+               unsigned long max_nr_buckets __attribute__((unused)))
+{
+       return &cds_lfht_mm_order;
+}
+#endif
+
 struct cds_lfht *_cds_lfht_new(unsigned long init_size,
                        unsigned long min_nr_alloc_buckets,
                        unsigned long max_nr_buckets,
@@ -1565,26 +1600,8 @@ struct cds_lfht *_cds_lfht_new(unsigned long init_size,
        /*
         * Memory management plugin default.
         */
-       if (!mm) {
-               if (CAA_BITS_PER_LONG > 32
-                               && max_nr_buckets
-                               && max_nr_buckets <= (1ULL << 32)) {
-                       /*
-                        * For 64-bit architectures, with max number of
-                        * buckets small enough not to use the entire
-                        * 64-bit memory mapping space (and allowing a
-                        * fair number of hash table instances), use the
-                        * mmap allocator, which is faster than the
-                        * order allocator.
-                        */
-                       mm = &cds_lfht_mm_mmap;
-               } else {
-                       /*
-                        * The fallback is to use the order allocator.
-                        */
-                       mm = &cds_lfht_mm_order;
-               }
-       }
+       if (!mm)
+               mm = get_mm_type(max_nr_buckets);
 
        /* max_nr_buckets == 0 for order based mm means infinite */
        if (mm == &cds_lfht_mm_order && !max_nr_buckets)
@@ -1660,7 +1677,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;
@@ -1694,7 +1712,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;
 
@@ -1816,7 +1835,7 @@ int cds_lfht_del(struct cds_lfht *ht, struct cds_lfht_node *node)
        return ret;
 }
 
-int cds_lfht_is_node_deleted(struct cds_lfht_node *node)
+int cds_lfht_is_node_deleted(const struct cds_lfht_node *node)
 {
        return is_removed(CMM_LOAD_SHARED(node->next));
 }
@@ -2100,7 +2119,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;
@@ -2110,7 +2129,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;
@@ -2121,7 +2140,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;
@@ -2138,18 +2157,25 @@ static struct urcu_atfork cds_lfht_atfork = {
        .after_fork_child = cds_lfht_after_fork_child,
 };
 
-/* Block all signals to ensure we don't disturb the application. */
-static void cds_lfht_worker_init(struct urcu_workqueue *workqueue,
-               void *priv)
+/*
+ * Block all signals for the workqueue worker thread to ensure we don't
+ * 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 __attribute__((unused)),
+               void *priv __attribute__((unused)))
 {
        int ret;
        sigset_t mask;
 
-       /* Block signal for entire process, so only our thread processes it. */
        ret = sigfillset(&mask);
        if (ret)
                urcu_die(errno);
-       ret = pthread_sigmask(SIG_BLOCK, &mask, NULL);
+       ret = sigdelset(&mask, SIGRCU);
+       if (ret)
+               urcu_die(errno);
+       ret = pthread_sigmask(SIG_SETMASK, &mask, NULL);
        if (ret)
                urcu_die(ret);
 }
This page took 0.02671 seconds and 4 git commands to generate.