2 * Copyright (c) 2016 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.
20 #include "ovs-atomic.h"
21 #include "openvswitch/type-props.h"
23 typedef uint64_t ovs_version_t
;
25 #define OVS_VERSION_MIN 0 /* Default version number to use. */
26 #define OVS_VERSION_MAX (TYPE_MAXIMUM(ovs_version_t) - 1)
27 #define OVS_VERSION_NOT_REMOVED TYPE_MAXIMUM(ovs_version_t)
30 * OVS_VERSION_NOT_REMOVED has a special meaning for 'remove_version',
31 * meaning that the rule has been added but not yet removed.
34 ovs_version_t add_version
; /* Version object was added in. */
35 ATOMIC(ovs_version_t
) remove_version
; /* Version object is removed in. */
38 #define VERSIONS_INITIALIZER(ADD, REMOVE) \
39 (struct versions){ ADD, ATOMIC_VAR_INIT(REMOVE) }
42 versions_set_remove_version(struct versions
*versions
, ovs_version_t version
)
44 atomic_store_relaxed(&versions
->remove_version
, version
);
48 versions_visible_in_version(const struct versions
*versions
,
49 ovs_version_t version
)
51 ovs_version_t remove_version
;
53 /* C11 does not want to access an atomic via a const object pointer. */
54 atomic_read_relaxed(&CONST_CAST(struct versions
*,
55 versions
)->remove_version
,
58 return versions
->add_version
<= version
&& version
< remove_version
;
62 versions_is_eventually_invisible(const struct versions
*versions
)
64 ovs_version_t remove_version
;
66 /* C11 does not want to access an atomic via a const object pointer. */
67 atomic_read_relaxed(&CONST_CAST(struct versions
*,
68 versions
)->remove_version
,
71 return remove_version
< OVS_VERSION_NOT_REMOVED
;
74 #endif /* VERSIONS_H */