summaryrefslogtreecommitdiff
path: root/lib/ovs-atomic-gcc4+.h
Commit message (Collapse)AuthorAgeFilesLines
* lib/ovs-atomic: Add missing macro argument parentheses.Jarno Rajahalme2014-08-291-4/+4
| | | | | | | | | | Otherwise the dereference operator could target a portion of a ternary expression, for example. Also minor style fixes. Signed-off-by: Jarno Rajahalme <jrajahalme@nicira.com> Acked-by: Ben Pfaff <blp@nicira.com>
* lib/ovs-atomic-gcc4+: Use 'volatile' to enforce memory access.Jarno Rajahalme2014-08-051-2/+2
| | | | | | | | | | | | | | | | | Use 'volatile' to enforce a new memory access on each lockless atomic store and read. Without this a loop consisting of an atomic_read with memory_order_relaxed would be simply optimized away. Also, using volatile is cheaper than adding a full compiler barrier (also) in that case. This use of a volatile cast mirrors the Linux kernel ACCESS_ONCE macro. Without this change the more rigorous atomic test cases introduced in a following patch will hang due to the atomic accesses being optimized away. Signed-off-by: Jarno Rajahalme <jrajahalme@nicira.com> Acked-by: Ben Pfaff <blp@nicira.com>
* ovs-atomic: Fix GCC4+ atomic_flag.Jarno Rajahalme2014-08-051-15/+25
| | | | | | | | | | The default memory order for atomic_flag is documented to be memory_order_seq_cst (as in C11), but the GCC4+ implementation only used the GCC builtins, which provide acquire and release semantics only. Additional barriers are needed for in other cases. Signed-off-by: Jarno Rajahalme <jrajahalme@nicira.com> Acked-by: Ben Pfaff <blp@nicira.com>
* lib/ovs-atomic: Require memory_order be constant.Jarno Rajahalme2014-08-051-6/+4
| | | | | | | | | | | | | | | | Compiler implementations may provide sub-optimal support for a memory_order passed in as a run-time value (ref. https://gcc.gnu.org/onlinedocs/gcc/_005f_005fatomic-Builtins.html). Document that OVS atomics require the memory order to be passed in as a compile-time constant. It should be noted, however, that when inlining is disabled (i.e., compiling without optimization) even compile-time constants may be passed as run-time values to (non-inlined) functions. Signed-off-by: Jarno Rajahalme <jrajahalme@nicira.com> Acked-by: Ben Pfaff <blp@nicira.com>
* ovs-atomic: Avoid evaluating arguments multiple times.Jarno Rajahalme2014-07-211-4/+4
| | | | | | | | | ovs-atomic-gcc4+ did expand arguments again, if locked set/get was called. Also fix atomic_is_lock_free(). Signed-off-by: Jarno Rajahalme <jrajahalme@nicira.com> Acked-by: Ben Pfaff <blp@nicira.com>
* lib/ovs-atomic: Add atomic compare_exchange.Jarno Rajahalme2014-07-071-0/+23
| | | | | | Add support for atomic compare_exchange operations. Signed-off-by: Jarno Rajahalme <jrajahalme@nicira.com> Acked-by: Ben Pfaff <blp@nicira.com>
* ovs-atomic: Delete atomic, atomic_flag, ovs_refcount destroy functions.Ben Pfaff2014-03-131-13/+0
| | | | | | | | None of the atomic implementations need a destroy function anymore, so it's "more standard" and more convenient for users to get rid of them. Signed-off-by: Ben Pfaff <blp@nicira.com> Acked-by: Andy Zhou <azhou@nicira.com>
* ovs-atomic-types: Move into ovs-atomic.h.Ben Pfaff2014-03-131-1/+0
| | | | | | | | Every implementation used this same code, so it makes sense to centralize it. Signed-off-by: Ben Pfaff <blp@nicira.com> Acked-by: Andy Zhou <azhou@nicira.com>
* ovs-atomic: Use raw types, not structs, when locks are required.Ben Pfaff2014-03-131-145/+53
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Until now, the GCC 4+ and pthreads implementations of atomics have used struct wrappers for their atomic types. This had the advantage of allowing a mutex to be wrapped in, in some cases, and of better type-checking by preventing stray uses of atomic variables other than through one of the atomic_*() functions or macros. However, the mutex meant that an atomic_destroy() function-like macro needed to be used. The struct wrapper also made it impossible to define new atomic types that were compatible with each other without using a typedef. For example, one could not simply define a macro like #define ATOMIC(TYPE) struct { TYPE value; } and then have two declarations like: ATOMIC(void *) x; ATOMIC(void *) y; and do anything with these objects that require type-compatibility, even "&x == &y", because the two structs are not compatible. One can do it through a typedef: typedef ATOMIC(void *) atomic_voidp; atomic_voidp x, y; but that is inconvenient, especially because of the need to invent a name for the type. This commit aims to ease the problem by getting rid of the wrapper structs in the cases where the atomic library used them. It gets rid of the mutexes, in the cases where they are still needed, by using a global array of mutexes instead. This commit also defines the ATOMIC macro described above and documents its use in ovs-atomic.h. Signed-off-by: Ben Pfaff <blp@nicira.com> Acked-by: Andy Zhou <azhou@nicira.com>
* ovs-atomic-gcc4+: Fix parenthesization in atomic_read_explicit().Ben Pfaff2014-03-131-1/+1
| | | | | Signed-off-by: Ben Pfaff <blp@nicira.com> Acked-by: Andy Zhou <azhou@nicira.com>
* ovs-atomic: Add atomic_destroy() and use everywhere it is needed.Ben Pfaff2014-01-081-0/+1
| | | | | | | C11 is able to require that atomics don't need to be destroyed, but some of the OVS implementations do. Signed-off-by: Ben Pfaff <blp@nicira.com>
* ovs-atomic: New functions atomic_flag_init(), atomic_flag_destroy().Ben Pfaff2014-01-081-0/+12
| | | | | | | | | | | | | | | Standard C11 doesn't need these functions because it is able to require implementations not to need them. But we can't construct a portable implementation that does not need them in every case, so this commit adds them. These functions are only needed for atomic_flag objects that are dynamically allocated (because statically allocated objects can use ATOMIC_FLAG_INIT). So far there aren't any of those, but an upcoming commit will introduce one. Signed-off-by: Ben Pfaff <blp@nicira.com> Acked-by: Ethan Jackson <ethan@nicira.com>
* clang: Fix the alignment warning.Alex Wang2013-07-231-2/+2
| | | | | | | | This commit fixes the warning issued by 'clang' when pointer is casted to one with greater alignment. Signed-off-by: Alex Wang <alexw@nicira.com> Signed-off-by: Ben Pfaff <blp@nicira.com>
* ovs-atomic: New library for atomic operations.Ben Pfaff2013-06-281-0/+265
This library should prove useful for the threading changes coming up. The following commit introduces one (very simple) user. Signed-off-by: Ben Pfaff <blp@nicira.com> Acked-by: Ethan Jackson <ethan@nicira.com>