Cleanup: Re-organise source dir Re-organise the sources, add a top level "src" and "include" dir and move relevant files. Disable autotools automated includes and define them manually. This fixes problems with collision of header names with system headers. Include the autoconf config.h in the default includes and remove it where it's explicitely included. Remove _GNU_SOURCE defines since it's detected at configure for platforms that requires it and added to the config.h. Signed-off-by: Michael Jeanson <mjeanson@efficios.com> Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fix: add missing destroy functions to queues/stack APIs Queues and stack APIs that invoke pthread_mutex_init() should have a "destroy" counterpart which calls pthread_mutex_destroy(), ortherwise this causes small memory leaks on platforms where pthread_mutex_init performs memory allocation. Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
wfcqueue: add C++ compatibility API Introduce __cds_wfcq_head_cast and cds_wfcq_head_cast for compability of wfcqueue with c++. Those are effect-less in C, where transparent unions are supported. However, in C++, those transform struct cds_wfcq_head and struct __cds_wfcq_head pointers to cds_wfcq_head_ptr_t. Reviewed-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com> Tested-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com> Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
lfstack: relax constraints on node re-use The documentation of the RCU-based synchronization technique in lfstack is too strict. It currently states that the cds_lfs_node structure cannot be overwritten before a grace period has passed. However, lfstack pop only use the next pointer as the replacement value when doing the cmpxchg on the head. After the node has been pop'd from the stack, concurrent cmpxchg trying to pop that same node will necessarily fail as long as there is a grace period before pop/pop_all and re-adding the node into the stack. It is therefore sufficient to wait for a grace period between: 1) pop/pop_all and 2) freeing the node (to ensure existence for concurrent pop trying to read node->next) or re-adding the node into the stack. This node re-use constraint relaxation is only possible because we don't care about node->next content read by concurrent pop: it will be simply discarded by the cmpxchg on head. Be careful not to apply this relaxed constraint to other data structures which care about the content of the node's next pointer (e.g. wfstack). This relaxed constraint allows implementing efficient free-lists (memory allocation) with a lock-free allocation/free based on lfstack: it allows re-using the memory backing the free-list node immediately after allocation. The only requirement with respect to this use-case is to wait for a grace period before putting the node back into the free-list. Also update the test_urcu_lfs to poison the next pointer immediately after pop/pop_all to make sure we test this relaxed constraint. Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> CC: Paul E. McKenney <paulmck@linux.vnet.ibm.com> CC: Lai Jiangshan <jiangshanlai@gmail.com> CC: lttng-dev@lists.lttng.org CC: rp@svcs.cs.pdx.edu
Detect RCU read-side overflows Use the urcu_assert() macro (enabled on DEBUG_RCU) to check for unmatched rcu_read_lock() that eventually leads to nesting counter overflow in urcu.h and urcu-bp.h. This won't necessarily point the the exact rcu_read_lock() that is unmatched, but will at least detect the overflow condition. Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Detect RCU read-side underflows Use the urcu_assert() macro (enabled on DEBUG_RCU) to check for unmatched rcu_read_unlock() that leads to nesting counter underflow in urcu.h and urcu-bp.h. Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Introduce urcu_assert and registration check Add a "registered" flag to urcu.c and urcu-qsbr.c, set/cleared when a thread is registered and unregistered. Add corresponding asserts in those functions checking if a thread is registered or unregistered more than once (which would be a bug in the way the application uses urcu). Move the checks enabled on RCU_DEBUG to a single header: urcu/debug.h. Add checks for the registered flag in RCU read-side lock functions (new urcu_assert() checks, which are only built-in if RCU_DEBUG is defined at compile-time). Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fix: handle sys_futex() FUTEX_WAIT interrupted by signal We need to handle EINTR returned by sys_futex() FUTEX_WAIT, otherwise a signal interrupting this system call could make sys_futex return too early, and therefore cause a synchronization issue. Ensure that the futex compatibility layer returns meaningful errors and errno when using poll() or pthread cond variables. Reported-by: Gerd Gerats <geg@ngncc.de> CC: Paul E. McKenney <paulmck@linux.vnet.ibm.com> CC: Lai Jiangshan <laijs@cn.fujitsu.com> CC: Stephen Hemminger <shemminger@vyatta.com> CC: Alan Stern <stern@rowland.harvard.edu> CC: lttng-dev@lists.lttng.org CC: rp@svcs.cs.pdx.edu Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mark braced-groups within expressions with __extension__ Braced-groups within expressions are not valid ISO C, so if a macro uses them and it's included in a project built with -pedantic, the build will fail. GCC and CLANG do support them as extension, so marking them as such allows the build to complete even with -pedantic. Signed-off-by: Luca Boccassi <lboccass@brocade.com> Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
wfstack: implement mutex-free wfstack with transparent union This allows users more freedom to use alternative synchronization mechanisms. Changes since v1: - Fix typos in cds_wfs_stack_ptr_t documentation. Thanks to Mathieu for spotting. Signed-off-by: Eric Wong <normalperson@yhbt.net> Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com> Cc: Lai Jiangshan <laijs@cn.fujitsu.com> Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
wfcqueue: Implement mutex-free wfcqueue head with transparent union Tested-by: Eric Wong <normalperson@yhbt.net> CC: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> CC: "Lai Jiangshan" <laijs@cn.fujitsu.com> Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
lfstack: Implement mutex-free stack head with transparent union (v2) Changes since v1: - implement __cds_lfs_init(). Tested-by: Eric Wong <normalperson@yhbt.net> CC: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> CC: "Lai Jiangshan" <laijs@cn.fujitsu.com> Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>