[ovs-dev] [PATCH] lib/ovs-thread: set prefer writer lock for ovs_rwlock_init()

gaohaifeng gaohaifeng.gao at huawei.com
Fri Dec 16 02:28:11 UTC 2016


From: zangchuanqiang <zangchuanqiang at huawei.com>

An alternative "writer nonrecursive" rwlock allows recursive
read-locks to succeed only if there are no threads waiting for the
write-lock. In the function ovs_rwlock_init(), there exist a problem,
the parameter of 'attr' is not used to set the attributes of ovs_rwlock 'l_',
just because use pthread_rwlock_init(&l->lock, NULL) to init l->lock.

The attr object needs to be passed to the pthread_rwlock_init()
call in order to make use of it.

Signed-off-by: zangchuanqiang <zangchuanqiang at huawei.com>
---
 lib/ovs-thread.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/lib/ovs-thread.c b/lib/ovs-thread.c
index aa0aab2..0efc5d5 100644
--- a/lib/ovs-thread.c
+++ b/lib/ovs-thread.c
@@ -239,8 +239,11 @@ ovs_rwlock_init(const struct ovs_rwlock *l_)
 #ifdef PTHREAD_RWLOCK_WRITER_NONRECURSIVE_INITIALIZER_NP
     xpthread_rwlockattr_setkind_np(
         &attr, PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP);
-#endif
+    error = pthread_rwlock_init(&l->lock, &attr);
+#else
     error = pthread_rwlock_init(&l->lock, NULL);
+#endif
+
     if (OVS_UNLIKELY(error)) {
         ovs_abort(error, "pthread_rwlock_init failed");
     }
-- 
1.8.3.1




More information about the dev mailing list