2
* Copyright (c) 2013 Nicira, Inc.
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at:
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
19
#include "ovs-atomic.h"
20
#include "ovs-thread.h"
22
#if OVS_ATOMIC_GCC4P_IMPL
23
static struct ovs_mutex mutex = OVS_ADAPTIVE_MUTEX_INITIALIZER;
25
#define DEFINE_LOCKED_OP(TYPE, NAME, OPERATOR) \
27
locked_##TYPE##_##NAME(struct locked_##TYPE *u, TYPE##_t arg) \
31
ovs_mutex_lock(&mutex); \
32
old_value = u->value; \
33
u->value OPERATOR arg; \
34
ovs_mutex_unlock(&mutex); \
39
#define DEFINE_LOCKED_TYPE(TYPE) \
41
locked_##TYPE##_load(const struct locked_##TYPE *u) \
45
ovs_mutex_lock(&mutex); \
47
ovs_mutex_unlock(&mutex); \
53
locked_##TYPE##_store(struct locked_##TYPE *u, TYPE##_t value) \
55
ovs_mutex_lock(&mutex); \
57
ovs_mutex_unlock(&mutex); \
59
DEFINE_LOCKED_OP(TYPE, add, +=); \
60
DEFINE_LOCKED_OP(TYPE, sub, -=); \
61
DEFINE_LOCKED_OP(TYPE, or, |=); \
62
DEFINE_LOCKED_OP(TYPE, xor, ^=); \
63
DEFINE_LOCKED_OP(TYPE, and, &=)
65
DEFINE_LOCKED_TYPE(uint64);
66
DEFINE_LOCKED_TYPE(int64);
68
#endif /* OVS_ATOMIC_GCC4P_IMPL */