2
0
mirror of https://github.com/openvswitch/ovs synced 2025-08-29 13:27:59 +00:00

16 Commits

Author SHA1 Message Date
Ben Pfaff
2fec1533fd ovs-thread: Use mutex instead of its address in thread-safety annotation.
CodingStyle says that this is preferred.

Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
2013-08-13 09:42:32 -07:00
Ben Pfaff
47b52c7123 sparse: Remove support for thread-safety annotations.
The Clang support for thread-safety annotations is much more effective
than "sparse" support.  I found that I was unable to make the annotations
warning-free under sparse.

Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
2013-08-13 09:42:28 -07:00
Ben Pfaff
d87d523dac ovs-thread: Remove superfluous semicolons in macro definitions.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
2013-08-08 15:53:44 -07:00
Ethan Jackson
ec2905a895 ovs-thread: New function xpthread_join().
Signed-off-by: Ethan Jackson <ethan@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>
2013-08-08 14:01:54 -07:00
Ben Pfaff
6878fada58 ovs-thread: New function ovsthread_id_self().
I foresee a need for possibly large numbers of instances of "struct
seq" (which is introduced in an upcoming patch).  Each struct seq
needs some per-thread data.  POSIX has pthread_key_t for this, but
the number of keys can be fairly limited, to as few as 128.  It is
reasonable to work around this by using a hash table indexed on the
current thread.  That only works if one can get a thread identifier
that is hashable (pthread_t is not).  This patch introduces a
hashable thread identifier.

Signed-off-by: Ben Pfaff <blp@nicira.com>
2013-08-08 13:18:10 -07:00
Ben Pfaff
2ba4f163d9 ovs-thread: Add support for globally visible per-thread data.
DEFINE_PER_THREAD_DATA always declared its data item as "static", meaning
that it was only directly visible within a single translation unit.
This commit adds additional forms of per-thread data that allow the data
to be accessible from multiple translation units.

Signed-off-by: Ben Pfaff <blp@nicira.com>
2013-08-08 13:18:10 -07:00
Ben Pfaff
9c4c45edc3 ovs-thread: New function xpthread_setspecific().
Signed-off-by: Ben Pfaff <blp@nicira.com>
2013-08-08 13:18:10 -07:00
Alex Wang
13d94ee9c8 ovs-atomic-pthreads: Fix "has incomplete type" error.
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>
2013-07-31 16:07:46 -07:00
Ethan Jackson
97be153858 clang: Add annotations for thread safety check.
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>
2013-07-30 21:30:45 -07:00
Ben Pfaff
5453ae2067 Avoid C preprocessor trick where macro has the same name as a function.
In C, one can do preprocessor tricks by making a macro expansion include
the macro's own name.  We actually used this in the tree to automatically
provide function arguments, e.g.:

    int f(int x, const char *file, int line);
    #define f(x) f(x, __FILE__, __LINE__)

...

    f(1);    /* Expands to a call like f(1, __FILE__, __LINE__); */

However it's somewhat confusing, so this commit stops using that trick.

Reported-by: Ed Maste <emaste@freebsd.org>
Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Ed Maste <emaste@freebsd.org>
2013-07-29 15:24:45 -07:00
Ben Pfaff
a8e736a848 ovs-thread: Add wrappers for "destroy" functions too.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
2013-07-25 09:56:01 -07:00
Ben Pfaff
b847adc620 fatal-signal: Make thread-safe.
Signed-off-by: Ben Pfaff <blp@nicira.com>
2013-07-23 11:38:21 -07:00
Ben Pfaff
728a8b141f ovs-thread: Add support for various thread-related assertions.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
2013-06-28 16:09:37 -07:00
Ben Pfaff
1514b27555 ovs-thread: Add support for convenient once-only initializers.
pthread_once() is portable but it does not allow passing any parameters to
the initialization function, which is often inconvenient, because it means
that the function can only access data declared at file scope.  This commit
introduces an alternative with a more convenient interface.

Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
2013-06-28 16:09:36 -07:00
Ben Pfaff
c22095a5fb ovs-thread: Add per-thread data support.
POSIX defines a portable pthread_key_t API for per-thread data.  GCC and
C11 have two different forms of per-thread data that are generally faster
than the POSIX API, where they are available.  This commit adds a
macro-based wrapper, DEFINE_PER_THREAD_DATA, that takes advantage of these
features where they are available and falls back to the POSIX API
otherwise.

The Clang compiler implements C11 thread_local in its <threads.h>.

This commit also adds a convenience wrapper for the POSIX API, via the
DEFINE_PER_THREAD_MALLOCED_DATA macro.

Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
2013-06-25 14:05:01 -07:00
Ben Pfaff
ec68790f6d ovs-thread: New module, initially just with pthreads wrapper functions.
The only tricky part here is that I'm throwing in annotations to allow
"sparse" to report unbalanced locking.

Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
2013-06-25 14:05:01 -07:00