LCOV - code coverage report
Current view: top level - lib - versions.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 9 9 100.0 %
Date: 2016-09-14 01:02:56 Functions: 3 3 100.0 %
Branches: 3 4 75.0 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * Copyright (c) 2016 Nicira, Inc.
       3                 :            :  *
       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:
       7                 :            :  *
       8                 :            :  *     http://www.apache.org/licenses/LICENSE-2.0
       9                 :            :  *
      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.
      15                 :            :  */
      16                 :            : 
      17                 :            : #ifndef VERSIONS_H
      18                 :            : #define VERSIONS_H 1
      19                 :            : 
      20                 :            : #include "ovs-atomic.h"
      21                 :            : #include "openvswitch/type-props.h"
      22                 :            : 
      23                 :            : typedef uint64_t ovs_version_t;
      24                 :            : 
      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)
      28                 :            : 
      29                 :            : /*
      30                 :            :  * OVS_VERSION_NOT_REMOVED has a special meaning for 'remove_version',
      31                 :            :  * meaning that the rule has been added but not yet removed.
      32                 :            :  */
      33                 :            : struct versions {
      34                 :            :     ovs_version_t add_version;              /* Version object was added in. */
      35                 :            :     ATOMIC(ovs_version_t) remove_version;   /* Version object is removed in. */
      36                 :            : };
      37                 :            : 
      38                 :            : #define VERSIONS_INITIALIZER(ADD, REMOVE) \
      39                 :            :     (struct versions){ ADD, ATOMIC_VAR_INIT(REMOVE) }
      40                 :            : 
      41                 :            : static inline void
      42                 :     523121 : versions_set_remove_version(struct versions *versions, ovs_version_t version)
      43                 :            : {
      44                 :     523121 :     atomic_store_relaxed(&versions->remove_version, version);
      45                 :     523121 : }
      46                 :            : 
      47                 :            : static inline bool
      48                 :   13359295 : versions_visible_in_version(const struct versions *versions,
      49                 :            :                             ovs_version_t version)
      50                 :            : {
      51                 :            :     ovs_version_t remove_version;
      52                 :            : 
      53                 :            :     /* C11 does not want to access an atomic via a const object pointer. */
      54                 :   13359295 :     atomic_read_relaxed(&CONST_CAST(struct versions *,
      55                 :            :                                     versions)->remove_version,
      56                 :            :                         &remove_version);
      57                 :            : 
      58 [ +  - ][ +  + ]:   13359295 :     return versions->add_version <= version && version < remove_version;
      59                 :            : }
      60                 :            : 
      61                 :            : static inline bool
      62                 :     468166 : versions_is_eventually_invisible(const struct versions *versions)
      63                 :            : {
      64                 :            :     ovs_version_t remove_version;
      65                 :            : 
      66                 :            :     /* C11 does not want to access an atomic via a const object pointer. */
      67                 :     468166 :     atomic_read_relaxed(&CONST_CAST(struct versions *,
      68                 :            :                                     versions)->remove_version,
      69                 :            :                         &remove_version);
      70                 :            : 
      71                 :     468166 :     return remove_version < OVS_VERSION_NOT_REMOVED;
      72                 :            : }
      73                 :            : 
      74                 :            : #endif /* VERSIONS_H */

Generated by: LCOV version 1.12