diff options
author | Ben Pfaff <blp@nicira.com> | 2013-06-28 15:54:40 -0700 |
---|---|---|
committer | Ben Pfaff <blp@nicira.com> | 2013-06-28 16:09:36 -0700 |
commit | 31a3fc6e3e9ce68d8bfebf65150d9455b9334dda (patch) | |
tree | 052b8e4940546c43a090730ee8fe248f1571ccda /lib/ovs-atomic-pthreads.c | |
parent | 42943cdef10197befc9acc8c6fdb632a210c055f (diff) |
ovs-atomic: New library for atomic operations.
This library should prove useful for the threading changes coming up.
The following commit introduces one (very simple) user.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
Diffstat (limited to 'lib/ovs-atomic-pthreads.c')
-rw-r--r-- | lib/ovs-atomic-pthreads.c | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/lib/ovs-atomic-pthreads.c b/lib/ovs-atomic-pthreads.c new file mode 100644 index 00000000..a501b825 --- /dev/null +++ b/lib/ovs-atomic-pthreads.c @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2013 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 +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 */ |