[ovs-dev] [urcu v2 07/15] ovs-atomic-pthreads: Use global shared locks for atomic_flag also.

Ben Pfaff blp at nicira.com
Tue Mar 11 20:56:09 UTC 2014


This will eliminate the need for atomic_flag_destroy().

Signed-off-by: Ben Pfaff <blp at nicira.com>
---
 lib/automake.mk           |    1 -
 lib/ovs-atomic-pthreads.c |   78 ---------------------------------------------
 lib/ovs-atomic-pthreads.h |   56 +++++++++++++++++++++++++++-----
 3 files changed, 48 insertions(+), 87 deletions(-)
 delete mode 100644 lib/ovs-atomic-pthreads.c

diff --git a/lib/automake.mk b/lib/automake.mk
index 1310dcd..6ed40f6 100644
--- a/lib/automake.mk
+++ b/lib/automake.mk
@@ -138,7 +138,6 @@ lib_libopenvswitch_la_SOURCES = \
 	lib/ovs-atomic-gcc4.7+.h \
 	lib/ovs-atomic-locked.c \
 	lib/ovs-atomic-locked.h \
-	lib/ovs-atomic-pthreads.c \
 	lib/ovs-atomic-pthreads.h \
 	lib/ovs-atomic-types.h \
 	lib/ovs-atomic.h \
diff --git a/lib/ovs-atomic-pthreads.c b/lib/ovs-atomic-pthreads.c
deleted file mode 100644
index 7311135..0000000
--- a/lib/ovs-atomic-pthreads.c
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Copyright (c) 2013, 2014 Nicira, Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <config.h>
-
-#include "ovs-atomic.h"
-#include "ovs-thread.h"
-
-#if OVS_ATOMIC_PTHREADS_IMPL
-void
-atomic_flag_init(volatile atomic_flag *flag_)
-{
-    atomic_flag *flag = CONST_CAST(atomic_flag *, flag_);
-
-    pthread_mutex_init(&flag->mutex, NULL);
-    atomic_flag_clear(flag_);
-}
-
-void
-atomic_flag_destroy(volatile atomic_flag *flag_)
-{
-    atomic_flag *flag = CONST_CAST(atomic_flag *, flag_);
-
-    pthread_mutex_destroy(&flag->mutex);
-}
-
-bool
-atomic_flag_test_and_set(volatile atomic_flag *flag_)
-{
-    atomic_flag *flag = CONST_CAST(atomic_flag *, flag_);
-    bool old_value;
-
-    xpthread_mutex_lock(&flag->mutex);
-    old_value = flag->b;
-    flag->b = true;
-    xpthread_mutex_unlock(&flag->mutex);
-
-    return old_value;
-}
-
-bool
-atomic_flag_test_and_set_explicit(volatile atomic_flag *flag,
-                                  memory_order order OVS_UNUSED)
-{
-    return atomic_flag_test_and_set(flag);
-}
-
-void
-atomic_flag_clear(volatile atomic_flag *flag_)
-{
-    atomic_flag *flag = CONST_CAST(atomic_flag *, flag_);
-
-    xpthread_mutex_lock(&flag->mutex);
-    flag->b = false;
-    xpthread_mutex_unlock(&flag->mutex);
-}
-
-void
-atomic_flag_clear_explicit(volatile atomic_flag *flag,
-                           memory_order order OVS_UNUSED)
-{
-    return atomic_flag_clear(flag);
-}
-
-#endif  /* OVS_ATOMIC_PTHREADS_IMPL */
diff --git a/lib/ovs-atomic-pthreads.h b/lib/ovs-atomic-pthreads.h
index 7b742cd..4b27bc2 100644
--- a/lib/ovs-atomic-pthreads.h
+++ b/lib/ovs-atomic-pthreads.h
@@ -90,15 +90,55 @@ atomic_signal_fence(memory_order order OVS_UNUSED)
 
 typedef struct {
     bool b;
-    pthread_mutex_t mutex;
 } atomic_flag;
-#define ATOMIC_FLAG_INIT { false, PTHREAD_MUTEX_INITIALIZER }
+#define ATOMIC_FLAG_INIT { false }
 
-void atomic_flag_init(volatile atomic_flag *);
-void atomic_flag_destroy(volatile atomic_flag *);
+static inline void
+atomic_flag_init(volatile atomic_flag *flag OVS_UNUSED)
+{
+    /* Nothing to do. */
+}
+
+static inline void
+atomic_flag_destroy(volatile atomic_flag *flag OVS_UNUSED)
+{
+    /* Nothing to do. */
+}
+
+static inline bool
+atomic_flag_test_and_set(volatile atomic_flag *flag_)
+{
+    atomic_flag *flag = CONST_CAST(atomic_flag *, flag_);
+    bool old_value;
+
+    atomic_lock__(flag);
+    old_value = flag->b;
+    flag->b = true;
+    atomic_unlock__(flag);
 
-bool atomic_flag_test_and_set(volatile atomic_flag *);
-bool atomic_flag_test_and_set_explicit(volatile atomic_flag *, memory_order);
+    return old_value;
+}
+
+static inline bool
+atomic_flag_test_and_set_explicit(volatile atomic_flag *flag,
+                                  memory_order order OVS_UNUSED)
+{
+    return atomic_flag_test_and_set(flag);
+}
+
+static inline void
+atomic_flag_clear(volatile atomic_flag *flag_)
+{
+    atomic_flag *flag = CONST_CAST(atomic_flag *, flag_);
+
+    atomic_lock__(flag);
+    flag->b = false;
+    atomic_unlock__(flag);
+}
 
-void atomic_flag_clear(volatile atomic_flag *);
-void atomic_flag_clear_explicit(volatile atomic_flag *, memory_order);
+static inline void
+atomic_flag_clear_explicit(volatile atomic_flag *flag,
+                           memory_order order OVS_UNUSED)
+{
+    atomic_flag_clear(flag);
+}
-- 
1.7.10.4




More information about the dev mailing list