2
0
mirror of https://github.com/openvswitch/ovs synced 2025-09-04 16:25:17 +00:00

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 <blp@nicira.com>
Acked-by: Andy Zhou <azhou@nicira.com>
This commit is contained in:
Ben Pfaff
2014-03-11 12:57:02 -07:00
parent 1bd2c9edc3
commit 4dff0893c3
3 changed files with 48 additions and 87 deletions

View 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 \

View File

@@ -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 */

View 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. */
}
bool atomic_flag_test_and_set(volatile atomic_flag *);
bool atomic_flag_test_and_set_explicit(volatile atomic_flag *, memory_order);
static inline void
atomic_flag_destroy(volatile atomic_flag *flag OVS_UNUSED)
{
/* Nothing to do. */
}
void atomic_flag_clear(volatile atomic_flag *);
void atomic_flag_clear_explicit(volatile atomic_flag *, memory_order);
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);
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);
}
static inline void
atomic_flag_clear_explicit(volatile atomic_flag *flag,
memory_order order OVS_UNUSED)
{
atomic_flag_clear(flag);
}