From: Ben Pfaff Date: Tue, 11 Mar 2014 19:57:02 +0000 (-0700) Subject: ovs-atomic-pthreads: Use global shared locks for atomic_flag also. X-Git-Tag: sliver-openvswitch-2.2.90-1~6^2~114 X-Git-Url: http://git.onelab.eu/?p=sliver-openvswitch.git;a=commitdiff_plain;h=4dff0893c3760fa388f053d8a4fb74b2600c85a5 ovs-atomic-pthreads: Use global shared locks for atomic_flag also. This will eliminate the need for atomic_flag_destroy(). Signed-off-by: Ben Pfaff Acked-by: Andy Zhou --- diff --git a/lib/automake.mk b/lib/automake.mk index c02557763..0612f2756 100644 --- a/lib/automake.mk +++ b/lib/automake.mk @@ -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 index 731113596..000000000 --- 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 - -#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 7b742cda0..4b27bc272 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); +}