aboutsummaryrefslogtreecommitdiff
path: root/lib/ovs-thread.c
AgeCommit message (Collapse)Author
2013-08-22ovs-thread: Mark lock and unlock functions as no_thread_safety_analysis.Ben Pfaff
I don't see any other way to make Clang realize that these are the real mutex implementation functions. I first noticed these warnings with Clang 1:3.4~svn188890-1~exp1. I previously used version 1:3.4~svn187484-1~exp1. Signed-off-by: Ben Pfaff <blp@nicira.com> Acked-by: Ethan Jackson <ethan@nicira.com>
2013-08-20Use "error-checking" mutexes in place of other kinds wherever possible.Ben Pfaff
We've seen a number of deadlocks in the tree since thread safety was introduced. So far, all of these are self-deadlocks, that is, a single thread acquiring a lock and then attempting to re-acquire the same lock recursively. When this has happened, the process simply hung, and it was somewhat difficult to find the cause. POSIX "error-checking" mutexes check for this specific problem (and others). This commit switches from other types of mutexes to error-checking mutexes everywhere that we can, that is, everywhere that we're not using recursive mutexes. This ought to help find problems more quickly in the future. There might be performance advantages to other kinds of mutexes in some cases. However, the existing mutex type choices were just guesses, so I'd rather go for easy detection of errors until we know that other mutex types actually perform better in specific cases. Also, I did a quick microbenchmark of glibc mutex types on my host and found that the error checking mutexes weren't any slower than the other types, at least when the mutex is uncontended. Signed-off-by: Ben Pfaff <blp@nicira.com> Acked-by: Ethan Jackson <ethan@nicira.com>
2013-08-08ovs-thread: New function xpthread_join().Ethan Jackson
Signed-off-by: Ethan Jackson <ethan@nicira.com> Acked-by: Ben Pfaff <blp@nicira.com>
2013-08-08ovs-thread: New function ovsthread_id_self().Ben Pfaff
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-08ovs-thread: New function xpthread_setspecific().Ben Pfaff
Signed-off-by: Ben Pfaff <blp@nicira.com>
2013-07-31ovs-atomic-pthreads: Fix "has incomplete type" error.Alex Wang
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-30clang: Add annotations for thread safety check.Ethan Jackson
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-29Avoid C preprocessor trick where macro has the same name as a function.Ben Pfaff
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-25ovs-thread: Add wrappers for "destroy" functions too.Ben Pfaff
Signed-off-by: Ben Pfaff <blp@nicira.com> Acked-by: Ethan Jackson <ethan@nicira.com>
2013-07-23fatal-signal: Make thread-safe.Ben Pfaff
Signed-off-by: Ben Pfaff <blp@nicira.com>
2013-06-28Replace all uses of strerror() by ovs_strerror(), for thread safety.Ben Pfaff
Signed-off-by: Ben Pfaff <blp@nicira.com>
2013-06-28ovs-thread: Add support for various thread-related assertions.Ben Pfaff
Signed-off-by: Ben Pfaff <blp@nicira.com> Acked-by: Ethan Jackson <ethan@nicira.com>
2013-06-28ovs-thread: Add support for convenient once-only initializers.Ben Pfaff
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-25ovs-thread: New module, initially just with pthreads wrapper functions.Ben Pfaff
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>