Cleanup: use mutex_lock() wrapper in rculfhash
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 8 Jun 2017 00:19:13 +0000 (20:19 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 8 Jun 2017 00:19:13 +0000 (20:19 -0400)
Fixes this coverity issue:

*** CID 1375952:  Error handling issues  (CHECKED_RETURN)
/src/rculfhash.c: 1950 in cds_lfht_resize()
1944     }
1945
1946     void cds_lfht_resize(struct cds_lfht *ht, unsigned long new_size)
1947     {
1948             resize_target_update_count(ht, new_size);
1949             CMM_STORE_SHARED(ht->resize_initiated, 1);
>>>     CID 1375952:  Error handling issues  (CHECKED_RETURN)
>>>     Calling "pthread_mutex_lock" without checking return value (as is done elsewhere 44 out of 50 times).
1950             pthread_mutex_lock(&ht->resize_mutex);
1951             _do_cds_lfht_resize(ht);
1952             pthread_mutex_unlock(&ht->resize_mutex);
1953     }
1954
1955     static

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
src/rculfhash.c

index 0bd138486d8d74a21edc46f8b9c74e0873b1a925..fed33e4574806969a768b01a777bc3c91a9eee03 100644 (file)
@@ -585,6 +585,37 @@ static
 void cds_lfht_resize_lazy_count(struct cds_lfht *ht, unsigned long size,
                                unsigned long count);
 
+static void mutex_lock(pthread_mutex_t *mutex)
+{
+       int ret;
+
+#ifndef DISTRUST_SIGNALS_EXTREME
+       ret = pthread_mutex_lock(mutex);
+       if (ret)
+               urcu_die(ret);
+#else /* #ifndef DISTRUST_SIGNALS_EXTREME */
+       while ((ret = pthread_mutex_trylock(mutex)) != 0) {
+               if (ret != EBUSY && ret != EINTR)
+                       urcu_die(ret);
+               if (CMM_LOAD_SHARED(URCU_TLS(rcu_reader).need_mb)) {
+                       cmm_smp_mb();
+                       _CMM_STORE_SHARED(URCU_TLS(rcu_reader).need_mb, 0);
+                       cmm_smp_mb();
+               }
+               (void) poll(NULL, 0, 10);
+       }
+#endif /* #else #ifndef DISTRUST_SIGNALS_EXTREME */
+}
+
+static void mutex_unlock(pthread_mutex_t *mutex)
+{
+       int ret;
+
+       ret = pthread_mutex_unlock(mutex);
+       if (ret)
+               urcu_die(ret);
+}
+
 static long nr_cpus_mask = -1;
 static long split_count_mask = -1;
 static int split_count_order = -1;
@@ -1947,9 +1978,9 @@ void cds_lfht_resize(struct cds_lfht *ht, unsigned long new_size)
 {
        resize_target_update_count(ht, new_size);
        CMM_STORE_SHARED(ht->resize_initiated, 1);
-       pthread_mutex_lock(&ht->resize_mutex);
+       mutex_lock(&ht->resize_mutex);
        _do_cds_lfht_resize(ht);
-       pthread_mutex_unlock(&ht->resize_mutex);
+       mutex_unlock(&ht->resize_mutex);
 }
 
 static
@@ -1960,9 +1991,9 @@ void do_resize_cb(struct urcu_work *work)
        struct cds_lfht *ht = resize_work->ht;
 
        ht->flavor->register_thread();
-       pthread_mutex_lock(&ht->resize_mutex);
+       mutex_lock(&ht->resize_mutex);
        _do_cds_lfht_resize(ht);
-       pthread_mutex_unlock(&ht->resize_mutex);
+       mutex_unlock(&ht->resize_mutex);
        ht->flavor->unregister_thread();
        poison_free(work);
 }
@@ -2037,37 +2068,6 @@ void cds_lfht_resize_lazy_count(struct cds_lfht *ht, unsigned long size,
        __cds_lfht_resize_lazy_launch(ht);
 }
 
-static void mutex_lock(pthread_mutex_t *mutex)
-{
-       int ret;
-
-#ifndef DISTRUST_SIGNALS_EXTREME
-       ret = pthread_mutex_lock(mutex);
-       if (ret)
-               urcu_die(ret);
-#else /* #ifndef DISTRUST_SIGNALS_EXTREME */
-       while ((ret = pthread_mutex_trylock(mutex)) != 0) {
-               if (ret != EBUSY && ret != EINTR)
-                       urcu_die(ret);
-               if (CMM_LOAD_SHARED(URCU_TLS(rcu_reader).need_mb)) {
-                       cmm_smp_mb();
-                       _CMM_STORE_SHARED(URCU_TLS(rcu_reader).need_mb, 0);
-                       cmm_smp_mb();
-               }
-               (void) poll(NULL, 0, 10);
-       }
-#endif /* #else #ifndef DISTRUST_SIGNALS_EXTREME */
-}
-
-static void mutex_unlock(pthread_mutex_t *mutex)
-{
-       int ret;
-
-       ret = pthread_mutex_unlock(mutex);
-       if (ret)
-               urcu_die(ret);
-}
-
 static void cds_lfht_before_fork(void *priv)
 {
        if (cds_lfht_workqueue_atfork_nesting++)
This page took 0.027923 seconds and 4 git commands to generate.