ovs-atomic-pthreads: Use global shared locks for atomic_flag also.
authorBen Pfaff <blp@nicira.com>
Tue, 11 Mar 2014 19:57:02 +0000 (12:57 -0700)
committerBen Pfaff <blp@nicira.com>
Thu, 13 Mar 2014 19:45:38 +0000 (12:45 -0700)
This will eliminate the need for atomic_flag_destroy().

Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Andy Zhou <azhou@nicira.com>
lib/automake.mk
lib/ovs-atomic-pthreads.c [deleted file]
lib/ovs-atomic-pthreads.h

index c025577..0612f27 100644 (file)
@@ -143,7 +143,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 (file)
index 7311135..0000000
+++ /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 */
index 7b742cd..4b27bc2 100644 (file)
@@ -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);
+}