summaryrefslogtreecommitdiff
path: root/lib/ovs-atomic-pthreads.h
Commit message (Collapse)AuthorAgeFilesLines
* lib/ovs-atomic: Add atomic compare_exchange.Jarno Rajahalme2014-07-071-0/+10
| | | | | | 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-pthreads: Use global shared locks for atomic_flag also.Ben Pfaff2014-03-131-8/+48
| | | | | | | This will eliminate the need for atomic_flag_destroy(). 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-42/+24
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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: Factor type declarations out of most implementations.Ben Pfaff2014-03-131-42/+3
| | | | | | | This reduces duplicate code. 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/+3
| | | | | | | 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/+3
| | | | | | | | | | | | | | | 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>
* ovs-atomic-pthreads: Fix "has incomplete type" error.Alex Wang2013-07-311-1/+1
| | | | | | | | | | | | | | | Commit 97be153858b4cd175cbe7862b8e1624bf22ab98a (clang: Add annotations for thread safety check.) defined 'struct ovs_mutex' variable in 'atomic_flag' in 'ovs-atomic-pthreads.h'. This casued "mutex: has incomplete type" error in compilation when 'ovs-atomic-pthreads.h' is included. This commit goes back to use 'pthread_mutex_t' for that variable and adds test for the 'atomic_flag' related functions. Reported-by: Gurucharan Shetty <gshetty@nicira.com> Signed-off-by: Alex Wang <alexw@nicira.com> Signed-off-by: Ben Pfaff <blp@nicira.com>
* clang: Add annotations for thread safety check.Ethan Jackson2013-07-301-1/+1
| | | | | | | | | | This commit adds annotations for thread safety check. And the check can be conducted by using -Wthread-safety flag in clang. Co-authored-by: Alex Wang <alexw@nicira.com> Signed-off-by: Alex Wang <alexw@nicira.com> Signed-off-by: Ethan Jackson <ethan@nicira.com> Signed-off-by: Ben Pfaff <blp@nicira.com>
* ovs-atomic: New library for atomic operations.Ben Pfaff2013-06-281-0/+155
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>