diff mbox series

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

Message ID 20181210170523.2279-5-i.maximets@samsung.com
State Accepted
Headers show
Series Various build/test fixes. | expand

Commit Message

Ilya Maximets Dec. 10, 2018, 5:05 p.m. UTC
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@samsung.com>
---
 include/openvswitch/thread.h | 3 ++-
 lib/ovs-thread.c             | 1 +
 2 files changed, 3 insertions(+), 1 deletion(-)

Comments

Ben Pfaff Dec. 10, 2018, 5:54 p.m. UTC | #1
On Mon, Dec 10, 2018 at 08:05:23PM +0300, Ilya Maximets wrote:
> 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@samsung.com>

Applied to master, thanks!
diff mbox series

Patch

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;