[ovs-dev] [PATCH 4/4] ovs-thread: Add thread safety annotation to cond_wait.

Ilya Maximets i.maximets at samsung.com
Mon Dec 10 17:05:23 UTC 2018


This fixes build with clang on FreeBSD:

  lib/ovs-thread.c:266:13: error:

  calling function 'pthread_cond_wait' requires holding mutex \
  'mutex->lock' exclusively [-Werror,-Wthread-safety-analysis]

      error = pthread_cond_wait(cond, &mutex->lock);
              ^

Fixes: 97be153858b4 ("clang: Add annotations for thread safety check.")
Signed-off-by: Ilya Maximets <i.maximets at samsung.com>
---
 include/openvswitch/thread.h | 3 ++-
 lib/ovs-thread.c             | 1 +
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/include/openvswitch/thread.h b/include/openvswitch/thread.h
index 5ffc29067..2987db37c 100644
--- a/include/openvswitch/thread.h
+++ b/include/openvswitch/thread.h
@@ -68,7 +68,8 @@ int ovs_mutex_trylock_at(const struct ovs_mutex *mutex, const char *where)
 #define ovs_mutex_trylock(mutex) \
         ovs_mutex_trylock_at(mutex, OVS_SOURCE_LOCATOR)
 
-void ovs_mutex_cond_wait(pthread_cond_t *, const struct ovs_mutex *);
+void ovs_mutex_cond_wait(pthread_cond_t *, const struct ovs_mutex *mutex)
+    OVS_REQUIRES(mutex);
 
 /* Convenient once-only execution.
  *
diff --git a/lib/ovs-thread.c b/lib/ovs-thread.c
index b5f7424b7..c8d92bc1b 100644
--- a/lib/ovs-thread.c
+++ b/lib/ovs-thread.c
@@ -257,6 +257,7 @@ ovs_rwlock_init(const struct ovs_rwlock *l_)
  * call with calls to ovsrcu_quiesce_start() and ovsrcu_quiesce_end().  */
 void
 ovs_mutex_cond_wait(pthread_cond_t *cond, const struct ovs_mutex *mutex_)
+    OVS_NO_THREAD_SAFETY_ANALYSIS
 {
     struct ovs_mutex *mutex = CONST_CAST(struct ovs_mutex *, mutex_);
     int error;
-- 
2.17.1



More information about the dev mailing list