From: Francis Deslauriers Date: Wed, 1 Sep 2021 17:34:17 +0000 (-0400) Subject: Add `urcu_posix_assert()` as `assert()` replacement X-Git-Tag: v0.14.0~68 X-Git-Url: https://git.lttng.org/?p=urcu.git;a=commitdiff_plain;h=014775106c60f02818ca755b331f887030bd440f Add `urcu_posix_assert()` as `assert()` replacement This macro acts like the regular `assert()` macro unless NDEBUG is defined in which case it consumes the expression and becomes a no-op. This consumption trick (see `_urcu_use_expression()` macro) prevents the compiler from warning about unused variables even when assert() are removed by the NDEBUG define. This macro is also used for the existing `urcu_assert_debug()` macro. The implementation of `_urcu_use_expression()` is inspired by the Babeltrace 2 approach. See `BT_USE_EXPR()` macro and documentation in Babeltrace commit [1]: commit 1778c2a4134647150b199b2b57130817144446b0 Author: Philippe Proulx Date: Tue Apr 21 11:15:42 2020 -0400 lib: assign a unique ID to each pre/postcond. and report it on failure All assertion macros are moved to the new urcu/assert.h file. Link: https://github.com/efficios/babeltrace/commit/1778c2a4134647150b199b2b57130817144446b0 [1] Signed-off-by: Francis Deslauriers Signed-off-by: Mathieu Desnoyers Change-Id: If60ce2d3f45ea8f5ec1dbb92fb43f83fd9f8102b --- diff --git a/include/Makefile.am b/include/Makefile.am index 3f92cc3..b55bcf0 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -16,6 +16,7 @@ nobase_include_HEADERS = \ urcu/arch/sparc64.h \ urcu/arch/tile.h \ urcu/arch/x86.h \ + urcu/assert.h \ urcu/call-rcu.h \ urcu/cds.h \ urcu/compiler.h \ diff --git a/include/urcu/assert.h b/include/urcu/assert.h new file mode 100644 index 0000000..c22419f --- /dev/null +++ b/include/urcu/assert.h @@ -0,0 +1,52 @@ +#ifndef _URCU_ASSERT_H +#define _URCU_ASSERT_H + +/* + * urcu/assert.h + * + * Userspace RCU assertion facilities. + * + * Copyright (c) 2021 Francis Deslauriers + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + */ + +#include + +/* + * Force usage of an expression to prevent unused expression compiler warning. + */ +#define _urcu_use_expression(_expr) ((void) sizeof((void) (_expr), 0)) + +#ifdef NDEBUG +/* + * Vanilla assert() replacement. When NDEBUG is defined, the expression is + * consumed to prevent unused variable compile warnings. + */ +# define urcu_posix_assert(_cond) _urcu_use_expression(_cond) +#else +# include +# define urcu_posix_assert(_cond) assert(_cond) +#endif + +#if defined(DEBUG_RCU) || defined(CONFIG_RCU_DEBUG) + +/* + * Enables debugging/expensive assertions to be used in fast paths and only + * enabled on demand. When disabled, the expression is consumed to prevent + * unused variable compile warnings. + */ +# define urcu_assert_debug(_cond) urcu_posix_assert(_cond) +#else +# define urcu_assert_debug(_cond) _urcu_use_expression(_cond) +#endif + +#endif /* _URCU_ASSERT_H */ diff --git a/include/urcu/debug.h b/include/urcu/debug.h index 1920a7d..41727f3 100644 --- a/include/urcu/debug.h +++ b/include/urcu/debug.h @@ -19,15 +19,7 @@ * all copies or substantial portions of the Software. */ -#include - -#include - -#if defined(DEBUG_RCU) || defined(CONFIG_RCU_DEBUG) -# define urcu_assert_debug(...) assert(__VA_ARGS__) -#else -# define urcu_assert_debug(...) -#endif +#include /* * For backward compatibility reasons, this file must expose the urcu_assert() diff --git a/include/urcu/rculfqueue.h b/include/urcu/rculfqueue.h index 7e80789..2c06247 100644 --- a/include/urcu/rculfqueue.h +++ b/include/urcu/rculfqueue.h @@ -23,7 +23,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include #ifdef __cplusplus extern "C" { diff --git a/include/urcu/ref.h b/include/urcu/ref.h index e546da5..e7ab531 100644 --- a/include/urcu/ref.h +++ b/include/urcu/ref.h @@ -14,10 +14,10 @@ * published by the Free Software Foundation. */ -#include #include #include #include +#include #include struct urcu_ref { @@ -63,7 +63,7 @@ static inline void urcu_ref_put(struct urcu_ref *ref, void (*release)(struct urcu_ref *)) { long res = uatomic_sub_return(&ref->refcount, 1); - assert (res >= 0); + urcu_posix_assert(res >= 0); if (res == 0) release(ref); } diff --git a/include/urcu/static/lfstack.h b/include/urcu/static/lfstack.h index b8b544f..6c82b42 100644 --- a/include/urcu/static/lfstack.h +++ b/include/urcu/static/lfstack.h @@ -28,7 +28,7 @@ #include #include -#include +#include #include #include @@ -76,7 +76,7 @@ void _cds_lfs_init(struct cds_lfs_stack *s) s->head = NULL; ret = pthread_mutex_init(&s->lock, NULL); - assert(!ret); + urcu_posix_assert(!ret); } /* @@ -87,7 +87,7 @@ static inline void _cds_lfs_destroy(struct cds_lfs_stack *s) { int ret = pthread_mutex_destroy(&s->lock); - assert(!ret); + urcu_posix_assert(!ret); } /* @@ -267,7 +267,7 @@ static inline void _cds_lfs_pop_lock(struct cds_lfs_stack *s) int ret; ret = pthread_mutex_lock(&s->lock); - assert(!ret); + urcu_posix_assert(!ret); } /* @@ -278,7 +278,7 @@ static inline void _cds_lfs_pop_unlock(struct cds_lfs_stack *s) int ret; ret = pthread_mutex_unlock(&s->lock); - assert(!ret); + urcu_posix_assert(!ret); } /* diff --git a/include/urcu/static/rculfqueue.h b/include/urcu/static/rculfqueue.h index af73c6f..a8e1091 100644 --- a/include/urcu/static/rculfqueue.h +++ b/include/urcu/static/rculfqueue.h @@ -27,9 +27,9 @@ */ #include +#include #include #include -#include #include #ifdef __cplusplus @@ -67,7 +67,7 @@ struct cds_lfq_node_rcu *make_dummy(struct cds_lfq_queue_rcu *q, struct cds_lfq_node_rcu_dummy *dummy; dummy = malloc(sizeof(struct cds_lfq_node_rcu_dummy)); - assert(dummy); + urcu_posix_assert(dummy); dummy->parent.next = next; dummy->parent.dummy = 1; dummy->q = q; @@ -87,7 +87,7 @@ void rcu_free_dummy(struct cds_lfq_node_rcu *node) { struct cds_lfq_node_rcu_dummy *dummy; - assert(node->dummy); + urcu_posix_assert(node->dummy); dummy = caa_container_of(node, struct cds_lfq_node_rcu_dummy, parent); dummy->q->queue_call_rcu(&dummy->head, free_dummy_cb); } @@ -97,7 +97,7 @@ void free_dummy(struct cds_lfq_node_rcu *node) { struct cds_lfq_node_rcu_dummy *dummy; - assert(node->dummy); + urcu_posix_assert(node->dummy); dummy = caa_container_of(node, struct cds_lfq_node_rcu_dummy, parent); free(dummy); } diff --git a/include/urcu/static/urcu-bp.h b/include/urcu/static/urcu-bp.h index 7f5d873..8ba3830 100644 --- a/include/urcu/static/urcu-bp.h +++ b/include/urcu/static/urcu-bp.h @@ -33,6 +33,7 @@ #include #include +#include #include #include #include @@ -40,7 +41,6 @@ #include #include #include -#include /* * This code section can only be included in LGPL 2.1 compatible source code. diff --git a/include/urcu/static/urcu-common.h b/include/urcu/static/urcu-common.h index 28d3160..60ea8b8 100644 --- a/include/urcu/static/urcu-common.h +++ b/include/urcu/static/urcu-common.h @@ -42,7 +42,6 @@ #include #include #include -#include #ifdef __cplusplus extern "C" { diff --git a/include/urcu/static/urcu-mb.h b/include/urcu/static/urcu-mb.h index 20e604d..b97e42a 100644 --- a/include/urcu/static/urcu-mb.h +++ b/include/urcu/static/urcu-mb.h @@ -34,6 +34,7 @@ #include #include +#include #include #include #include @@ -42,7 +43,6 @@ #include #include #include -#include #include #ifdef __cplusplus diff --git a/include/urcu/static/urcu-memb.h b/include/urcu/static/urcu-memb.h index 65a985b..c8d102f 100644 --- a/include/urcu/static/urcu-memb.h +++ b/include/urcu/static/urcu-memb.h @@ -34,6 +34,7 @@ #include #include +#include #include #include #include @@ -42,7 +43,6 @@ #include #include #include -#include #include #ifdef __cplusplus diff --git a/include/urcu/static/urcu-qsbr.h b/include/urcu/static/urcu-qsbr.h index 5eca3e2..b878877 100644 --- a/include/urcu/static/urcu-qsbr.h +++ b/include/urcu/static/urcu-qsbr.h @@ -35,6 +35,7 @@ #include #include +#include #include #include #include @@ -42,7 +43,6 @@ #include #include #include -#include #include #ifdef __cplusplus diff --git a/include/urcu/static/urcu-signal.h b/include/urcu/static/urcu-signal.h index 56730e1..c7577d3 100644 --- a/include/urcu/static/urcu-signal.h +++ b/include/urcu/static/urcu-signal.h @@ -34,6 +34,7 @@ #include #include +#include #include #include #include @@ -42,7 +43,6 @@ #include #include #include -#include #include #include diff --git a/include/urcu/static/wfcqueue.h b/include/urcu/static/wfcqueue.h index 5e54cbe..478e859 100644 --- a/include/urcu/static/wfcqueue.h +++ b/include/urcu/static/wfcqueue.h @@ -28,9 +28,9 @@ */ #include -#include #include #include +#include #include #include @@ -104,7 +104,7 @@ static inline void _cds_wfcq_init(struct cds_wfcq_head *head, _cds_wfcq_node_init(&head->node); tail->p = &head->node; ret = pthread_mutex_init(&head->lock, NULL); - assert(!ret); + urcu_posix_assert(!ret); } /* @@ -115,7 +115,7 @@ static inline void _cds_wfcq_destroy(struct cds_wfcq_head *head, struct cds_wfcq_tail *tail __attribute__((unused))) { int ret = pthread_mutex_destroy(&head->lock); - assert(!ret); + urcu_posix_assert(!ret); } /* @@ -163,7 +163,7 @@ static inline void _cds_wfcq_dequeue_lock(struct cds_wfcq_head *head, int ret; ret = pthread_mutex_lock(&head->lock); - assert(!ret); + urcu_posix_assert(!ret); } static inline void _cds_wfcq_dequeue_unlock(struct cds_wfcq_head *head, @@ -172,7 +172,7 @@ static inline void _cds_wfcq_dequeue_unlock(struct cds_wfcq_head *head, int ret; ret = pthread_mutex_unlock(&head->lock); - assert(!ret); + urcu_posix_assert(!ret); } static inline bool ___cds_wfcq_append(cds_wfcq_head_ptr_t u_head, diff --git a/include/urcu/static/wfqueue.h b/include/urcu/static/wfqueue.h index df9f62f..d04f66f 100644 --- a/include/urcu/static/wfqueue.h +++ b/include/urcu/static/wfqueue.h @@ -27,8 +27,8 @@ */ #include -#include #include +#include #include #include @@ -62,13 +62,13 @@ static inline void _cds_wfq_init(struct cds_wfq_queue *q) q->head = &q->dummy; q->tail = &q->dummy.next; ret = pthread_mutex_init(&q->lock, NULL); - assert(!ret); + urcu_posix_assert(!ret); } static inline void _cds_wfq_destroy(struct cds_wfq_queue *q) { int ret = pthread_mutex_destroy(&q->lock); - assert(!ret); + urcu_posix_assert(!ret); } static inline void _cds_wfq_enqueue(struct cds_wfq_queue *q, @@ -157,10 +157,10 @@ _cds_wfq_dequeue_blocking(struct cds_wfq_queue *q) int ret; ret = pthread_mutex_lock(&q->lock); - assert(!ret); + urcu_posix_assert(!ret); retnode = ___cds_wfq_dequeue_blocking(q); ret = pthread_mutex_unlock(&q->lock); - assert(!ret); + urcu_posix_assert(!ret); return retnode; } diff --git a/include/urcu/static/wfstack.h b/include/urcu/static/wfstack.h index e96c887..bd7ba68 100644 --- a/include/urcu/static/wfstack.h +++ b/include/urcu/static/wfstack.h @@ -27,9 +27,9 @@ */ #include -#include #include #include +#include #include #include @@ -96,7 +96,7 @@ void _cds_wfs_init(struct cds_wfs_stack *s) s->head = CDS_WFS_END; ret = pthread_mutex_init(&s->lock, NULL); - assert(!ret); + urcu_posix_assert(!ret); } /* @@ -107,7 +107,7 @@ static inline void _cds_wfs_destroy(struct cds_wfs_stack *s) { int ret = pthread_mutex_destroy(&s->lock); - assert(!ret); + urcu_posix_assert(!ret); } static inline bool ___cds_wfs_end(void *node) @@ -142,7 +142,7 @@ int _cds_wfs_push(cds_wfs_stack_ptr_t u_stack, struct cds_wfs_node *node) struct __cds_wfs_stack *s = u_stack._s; struct cds_wfs_head *old_head, *new_head; - assert(node->next == NULL); + urcu_posix_assert(node->next == NULL); new_head = caa_container_of(node, struct cds_wfs_head, node); /* * uatomic_xchg() implicit memory barrier orders earlier stores @@ -323,7 +323,7 @@ static inline void _cds_wfs_pop_lock(struct cds_wfs_stack *s) int ret; ret = pthread_mutex_lock(&s->lock); - assert(!ret); + urcu_posix_assert(!ret); } /* @@ -334,7 +334,7 @@ static inline void _cds_wfs_pop_unlock(struct cds_wfs_stack *s) int ret; ret = pthread_mutex_unlock(&s->lock); - assert(!ret); + urcu_posix_assert(!ret); } /* diff --git a/include/urcu/wfcqueue.h b/include/urcu/wfcqueue.h index 6c6ebba..407c0db 100644 --- a/include/urcu/wfcqueue.h +++ b/include/urcu/wfcqueue.h @@ -25,7 +25,6 @@ */ #include -#include #include #include #include diff --git a/include/urcu/wfqueue.h b/include/urcu/wfqueue.h index 2ba8624..214d3bf 100644 --- a/include/urcu/wfqueue.h +++ b/include/urcu/wfqueue.h @@ -24,7 +24,6 @@ */ #include -#include #include #ifdef __cplusplus diff --git a/include/urcu/wfstack.h b/include/urcu/wfstack.h index 9d69305..1058fba 100644 --- a/include/urcu/wfstack.h +++ b/include/urcu/wfstack.h @@ -24,7 +24,6 @@ */ #include -#include #include #include diff --git a/src/compat_arch.c b/src/compat_arch.c index 73f7d2d..e1651d3 100644 --- a/src/compat_arch.c +++ b/src/compat_arch.c @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include /* @@ -95,11 +95,11 @@ static void mutex_lock_signal_save(pthread_mutex_t *mutex, sigset_t *oldmask) /* Disable signals */ ret = sigfillset(&newmask); - assert(!ret); + urcu_posix_assert(!ret); ret = pthread_sigmask(SIG_BLOCK, &newmask, oldmask); - assert(!ret); + urcu_posix_assert(!ret); ret = pthread_mutex_lock(&__urcu_x86_compat_mutex); - assert(!ret); + urcu_posix_assert(!ret); } static void mutex_lock_signal_restore(pthread_mutex_t *mutex, sigset_t *oldmask) @@ -107,9 +107,9 @@ static void mutex_lock_signal_restore(pthread_mutex_t *mutex, sigset_t *oldmask) int ret; ret = pthread_mutex_unlock(&__urcu_x86_compat_mutex); - assert(!ret); + urcu_posix_assert(!ret); ret = pthread_sigmask(SIG_SETMASK, oldmask, NULL); - assert(!ret); + urcu_posix_assert(!ret); } unsigned long _compat_uatomic_set(void *addr, unsigned long _new, int len) diff --git a/src/compat_futex.c b/src/compat_futex.c index 9e918fe..9281138 100644 --- a/src/compat_futex.c +++ b/src/compat_futex.c @@ -23,12 +23,12 @@ #include #include #include -#include #include #include #include #include +#include #include #include @@ -60,9 +60,9 @@ int compat_futex_noasync(int32_t *uaddr, int op, int32_t val, * Check if NULL. Don't let users expect that they are taken into * account. */ - assert(!timeout); - assert(!uaddr2); - assert(!val3); + urcu_posix_assert(!timeout); + urcu_posix_assert(!uaddr2); + urcu_posix_assert(!val3); /* * memory barriers to serialize with the previous uaddr modification. @@ -124,9 +124,9 @@ int compat_futex_async(int32_t *uaddr, int op, int32_t val, * Check if NULL. Don't let users expect that they are taken into * account. */ - assert(!timeout); - assert(!uaddr2); - assert(!val3); + urcu_posix_assert(!timeout); + urcu_posix_assert(!uaddr2); + urcu_posix_assert(!val3); /* * Ensure previous memory operations on uaddr have completed. diff --git a/src/rculfhash-internal.h b/src/rculfhash-internal.h index d29a923..e17210b 100644 --- a/src/rculfhash-internal.h +++ b/src/rculfhash-internal.h @@ -24,10 +24,10 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include #include #include #include -#include #ifdef DEBUG #define dbg_printf(fmt, args...) printf("[debug rculfhash] " fmt, ## args) @@ -170,7 +170,7 @@ struct cds_lfht *__default_alloc_cds_lfht( struct cds_lfht *ht; ht = calloc(1, cds_lfht_size); - assert(ht); + urcu_posix_assert(ht); ht->mm = mm; ht->bucket_at = mm->bucket_at; diff --git a/src/rculfhash-mm-chunk.c b/src/rculfhash-mm-chunk.c index a7a9b76..9273ac9 100644 --- a/src/rculfhash-mm-chunk.c +++ b/src/rculfhash-mm-chunk.c @@ -21,6 +21,7 @@ */ #include +#include #include static @@ -29,14 +30,14 @@ void cds_lfht_alloc_bucket_table(struct cds_lfht *ht, unsigned long order) if (order == 0) { ht->tbl_chunk[0] = calloc(ht->min_nr_alloc_buckets, sizeof(struct cds_lfht_node)); - assert(ht->tbl_chunk[0]); + urcu_posix_assert(ht->tbl_chunk[0]); } else if (order > ht->min_alloc_buckets_order) { unsigned long i, len = 1UL << (order - 1 - ht->min_alloc_buckets_order); for (i = len; i < 2 * len; i++) { ht->tbl_chunk[i] = calloc(ht->min_nr_alloc_buckets, sizeof(struct cds_lfht_node)); - assert(ht->tbl_chunk[i]); + urcu_posix_assert(ht->tbl_chunk[i]); } } /* Nothing to do for 0 < order && order <= ht->min_alloc_buckets_order */ diff --git a/src/rculfhash-mm-mmap.c b/src/rculfhash-mm-mmap.c index 72333a8..4bce972 100644 --- a/src/rculfhash-mm-mmap.c +++ b/src/rculfhash-mm-mmap.c @@ -25,6 +25,7 @@ #include #include #include +#include #include "rculfhash-internal.h" #ifndef MAP_ANONYMOUS @@ -133,7 +134,7 @@ void cds_lfht_alloc_bucket_table(struct cds_lfht *ht, unsigned long order) /* small table */ ht->tbl_mmap = calloc(ht->max_nr_buckets, sizeof(*ht->tbl_mmap)); - assert(ht->tbl_mmap); + urcu_posix_assert(ht->tbl_mmap); return; } /* large table */ @@ -145,7 +146,7 @@ void cds_lfht_alloc_bucket_table(struct cds_lfht *ht, unsigned long order) /* large table */ unsigned long len = 1UL << (order - 1); - assert(ht->min_nr_alloc_buckets < ht->max_nr_buckets); + urcu_posix_assert(ht->min_nr_alloc_buckets < ht->max_nr_buckets); memory_populate(ht->tbl_mmap + len, len * sizeof(*ht->tbl_mmap)); } @@ -173,7 +174,7 @@ void cds_lfht_free_bucket_table(struct cds_lfht *ht, unsigned long order) /* large table */ unsigned long len = 1UL << (order - 1); - assert(ht->min_nr_alloc_buckets < ht->max_nr_buckets); + urcu_posix_assert(ht->min_nr_alloc_buckets < ht->max_nr_buckets); memory_discard(ht->tbl_mmap + len, len * sizeof(*ht->tbl_mmap)); } /* Nothing to do for 0 < order && order <= ht->min_alloc_buckets_order */ diff --git a/src/rculfhash-mm-order.c b/src/rculfhash-mm-order.c index 20f3edd..a182a83 100644 --- a/src/rculfhash-mm-order.c +++ b/src/rculfhash-mm-order.c @@ -21,6 +21,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include #include static @@ -29,11 +30,11 @@ void cds_lfht_alloc_bucket_table(struct cds_lfht *ht, unsigned long order) if (order == 0) { ht->tbl_order[0] = calloc(ht->min_nr_alloc_buckets, sizeof(struct cds_lfht_node)); - assert(ht->tbl_order[0]); + urcu_posix_assert(ht->tbl_order[0]); } else if (order > ht->min_alloc_buckets_order) { ht->tbl_order[order] = calloc(1UL << (order -1), sizeof(struct cds_lfht_node)); - assert(ht->tbl_order[order]); + urcu_posix_assert(ht->tbl_order[order]); } /* Nothing to do for 0 < order && order <= ht->min_alloc_buckets_order */ } diff --git a/src/rculfhash.c b/src/rculfhash.c index 9106a74..04fd499 100644 --- a/src/rculfhash.c +++ b/src/rculfhash.c @@ -258,7 +258,6 @@ #define _LGPL_SOURCE #include #include -#include #include #include #include @@ -266,6 +265,7 @@ #include #include "compat-getcpu.h" +#include #include #include #include @@ -390,7 +390,7 @@ void cds_lfht_iter_debug_set_ht(struct cds_lfht *ht, struct cds_lfht_iter *iter) iter->lfht = ht; } -#define cds_lfht_iter_debug_assert(...) assert(__VA_ARGS__) +#define cds_lfht_iter_debug_assert(...) urcu_posix_assert(__VA_ARGS__) #else @@ -682,12 +682,12 @@ void alloc_split_items_count(struct cds_lfht *ht) cds_lfht_get_count_order_ulong(split_count_mask + 1); } - assert(split_count_mask >= 0); + urcu_posix_assert(split_count_mask >= 0); if (ht->flags & CDS_LFHT_ACCOUNTING) { ht->split_count = calloc(split_count_mask + 1, sizeof(struct ht_items_count)); - assert(ht->split_count); + urcu_posix_assert(ht->split_count); } else { ht->split_count = NULL; } @@ -704,7 +704,7 @@ int ht_get_split_count_index(unsigned long hash) { int cpu; - assert(split_count_mask >= 0); + urcu_posix_assert(split_count_mask >= 0); cpu = urcu_sched_getcpu(); if (caa_unlikely(cpu < 0)) return hash & split_count_mask; @@ -917,7 +917,7 @@ static inline struct cds_lfht_node *lookup_bucket(struct cds_lfht *ht, unsigned long size, unsigned long hash) { - assert(size > 0); + urcu_posix_assert(size > 0); return bucket_at(ht, hash & (size - 1)); } @@ -929,26 +929,26 @@ void _cds_lfht_gc_bucket(struct cds_lfht_node *bucket, struct cds_lfht_node *nod { struct cds_lfht_node *iter_prev, *iter, *next, *new_next; - assert(!is_bucket(bucket)); - assert(!is_removed(bucket)); - assert(!is_removal_owner(bucket)); - assert(!is_bucket(node)); - assert(!is_removed(node)); - assert(!is_removal_owner(node)); + urcu_posix_assert(!is_bucket(bucket)); + urcu_posix_assert(!is_removed(bucket)); + urcu_posix_assert(!is_removal_owner(bucket)); + urcu_posix_assert(!is_bucket(node)); + urcu_posix_assert(!is_removed(node)); + urcu_posix_assert(!is_removal_owner(node)); for (;;) { iter_prev = bucket; /* We can always skip the bucket node initially */ iter = rcu_dereference(iter_prev->next); - assert(!is_removed(iter)); - assert(!is_removal_owner(iter)); - assert(iter_prev->reverse_hash <= node->reverse_hash); + urcu_posix_assert(!is_removed(iter)); + urcu_posix_assert(!is_removal_owner(iter)); + urcu_posix_assert(iter_prev->reverse_hash <= node->reverse_hash); /* * We should never be called with bucket (start of chain) * and logically removed node (end of path compression * marker) being the actual same node. This would be a * bug in the algorithm implementation. */ - assert(bucket != node); + urcu_posix_assert(bucket != node); for (;;) { if (caa_unlikely(is_end(iter))) return; @@ -960,8 +960,8 @@ void _cds_lfht_gc_bucket(struct cds_lfht_node *bucket, struct cds_lfht_node *nod iter_prev = clear_flag(iter); iter = next; } - assert(!is_removed(iter)); - assert(!is_removal_owner(iter)); + urcu_posix_assert(!is_removed(iter)); + urcu_posix_assert(!is_removal_owner(iter)); if (is_bucket(iter)) new_next = flag_bucket(clear_flag(next)); else @@ -981,13 +981,13 @@ int _cds_lfht_replace(struct cds_lfht *ht, unsigned long size, if (!old_node) /* Return -ENOENT if asked to replace NULL node */ return -ENOENT; - assert(!is_removed(old_node)); - assert(!is_removal_owner(old_node)); - assert(!is_bucket(old_node)); - assert(!is_removed(new_node)); - assert(!is_removal_owner(new_node)); - assert(!is_bucket(new_node)); - assert(new_node != old_node); + urcu_posix_assert(!is_removed(old_node)); + urcu_posix_assert(!is_removal_owner(old_node)); + urcu_posix_assert(!is_bucket(old_node)); + urcu_posix_assert(!is_removed(new_node)); + urcu_posix_assert(!is_removal_owner(new_node)); + urcu_posix_assert(!is_bucket(new_node)); + urcu_posix_assert(new_node != old_node); for (;;) { /* Insert after node to be replaced */ if (is_removed(old_next)) { @@ -997,14 +997,14 @@ int _cds_lfht_replace(struct cds_lfht *ht, unsigned long size, */ return -ENOENT; } - assert(old_next == clear_flag(old_next)); - assert(new_node != old_next); + urcu_posix_assert(old_next == clear_flag(old_next)); + urcu_posix_assert(new_node != old_next); /* * REMOVAL_OWNER flag is _NEVER_ set before the REMOVED * flag. It is either set atomically at the same time * (replace) or after (del). */ - assert(!is_removal_owner(old_next)); + urcu_posix_assert(!is_removal_owner(old_next)); new_node->next = old_next; /* * Here is the whole trick for lock-free replace: we add @@ -1036,7 +1036,7 @@ int _cds_lfht_replace(struct cds_lfht *ht, unsigned long size, bucket = lookup_bucket(ht, size, bit_reverse_ulong(old_node->reverse_hash)); _cds_lfht_gc_bucket(bucket, new_node); - assert(is_removed(CMM_LOAD_SHARED(old_node->next))); + urcu_posix_assert(is_removed(CMM_LOAD_SHARED(old_node->next))); return 0; } @@ -1058,9 +1058,9 @@ void _cds_lfht_add(struct cds_lfht *ht, *return_node; struct cds_lfht_node *bucket; - assert(!is_bucket(node)); - assert(!is_removed(node)); - assert(!is_removal_owner(node)); + urcu_posix_assert(!is_bucket(node)); + urcu_posix_assert(!is_removed(node)); + urcu_posix_assert(!is_removal_owner(node)); bucket = lookup_bucket(ht, size, hash); for (;;) { uint32_t chain_len = 0; @@ -1072,7 +1072,7 @@ void _cds_lfht_add(struct cds_lfht *ht, iter_prev = bucket; /* We can always skip the bucket node initially */ iter = rcu_dereference(iter_prev->next); - assert(iter_prev->reverse_hash <= node->reverse_hash); + urcu_posix_assert(iter_prev->reverse_hash <= node->reverse_hash); for (;;) { if (caa_unlikely(is_end(iter))) goto insert; @@ -1125,12 +1125,12 @@ void _cds_lfht_add(struct cds_lfht *ht, } insert: - assert(node != clear_flag(iter)); - assert(!is_removed(iter_prev)); - assert(!is_removal_owner(iter_prev)); - assert(!is_removed(iter)); - assert(!is_removal_owner(iter)); - assert(iter_prev != node); + urcu_posix_assert(node != clear_flag(iter)); + urcu_posix_assert(!is_removed(iter_prev)); + urcu_posix_assert(!is_removal_owner(iter_prev)); + urcu_posix_assert(!is_removed(iter)); + urcu_posix_assert(!is_removal_owner(iter)); + urcu_posix_assert(iter_prev != node); if (!bucket_flag) node->next = clear_flag(iter); else @@ -1148,8 +1148,8 @@ void _cds_lfht_add(struct cds_lfht *ht, } gc_node: - assert(!is_removed(iter)); - assert(!is_removal_owner(iter)); + urcu_posix_assert(!is_removed(iter)); + urcu_posix_assert(!is_removal_owner(iter)); if (is_bucket(iter)) new_next = flag_bucket(clear_flag(next)); else @@ -1174,9 +1174,9 @@ int _cds_lfht_del(struct cds_lfht *ht, unsigned long size, return -ENOENT; /* logically delete the node */ - assert(!is_bucket(node)); - assert(!is_removed(node)); - assert(!is_removal_owner(node)); + urcu_posix_assert(!is_bucket(node)); + urcu_posix_assert(!is_removed(node)); + urcu_posix_assert(!is_removal_owner(node)); /* * We are first checking if the node had previously been @@ -1187,7 +1187,7 @@ int _cds_lfht_del(struct cds_lfht *ht, unsigned long size, next = CMM_LOAD_SHARED(node->next); /* next is not dereferenced */ if (caa_unlikely(is_removed(next))) return -ENOENT; - assert(!is_bucket(next)); + urcu_posix_assert(!is_bucket(next)); /* * The del operation semantic guarantees a full memory barrier * before the uatomic_or atomic commit of the deletion flag. @@ -1210,7 +1210,7 @@ int _cds_lfht_del(struct cds_lfht *ht, unsigned long size, bucket = lookup_bucket(ht, size, bit_reverse_ulong(node->reverse_hash)); _cds_lfht_gc_bucket(bucket, node); - assert(is_removed(CMM_LOAD_SHARED(node->next))); + urcu_posix_assert(is_removed(CMM_LOAD_SHARED(node->next))); /* * Last phase: atomically exchange node->next with a version * having "REMOVAL_OWNER_FLAG" set. If the returned node->next @@ -1252,7 +1252,7 @@ void partition_resize_helper(struct cds_lfht *ht, unsigned long i, int ret; unsigned long thread, nr_threads; - assert(nr_cpus_mask != -1); + urcu_posix_assert(nr_cpus_mask != -1); if (nr_cpus_mask < 0 || len < 2 * MIN_PARTITION_PER_THREAD) goto fallback; @@ -1292,11 +1292,11 @@ void partition_resize_helper(struct cds_lfht *ht, unsigned long i, nr_threads = thread; break; } - assert(!ret); + urcu_posix_assert(!ret); } for (thread = 0; thread < nr_threads; thread++) { ret = pthread_join(work[thread].thread_id, NULL); - assert(!ret); + urcu_posix_assert(!ret); } free(work); @@ -1328,12 +1328,12 @@ void init_table_populate_partition(struct cds_lfht *ht, unsigned long i, { unsigned long j, size = 1UL << (i - 1); - assert(i > MIN_TABLE_ORDER); + urcu_posix_assert(i > MIN_TABLE_ORDER); ht->flavor->read_lock(); for (j = size + start; j < size + start + len; j++) { struct cds_lfht_node *new_node = bucket_at(ht, j); - assert(j >= size && j < (size << 1)); + urcu_posix_assert(j >= size && j < (size << 1)); dbg_printf("init populate: order %lu index %lu hash %lu\n", i, j, j); new_node->reverse_hash = bit_reverse_ulong(j); @@ -1357,7 +1357,7 @@ void init_table(struct cds_lfht *ht, dbg_printf("init table: first_order %lu last_order %lu\n", first_order, last_order); - assert(first_order > MIN_TABLE_ORDER); + urcu_posix_assert(first_order > MIN_TABLE_ORDER); for (i = first_order; i <= last_order; i++) { unsigned long len; @@ -1420,13 +1420,13 @@ void remove_table_partition(struct cds_lfht *ht, unsigned long i, { unsigned long j, size = 1UL << (i - 1); - assert(i > MIN_TABLE_ORDER); + urcu_posix_assert(i > MIN_TABLE_ORDER); ht->flavor->read_lock(); for (j = size + start; j < size + start + len; j++) { struct cds_lfht_node *fini_bucket = bucket_at(ht, j); struct cds_lfht_node *parent_bucket = bucket_at(ht, j - size); - assert(j >= size && j < (size << 1)); + urcu_posix_assert(j >= size && j < (size << 1)); dbg_printf("remove entry: order %lu index %lu hash %lu\n", i, j, j); /* Set the REMOVED_FLAG to freeze the ->next for gc */ @@ -1455,7 +1455,7 @@ void fini_table(struct cds_lfht *ht, dbg_printf("fini table: first_order %lu last_order %lu\n", first_order, last_order); - assert(first_order > MIN_TABLE_ORDER); + urcu_posix_assert(first_order > MIN_TABLE_ORDER); for (i = last_order; i >= first_order; i--) { unsigned long len; @@ -1518,7 +1518,7 @@ void cds_lfht_create_bucket(struct cds_lfht *ht, unsigned long size) node->reverse_hash = 0; bucket_order = cds_lfht_get_count_order_ulong(size); - assert(bucket_order >= 0); + urcu_posix_assert(bucket_order >= 0); for (order = 1; order < (unsigned long) bucket_order + 1; order++) { len = 1UL << (order - 1); @@ -1544,7 +1544,7 @@ void cds_lfht_create_bucket(struct cds_lfht *ht, unsigned long size) node->reverse_hash = bit_reverse_ulong(len + i); /* insert after prev */ - assert(is_bucket(prev->next)); + urcu_posix_assert(is_bucket(prev->next)); node->next = prev->next; prev->next = flag_bucket(node); } @@ -1620,9 +1620,9 @@ struct cds_lfht *_cds_lfht_new(unsigned long init_size, init_size = min(init_size, max_nr_buckets); ht = mm->alloc_cds_lfht(min_nr_alloc_buckets, max_nr_buckets); - assert(ht); - assert(ht->mm == mm); - assert(ht->bucket_at == mm->bucket_at); + urcu_posix_assert(ht); + urcu_posix_assert(ht->mm == mm); + urcu_posix_assert(ht->bucket_at == mm->bucket_at); ht->flags = flags; ht->flavor = flavor; @@ -1663,7 +1663,7 @@ void cds_lfht_lookup(struct cds_lfht *ht, unsigned long hash, break; } next = rcu_dereference(node->next); - assert(node == clear_flag(node)); + urcu_posix_assert(node == clear_flag(node)); if (caa_likely(!is_removed(next)) && !is_bucket(next) && node->reverse_hash == reverse_hash @@ -1672,7 +1672,7 @@ void cds_lfht_lookup(struct cds_lfht *ht, unsigned long hash, } node = clear_flag(next); } - assert(!node || !is_bucket(CMM_LOAD_SHARED(node->next))); + urcu_posix_assert(!node || !is_bucket(CMM_LOAD_SHARED(node->next))); iter->node = node; iter->next = next; } @@ -1707,7 +1707,7 @@ void cds_lfht_next_duplicate(struct cds_lfht *ht __attribute__((unused)), } node = clear_flag(next); } - assert(!node || !is_bucket(CMM_LOAD_SHARED(node->next))); + urcu_posix_assert(!node || !is_bucket(CMM_LOAD_SHARED(node->next))); iter->node = node; iter->next = next; } @@ -1731,7 +1731,7 @@ void cds_lfht_next(struct cds_lfht *ht __attribute__((unused)), } node = clear_flag(next); } - assert(!node || !is_bucket(CMM_LOAD_SHARED(node->next))); + urcu_posix_assert(!node || !is_bucket(CMM_LOAD_SHARED(node->next))); iter->node = node; iter->next = next; } @@ -1852,8 +1852,8 @@ int cds_lfht_delete_bucket(struct cds_lfht *ht) node = clear_flag(node)->next; if (!is_bucket(node)) return -EPERM; - assert(!is_removed(node)); - assert(!is_removal_owner(node)); + urcu_posix_assert(!is_removed(node)); + urcu_posix_assert(!is_removal_owner(node)); } while (!is_end(node)); /* * size accessed without rcu_dereference because hash table is @@ -1865,7 +1865,7 @@ int cds_lfht_delete_bucket(struct cds_lfht *ht) node = bucket_at(ht, i); dbg_printf("delete bucket: index %lu expected hash %lu hash %lu\n", i, i, bit_reverse_ulong(node->reverse_hash)); - assert(is_bucket(node->next)); + urcu_posix_assert(is_bucket(node->next)); } for (order = cds_lfht_get_count_order_ulong(size); (long)order >= 0; order--) @@ -1962,7 +1962,7 @@ void _do_cds_lfht_grow(struct cds_lfht *ht, new_order = cds_lfht_get_count_order_ulong(new_size); dbg_printf("resize from %lu (order %lu) to %lu (order %lu) buckets\n", old_size, old_order, new_size, new_order); - assert(new_size > old_size); + urcu_posix_assert(new_size > old_size); init_table(ht, old_order + 1, new_order); } @@ -1978,7 +1978,7 @@ void _do_cds_lfht_shrink(struct cds_lfht *ht, new_order = cds_lfht_get_count_order_ulong(new_size); dbg_printf("resize from %lu (order %lu) to %lu (order %lu) buckets\n", old_size, old_order, new_size, new_order); - assert(new_size < old_size); + urcu_posix_assert(new_size < old_size); /* Remove and unlink all bucket nodes to remove. */ fini_table(ht, new_order + 1, old_order); diff --git a/src/urcu-bp.c b/src/urcu-bp.c index 83df139..a097d7f 100644 --- a/src/urcu-bp.c +++ b/src/urcu-bp.c @@ -28,7 +28,6 @@ #include #include #include -#include #include #include #include @@ -37,6 +36,7 @@ #include #include +#include #include #include #include @@ -80,7 +80,7 @@ void *mremap_wrapper(void *old_address __attribute__((unused)), size_t new_size __attribute__((unused)), int flags) { - assert(!(flags & MREMAP_MAYMOVE)); + urcu_posix_assert(!(flags & MREMAP_MAYMOVE)); return MAP_FAILED; } @@ -277,9 +277,9 @@ void urcu_bp_synchronize_rcu(void) int ret; ret = sigfillset(&newmask); - assert(!ret); + urcu_posix_assert(!ret); ret = pthread_sigmask(SIG_BLOCK, &newmask, &oldmask); - assert(!ret); + urcu_posix_assert(!ret); mutex_lock(&rcu_gp_lock); @@ -345,7 +345,7 @@ out: mutex_unlock(&rcu_registry_lock); mutex_unlock(&rcu_gp_lock); ret = pthread_sigmask(SIG_SETMASK, &oldmask, NULL); - assert(!ret); + urcu_posix_assert(!ret); } /* @@ -383,7 +383,7 @@ void expand_arena(struct registry_arena *arena) /* No chunk. */ if (cds_list_empty(&arena->chunk_list)) { - assert(ARENA_INIT_ALLOC >= + urcu_posix_assert(ARENA_INIT_ALLOC >= sizeof(struct registry_chunk) + sizeof(struct rcu_reader)); new_chunk_len = ARENA_INIT_ALLOC; @@ -413,7 +413,7 @@ void expand_arena(struct registry_arena *arena) new_chunk_len, 0); if (new_chunk != MAP_FAILED) { /* Should not have moved. */ - assert(new_chunk == last_chunk); + urcu_posix_assert(new_chunk == last_chunk); memset((char *) last_chunk + old_chunk_len, 0, new_chunk_len - old_chunk_len); last_chunk->data_len = @@ -484,7 +484,7 @@ void add_thread(void) /* Add to registry */ rcu_reader_reg->tid = pthread_self(); - assert(rcu_reader_reg->ctr == 0); + urcu_posix_assert(rcu_reader_reg->ctr == 0); cds_list_add(&rcu_reader_reg->node, ®istry); /* * Reader threads are pointing to the reader registry. This is @@ -685,9 +685,9 @@ void urcu_bp_before_fork(void) int ret; ret = sigfillset(&newmask); - assert(!ret); + urcu_posix_assert(!ret); ret = pthread_sigmask(SIG_BLOCK, &newmask, &oldmask); - assert(!ret); + urcu_posix_assert(!ret); mutex_lock(&rcu_gp_lock); mutex_lock(&rcu_registry_lock); saved_fork_signal_mask = oldmask; @@ -702,7 +702,7 @@ void urcu_bp_after_fork_parent(void) mutex_unlock(&rcu_registry_lock); mutex_unlock(&rcu_gp_lock); ret = pthread_sigmask(SIG_SETMASK, &oldmask, NULL); - assert(!ret); + urcu_posix_assert(!ret); } /* @@ -738,7 +738,7 @@ void urcu_bp_after_fork_child(void) mutex_unlock(&rcu_registry_lock); mutex_unlock(&rcu_gp_lock); ret = pthread_sigmask(SIG_SETMASK, &oldmask, NULL); - assert(!ret); + urcu_posix_assert(!ret); } void *urcu_bp_dereference_sym(void *p) diff --git a/src/urcu-call-rcu-impl.h b/src/urcu-call-rcu-impl.h index 2886865..4392bc6 100644 --- a/src/urcu-call-rcu-impl.h +++ b/src/urcu-call-rcu-impl.h @@ -24,7 +24,6 @@ #include #include #include -#include #include #include #include @@ -35,6 +34,7 @@ #include #include "compat-getcpu.h" +#include #include #include #include @@ -355,8 +355,8 @@ static void *call_rcu_thread(void *arg) cds_wfcq_init(&cbs_tmp_head, &cbs_tmp_tail); splice_ret = __cds_wfcq_splice_blocking(&cbs_tmp_head, &cbs_tmp_tail, &crdp->cbs_head, &crdp->cbs_tail); - assert(splice_ret != CDS_WFCQ_RET_WOULDBLOCK); - assert(splice_ret != CDS_WFCQ_RET_DEST_NON_EMPTY); + urcu_posix_assert(splice_ret != CDS_WFCQ_RET_WOULDBLOCK); + urcu_posix_assert(splice_ret != CDS_WFCQ_RET_DEST_NON_EMPTY); if (splice_ret != CDS_WFCQ_RET_SRC_EMPTY) { synchronize_rcu(); cbcount = 0; diff --git a/src/urcu-defer-impl.h b/src/urcu-defer-impl.h index 8b5ad97..d25e9b9 100644 --- a/src/urcu-defer-impl.h +++ b/src/urcu-defer-impl.h @@ -33,7 +33,6 @@ #include #include #include -#include #include #include #include @@ -43,6 +42,7 @@ #include "urcu/futex.h" +#include #include #include #include @@ -325,9 +325,9 @@ static void _defer_rcu(void (*fct)(void *p), void *p) * Worse-case: must allow 2 supplementary entries for fct pointer. */ if (caa_unlikely(head - tail >= DEFER_QUEUE_SIZE - 2)) { - assert(head - tail <= DEFER_QUEUE_SIZE); + urcu_posix_assert(head - tail <= DEFER_QUEUE_SIZE); rcu_defer_barrier_thread(); - assert(head - CMM_LOAD_SHARED(URCU_TLS(defer_queue).tail) == 0); + urcu_posix_assert(head - CMM_LOAD_SHARED(URCU_TLS(defer_queue).tail) == 0); } /* @@ -403,7 +403,7 @@ static void start_defer_thread(void) int ret; ret = pthread_create(&tid_defer, NULL, thr_defer, NULL); - assert(!ret); + urcu_posix_assert(!ret); } static void stop_defer_thread(void) @@ -417,19 +417,19 @@ static void stop_defer_thread(void) wake_up_defer(); ret = pthread_join(tid_defer, &tret); - assert(!ret); + urcu_posix_assert(!ret); CMM_STORE_SHARED(defer_thread_stop, 0); /* defer thread should always exit when futex value is 0 */ - assert(uatomic_read(&defer_thread_futex) == 0); + urcu_posix_assert(uatomic_read(&defer_thread_futex) == 0); } int rcu_defer_register_thread(void) { int was_empty; - assert(URCU_TLS(defer_queue).last_head == 0); - assert(URCU_TLS(defer_queue).q == NULL); + urcu_posix_assert(URCU_TLS(defer_queue).last_head == 0); + urcu_posix_assert(URCU_TLS(defer_queue).q == NULL); URCU_TLS(defer_queue).q = malloc(sizeof(void *) * DEFER_QUEUE_SIZE); if (!URCU_TLS(defer_queue).q) return -ENOMEM; @@ -466,7 +466,7 @@ void rcu_defer_unregister_thread(void) void rcu_defer_exit(void) { - assert(cds_list_empty(®istry_defer)); + urcu_posix_assert(cds_list_empty(®istry_defer)); } #endif /* _URCU_DEFER_IMPL_H */ diff --git a/src/urcu-qsbr.c b/src/urcu-qsbr.c index e934d3b..d69d93b 100644 --- a/src/urcu-qsbr.c +++ b/src/urcu-qsbr.c @@ -28,13 +28,13 @@ #include #include #include -#include #include #include #include #include #include +#include #include #include #define BUILD_QSBR_LIB @@ -470,10 +470,10 @@ void urcu_qsbr_thread_online(void) void urcu_qsbr_register_thread(void) { URCU_TLS(urcu_qsbr_reader).tid = pthread_self(); - assert(URCU_TLS(urcu_qsbr_reader).ctr == 0); + urcu_posix_assert(URCU_TLS(urcu_qsbr_reader).ctr == 0); mutex_lock(&rcu_registry_lock); - assert(!URCU_TLS(urcu_qsbr_reader).registered); + urcu_posix_assert(!URCU_TLS(urcu_qsbr_reader).registered); URCU_TLS(urcu_qsbr_reader).registered = 1; cds_list_add(&URCU_TLS(urcu_qsbr_reader).node, ®istry); mutex_unlock(&rcu_registry_lock); @@ -487,7 +487,7 @@ void urcu_qsbr_unregister_thread(void) * with a waiting writer. */ _urcu_qsbr_thread_offline(); - assert(URCU_TLS(urcu_qsbr_reader).registered); + urcu_posix_assert(URCU_TLS(urcu_qsbr_reader).registered); URCU_TLS(urcu_qsbr_reader).registered = 0; mutex_lock(&rcu_registry_lock); cds_list_del(&URCU_TLS(urcu_qsbr_reader).node); @@ -499,7 +499,7 @@ void urcu_qsbr_exit(void) /* * Assertion disabled because call_rcu threads are now rcu * readers, and left running at exit. - * assert(cds_list_empty(®istry)); + * urcu_posix_assert(cds_list_empty(®istry)); */ } diff --git a/src/urcu-wait.h b/src/urcu-wait.h index 47ac5eb..c586ec9 100644 --- a/src/urcu-wait.h +++ b/src/urcu-wait.h @@ -23,6 +23,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include #include #include #include "urcu-die.h" @@ -126,7 +127,7 @@ static inline void urcu_adaptative_wake_up(struct urcu_wait_node *wait) { cmm_smp_mb(); - assert(uatomic_read(&wait->state) == URCU_WAIT_WAITING); + urcu_posix_assert(uatomic_read(&wait->state) == URCU_WAIT_WAITING); uatomic_set(&wait->state, URCU_WAIT_WAKEUP); if (!(uatomic_read(&wait->state) & URCU_WAIT_RUNNING)) { if (futex_noasync(&wait->state, FUTEX_WAKE, 1, @@ -183,7 +184,7 @@ skip_futex_wait: } while (!(uatomic_read(&wait->state) & URCU_WAIT_TEARDOWN)) poll(NULL, 0, 10); - assert(uatomic_read(&wait->state) & URCU_WAIT_TEARDOWN); + urcu_posix_assert(uatomic_read(&wait->state) & URCU_WAIT_TEARDOWN); } static inline diff --git a/src/urcu.c b/src/urcu.c index 902b8f8..67c6525 100644 --- a/src/urcu.c +++ b/src/urcu.c @@ -30,7 +30,6 @@ #include #include #include -#include #include #include #include @@ -39,6 +38,7 @@ #include #include +#include #include #include #include @@ -532,11 +532,11 @@ int rcu_read_ongoing(void) void rcu_register_thread(void) { URCU_TLS(rcu_reader).tid = pthread_self(); - assert(URCU_TLS(rcu_reader).need_mb == 0); - assert(!(URCU_TLS(rcu_reader).ctr & URCU_GP_CTR_NEST_MASK)); + urcu_posix_assert(URCU_TLS(rcu_reader).need_mb == 0); + urcu_posix_assert(!(URCU_TLS(rcu_reader).ctr & URCU_GP_CTR_NEST_MASK)); mutex_lock(&rcu_registry_lock); - assert(!URCU_TLS(rcu_reader).registered); + urcu_posix_assert(!URCU_TLS(rcu_reader).registered); URCU_TLS(rcu_reader).registered = 1; rcu_init(); /* In case gcc does not support constructor attribute */ cds_list_add(&URCU_TLS(rcu_reader).node, ®istry); @@ -546,7 +546,7 @@ void rcu_register_thread(void) void rcu_unregister_thread(void) { mutex_lock(&rcu_registry_lock); - assert(URCU_TLS(rcu_reader).registered); + urcu_posix_assert(URCU_TLS(rcu_reader).registered); URCU_TLS(rcu_reader).registered = 0; cds_list_del(&URCU_TLS(rcu_reader).node); mutex_unlock(&rcu_registry_lock); @@ -648,7 +648,7 @@ void rcu_exit(void) * application exits. * Assertion disabled because call_rcu threads are now rcu * readers, and left running at exit. - * assert(cds_list_empty(®istry)); + * urcu_posix_assert(cds_list_empty(®istry)); */ } diff --git a/src/workqueue.c b/src/workqueue.c index cadcf87..e5931b5 100644 --- a/src/workqueue.c +++ b/src/workqueue.c @@ -25,7 +25,6 @@ #include #include #include -#include #include #include #include @@ -36,6 +35,7 @@ #include #include "compat-getcpu.h" +#include #include #include #include @@ -210,8 +210,8 @@ static void *workqueue_thread(void *arg) cds_wfcq_init(&cbs_tmp_head, &cbs_tmp_tail); splice_ret = __cds_wfcq_splice_blocking(&cbs_tmp_head, &cbs_tmp_tail, &workqueue->cbs_head, &workqueue->cbs_tail); - assert(splice_ret != CDS_WFCQ_RET_WOULDBLOCK); - assert(splice_ret != CDS_WFCQ_RET_DEST_NON_EMPTY); + urcu_posix_assert(splice_ret != CDS_WFCQ_RET_WOULDBLOCK); + urcu_posix_assert(splice_ret != CDS_WFCQ_RET_DEST_NON_EMPTY); if (splice_ret != CDS_WFCQ_RET_SRC_EMPTY) { if (workqueue->grace_period_fct) workqueue->grace_period_fct(workqueue, workqueue->priv); @@ -336,7 +336,7 @@ void urcu_workqueue_destroy(struct urcu_workqueue *workqueue) if (urcu_workqueue_destroy_worker(workqueue)) { urcu_die(errno); } - assert(cds_wfcq_empty(&workqueue->cbs_head, &workqueue->cbs_tail)); + urcu_posix_assert(cds_wfcq_empty(&workqueue->cbs_head, &workqueue->cbs_tail)); free(workqueue); } diff --git a/tests/benchmark/test_looplen.c b/tests/benchmark/test_looplen.c index 51c1744..d969ffc 100644 --- a/tests/benchmark/test_looplen.c +++ b/tests/benchmark/test_looplen.c @@ -28,11 +28,11 @@ #include #include #include -#include #include #include #include +#include #ifndef DYNAMIC_LINK_TEST #define _LGPL_SOURCE diff --git a/tests/benchmark/test_mutex.c b/tests/benchmark/test_mutex.c index 6c4e8c7..55f7c38 100644 --- a/tests/benchmark/test_mutex.c +++ b/tests/benchmark/test_mutex.c @@ -28,10 +28,10 @@ #include #include #include -#include #include #include +#include #include #include "thread-id.h" @@ -156,7 +156,7 @@ void *thr_reader(void *data) pthread_mutex_lock(&lock); v = test_array.a; - assert(v == 8); + urcu_posix_assert(v == 8); if (caa_unlikely(rduration)) loop_sleep(rduration); pthread_mutex_unlock(&lock); diff --git a/tests/benchmark/test_perthreadlock.c b/tests/benchmark/test_perthreadlock.c index 76cdee9..47a512c 100644 --- a/tests/benchmark/test_perthreadlock.c +++ b/tests/benchmark/test_perthreadlock.c @@ -28,10 +28,10 @@ #include #include #include -#include #include #include +#include #include #include "thread-id.h" @@ -184,7 +184,7 @@ void *thr_reader(void *data) urcu_mutex_lock(&per_thread_lock[tidx].lock); v = test_array.a; - assert(v == 8); + urcu_posix_assert(v == 8); if (caa_unlikely(rduration)) loop_sleep(rduration); urcu_mutex_unlock(&per_thread_lock[tidx].lock); diff --git a/tests/benchmark/test_perthreadlock_timing.c b/tests/benchmark/test_perthreadlock_timing.c index 712eca1..34aae5f 100644 --- a/tests/benchmark/test_perthreadlock_timing.c +++ b/tests/benchmark/test_perthreadlock_timing.c @@ -28,11 +28,11 @@ #include #include #include -#include #include #include #include +#include #include "thread-id.h" @@ -87,7 +87,7 @@ void *thr_reader(void *arg) perror("Error in pthread mutex lock"); exit(-1); } - assert(test_array.a == 8); + urcu_posix_assert(test_array.a == 8); ret = pthread_mutex_unlock(&per_thread_lock[tidx].lock); if (ret) { perror("Error in pthread mutex unlock"); diff --git a/tests/benchmark/test_rwlock.c b/tests/benchmark/test_rwlock.c index 7ee73b4..6908ea4 100644 --- a/tests/benchmark/test_rwlock.c +++ b/tests/benchmark/test_rwlock.c @@ -28,10 +28,10 @@ #include #include #include -#include #include #include +#include #include #include "thread-id.h" @@ -161,7 +161,7 @@ void *thr_reader(void *_count) } a = test_array.a; - assert(a == 8); + urcu_posix_assert(a == 8); if (caa_unlikely(rduration)) loop_sleep(rduration); diff --git a/tests/benchmark/test_rwlock_timing.c b/tests/benchmark/test_rwlock_timing.c index a7d035e..99c957c 100644 --- a/tests/benchmark/test_rwlock_timing.c +++ b/tests/benchmark/test_rwlock_timing.c @@ -28,11 +28,11 @@ #include #include #include -#include #include #include #include +#include #include "thread-id.h" @@ -87,7 +87,7 @@ void *thr_reader(void *arg) abort(); } - assert(test_array.a == 8); + urcu_posix_assert(test_array.a == 8); ret = pthread_rwlock_unlock(&lock); if (ret) { diff --git a/tests/benchmark/test_urcu.c b/tests/benchmark/test_urcu.c index 2f41a82..ea849fa 100644 --- a/tests/benchmark/test_urcu.c +++ b/tests/benchmark/test_urcu.c @@ -28,9 +28,9 @@ #include #include #include -#include #include +#include #include #include #include "thread-id.h" @@ -140,7 +140,7 @@ void *thr_reader(void *_count) set_affinity(); rcu_register_thread(); - assert(!rcu_read_ongoing()); + urcu_posix_assert(!rcu_read_ongoing()); while (!test_go) { @@ -149,11 +149,11 @@ void *thr_reader(void *_count) for (;;) { rcu_read_lock(); - assert(rcu_read_ongoing()); + urcu_posix_assert(rcu_read_ongoing()); local_ptr = rcu_dereference(test_rcu_pointer); rcu_debug_yield_read(); if (local_ptr) - assert(*local_ptr == 8); + urcu_posix_assert(*local_ptr == 8); if (caa_unlikely(rduration)) loop_sleep(rduration); rcu_read_unlock(); @@ -193,7 +193,7 @@ void *thr_writer(void *_count) for (;;) { new = malloc(sizeof(int)); - assert(new); + urcu_posix_assert(new); *new = 8; old = rcu_xchg_pointer(&test_rcu_pointer, new); if (caa_unlikely(wduration)) diff --git a/tests/benchmark/test_urcu_assign.c b/tests/benchmark/test_urcu_assign.c index dcb5d1e..88889a8 100644 --- a/tests/benchmark/test_urcu_assign.c +++ b/tests/benchmark/test_urcu_assign.c @@ -28,10 +28,10 @@ #include #include #include -#include #include #include +#include #include #include "thread-id.h" #include "../common/debug-yield.h" @@ -172,7 +172,7 @@ static struct test_array *test_array_alloc(void) int index; index = array_index % ARRAY_SIZE; - assert(test_array[index].a == ARRAY_POISON || + urcu_posix_assert(test_array[index].a == ARRAY_POISON || test_array[index].a == 0); ret = &test_array[index]; array_index++; @@ -211,7 +211,7 @@ void *thr_reader(void *_count) local_ptr = rcu_dereference(test_rcu_pointer); rcu_debug_yield_read(); if (local_ptr) - assert(local_ptr->a == 8); + urcu_posix_assert(local_ptr->a == 8); if (caa_unlikely(rduration)) loop_sleep(rduration); rcu_read_unlock(); diff --git a/tests/benchmark/test_urcu_bp.c b/tests/benchmark/test_urcu_bp.c index 1bf62bd..6f8c59d 100644 --- a/tests/benchmark/test_urcu_bp.c +++ b/tests/benchmark/test_urcu_bp.c @@ -28,10 +28,10 @@ #include #include #include -#include #include #include +#include #include #include "thread-id.h" #include "../common/debug-yield.h" @@ -140,7 +140,7 @@ void *thr_reader(void *_count) set_affinity(); rcu_register_thread(); - assert(!rcu_read_ongoing()); + urcu_posix_assert(!rcu_read_ongoing()); while (!test_go) { @@ -149,11 +149,11 @@ void *thr_reader(void *_count) for (;;) { rcu_read_lock(); - assert(rcu_read_ongoing()); + urcu_posix_assert(rcu_read_ongoing()); local_ptr = rcu_dereference(test_rcu_pointer); rcu_debug_yield_read(); if (local_ptr) - assert(*local_ptr == 8); + urcu_posix_assert(*local_ptr == 8); if (caa_unlikely(rduration)) loop_sleep(rduration); rcu_read_unlock(); diff --git a/tests/benchmark/test_urcu_defer.c b/tests/benchmark/test_urcu_defer.c index 3635f1a..e948ebf 100644 --- a/tests/benchmark/test_urcu_defer.c +++ b/tests/benchmark/test_urcu_defer.c @@ -28,10 +28,10 @@ #include #include #include -#include #include #include +#include #include #include "thread-id.h" #include "../common/debug-yield.h" @@ -159,7 +159,7 @@ void *thr_reader(void *_count) local_ptr = rcu_dereference(test_rcu_pointer); rcu_debug_yield_read(); if (local_ptr) - assert(local_ptr->a == 8); + urcu_posix_assert(local_ptr->a == 8); if (caa_unlikely(rduration)) loop_sleep(rduration); rcu_read_unlock(); diff --git a/tests/benchmark/test_urcu_gc.c b/tests/benchmark/test_urcu_gc.c index 50c5b76..f14f728 100644 --- a/tests/benchmark/test_urcu_gc.c +++ b/tests/benchmark/test_urcu_gc.c @@ -28,10 +28,10 @@ #include #include #include -#include #include #include +#include #include #include "thread-id.h" #include "../common/debug-yield.h" @@ -167,7 +167,7 @@ void *thr_reader(void *_count) local_ptr = rcu_dereference(test_rcu_pointer); rcu_debug_yield_read(); if (local_ptr) - assert(local_ptr->a == 8); + urcu_posix_assert(local_ptr->a == 8); if (caa_unlikely(rduration)) loop_sleep(rduration); rcu_read_unlock(); diff --git a/tests/benchmark/test_urcu_hash.c b/tests/benchmark/test_urcu_hash.c index 8838bc0..3574b4c 100644 --- a/tests/benchmark/test_urcu_hash.c +++ b/tests/benchmark/test_urcu_hash.c @@ -192,7 +192,7 @@ unsigned long test_compare(const void *key1, size_t key1_len, { if (caa_unlikely(key1_len != key2_len)) return -1; - assert(key1_len == sizeof(unsigned long)); + urcu_posix_assert(key1_len == sizeof(unsigned long)); if (key1 == key2) return 0; else @@ -258,7 +258,7 @@ void test_delete_all_nodes(struct cds_lfht *ht) int ret; ret = cds_lfht_del(test_ht, cds_lfht_iter_get_node(&iter)); - assert(!ret); + urcu_posix_assert(!ret); call_rcu(&node->head, free_node_cb); count++; } @@ -599,7 +599,7 @@ int main(int argc, char **argv) */ rcu_register_thread(); ret = (get_populate_hash_cb())(); - assert(!ret); + urcu_posix_assert(!ret); rcu_thread_offline(); diff --git a/tests/benchmark/test_urcu_hash.h b/tests/benchmark/test_urcu_hash.h index dfb8116..47b2ae3 100644 --- a/tests/benchmark/test_urcu_hash.h +++ b/tests/benchmark/test_urcu_hash.h @@ -31,10 +31,10 @@ #include #include #include -#include #include #include +#include #include #include #include "thread-id.h" @@ -304,7 +304,7 @@ unsigned long test_hash_mix(const void *_key, size_t length, unsigned long seed) { unsigned int key = (unsigned int) _key; - assert(length == sizeof(unsigned int)); + urcu_posix_assert(length == sizeof(unsigned int)); return hash_u32(&key, 1, seed); } #else @@ -320,7 +320,7 @@ unsigned long test_hash_mix(const void *_key, size_t length, unsigned long seed) uint32_t v32[2]; } key; - assert(length == sizeof(unsigned long)); + urcu_posix_assert(length == sizeof(unsigned long)); v.v64 = (uint64_t) seed; key.v64 = (uint64_t) _key; hashword2(key.v32, 2, &v.v32[0], &v.v32[1]); @@ -345,7 +345,7 @@ unsigned long test_hash(const void *_key, size_t length, } else { unsigned long v; - assert(length == sizeof(unsigned long)); + urcu_posix_assert(length == sizeof(unsigned long)); v = (unsigned long) _key; return v % nr_hash_chains; } @@ -367,7 +367,7 @@ static inline void cds_lfht_test_lookup(struct cds_lfht *ht, void *key, size_t key_len, struct cds_lfht_iter *iter) { - assert(key_len == sizeof(unsigned long)); + urcu_posix_assert(key_len == sizeof(unsigned long)); cds_lfht_lookup(ht, test_hash(key, key_len, TEST_HASH_SEED), test_match, key, iter); diff --git a/tests/benchmark/test_urcu_lfq.c b/tests/benchmark/test_urcu_lfq.c index 708e29b..490e8b0 100644 --- a/tests/benchmark/test_urcu_lfq.c +++ b/tests/benchmark/test_urcu_lfq.c @@ -31,10 +31,10 @@ #include #include #include -#include #include #include +#include #include #include "thread-id.h" @@ -404,7 +404,7 @@ int main(int argc, char **argv) test_end(&end_dequeues); err = cds_lfq_destroy_rcu(&q); - assert(!err); + urcu_posix_assert(!err); printf_verbose("total number of enqueues : %llu, dequeues %llu\n", tot_enqueues, tot_dequeues); diff --git a/tests/benchmark/test_urcu_lfs.c b/tests/benchmark/test_urcu_lfs.c index 1d1ae52..52239e0 100644 --- a/tests/benchmark/test_urcu_lfs.c +++ b/tests/benchmark/test_urcu_lfs.c @@ -31,10 +31,10 @@ #include #include #include -#include #include #include +#include #include #include "thread-id.h" @@ -266,7 +266,7 @@ static void *thr_dequeuer(void *_count) } cmm_smp_mb(); - assert(test_pop || test_pop_all); + urcu_posix_assert(test_pop || test_pop_all); for (;;) { if (test_pop && test_pop_all) { diff --git a/tests/benchmark/test_urcu_lfs_rcu.c b/tests/benchmark/test_urcu_lfs_rcu.c index 7b5c055..7975faf 100644 --- a/tests/benchmark/test_urcu_lfs_rcu.c +++ b/tests/benchmark/test_urcu_lfs_rcu.c @@ -31,10 +31,10 @@ #include #include #include -#include #include #include +#include #include #include "thread-id.h" diff --git a/tests/benchmark/test_urcu_qsbr.c b/tests/benchmark/test_urcu_qsbr.c index 6a51744..1ea369c 100644 --- a/tests/benchmark/test_urcu_qsbr.c +++ b/tests/benchmark/test_urcu_qsbr.c @@ -28,10 +28,10 @@ #include #include #include -#include #include #include +#include #include #include "thread-id.h" #include "../common/debug-yield.h" @@ -140,9 +140,9 @@ void *thr_reader(void *_count) rcu_register_thread(); - assert(rcu_read_ongoing()); + urcu_posix_assert(rcu_read_ongoing()); rcu_thread_offline(); - assert(!rcu_read_ongoing()); + urcu_posix_assert(!rcu_read_ongoing()); rcu_thread_online(); while (!test_go) @@ -152,11 +152,11 @@ void *thr_reader(void *_count) for (;;) { rcu_read_lock(); - assert(rcu_read_ongoing()); + urcu_posix_assert(rcu_read_ongoing()); local_ptr = rcu_dereference(test_rcu_pointer); rcu_debug_yield_read(); if (local_ptr) - assert(*local_ptr == 8); + urcu_posix_assert(*local_ptr == 8); if (caa_unlikely(rduration)) loop_sleep(rduration); rcu_read_unlock(); @@ -199,7 +199,7 @@ void *thr_writer(void *_count) for (;;) { new = malloc(sizeof(int)); - assert(new); + urcu_posix_assert(new); *new = 8; old = rcu_xchg_pointer(&test_rcu_pointer, new); if (caa_unlikely(wduration)) diff --git a/tests/benchmark/test_urcu_qsbr_gc.c b/tests/benchmark/test_urcu_qsbr_gc.c index 8eaf8d4..8877a82 100644 --- a/tests/benchmark/test_urcu_qsbr_gc.c +++ b/tests/benchmark/test_urcu_qsbr_gc.c @@ -28,10 +28,10 @@ #include #include #include -#include #include #include +#include #include #include "thread-id.h" #include "../common/debug-yield.h" @@ -164,7 +164,7 @@ void *thr_reader(void *_count) local_ptr = _rcu_dereference(test_rcu_pointer); rcu_debug_yield_read(); if (local_ptr) - assert(local_ptr->a == 8); + urcu_posix_assert(local_ptr->a == 8); if (caa_unlikely(rduration)) loop_sleep(rduration); _rcu_read_unlock(); diff --git a/tests/benchmark/test_urcu_qsbr_timing.c b/tests/benchmark/test_urcu_qsbr_timing.c index 71d8d8d..09b9ca9 100644 --- a/tests/benchmark/test_urcu_qsbr_timing.c +++ b/tests/benchmark/test_urcu_qsbr_timing.c @@ -28,10 +28,10 @@ #include #include #include -#include #include #include +#include #include "thread-id.h" #define _LGPL_SOURCE @@ -104,7 +104,7 @@ void *thr_reader(void *arg) _rcu_read_lock(); local_ptr = _rcu_dereference(test_rcu_pointer); if (local_ptr) { - assert(local_ptr->a == 8); + urcu_posix_assert(local_ptr->a == 8); } _rcu_read_unlock(); } @@ -141,7 +141,7 @@ void *thr_writer(void *arg) rcu_copy_mutex_lock(); old = test_rcu_pointer; if (old) { - assert(old->a == 8); + urcu_posix_assert(old->a == 8); } new->a = 8; old = rcu_xchg_pointer(&test_rcu_pointer, new); diff --git a/tests/benchmark/test_urcu_timing.c b/tests/benchmark/test_urcu_timing.c index 44911f5..35b0e80 100644 --- a/tests/benchmark/test_urcu_timing.c +++ b/tests/benchmark/test_urcu_timing.c @@ -28,9 +28,10 @@ #include #include #include -#include #include + #include +#include #include "thread-id.h" @@ -104,7 +105,7 @@ void *thr_reader(void *arg) rcu_read_lock(); local_ptr = rcu_dereference(test_rcu_pointer); if (local_ptr) { - assert(local_ptr->a == 8); + urcu_posix_assert(local_ptr->a == 8); } rcu_read_unlock(); } @@ -140,7 +141,7 @@ void *thr_writer(void *arg) rcu_copy_mutex_lock(); old = test_rcu_pointer; if (old) { - assert(old->a == 8); + urcu_posix_assert(old->a == 8); } new->a = 8; old = rcu_xchg_pointer(&test_rcu_pointer, new); diff --git a/tests/benchmark/test_urcu_wfcq.c b/tests/benchmark/test_urcu_wfcq.c index 3cae9b7..2c6e0fd 100644 --- a/tests/benchmark/test_urcu_wfcq.c +++ b/tests/benchmark/test_urcu_wfcq.c @@ -31,10 +31,10 @@ #include #include #include -#include #include #include +#include #include #include #include "thread-id.h" @@ -233,7 +233,7 @@ static void do_test_splice(enum test_sync sync) switch (ret) { case CDS_WFCQ_RET_WOULDBLOCK: - assert(0); /* blocking call */ + urcu_posix_assert(0); /* blocking call */ break; case CDS_WFCQ_RET_DEST_EMPTY: URCU_TLS(nr_splice)++; @@ -241,7 +241,7 @@ static void do_test_splice(enum test_sync sync) /* ok */ break; case CDS_WFCQ_RET_DEST_NON_EMPTY: - assert(0); /* entirely unexpected */ + urcu_posix_assert(0); /* entirely unexpected */ break; case CDS_WFCQ_RET_SRC_EMPTY: /* ok, we could even skip iteration on dest if we wanted */ diff --git a/tests/benchmark/test_urcu_wfq.c b/tests/benchmark/test_urcu_wfq.c index 173a567..8381160 100644 --- a/tests/benchmark/test_urcu_wfq.c +++ b/tests/benchmark/test_urcu_wfq.c @@ -31,10 +31,10 @@ #include #include #include -#include #include #include +#include #include #include "thread-id.h" diff --git a/tests/benchmark/test_urcu_wfs.c b/tests/benchmark/test_urcu_wfs.c index 64731b3..c285feb 100644 --- a/tests/benchmark/test_urcu_wfs.c +++ b/tests/benchmark/test_urcu_wfs.c @@ -31,10 +31,10 @@ #include #include #include -#include #include #include +#include #include #include #include "thread-id.h" @@ -255,7 +255,7 @@ static void *thr_dequeuer(void *_count) } cmm_smp_mb(); - assert(test_pop || test_pop_all); + urcu_posix_assert(test_pop || test_pop_all); for (;;) { if (test_pop && test_pop_all) { diff --git a/tests/regression/test_urcu_fork.c b/tests/regression/test_urcu_fork.c index b6f94f5..81dbe77 100644 --- a/tests/regression/test_urcu_fork.c +++ b/tests/regression/test_urcu_fork.c @@ -28,10 +28,10 @@ #include #include #include -#include #include #include +#include #include #include @@ -89,7 +89,7 @@ static void test_rcu(void) rcu_read_unlock(); node = malloc(sizeof(*node)); - assert(node); + urcu_posix_assert(node); call_rcu(&node->head, cb);