LCOV - code coverage report
Current view: directory - src/include/osx - atomic_ops_osx.h (source / functions) Found Hit Coverage
Test: coverage.lcov Lines: 13 13 100.0 %
Date: 2012-02-16 Functions: 0 0 -

       1                 : /*
       2                 :  * Copyright 2008, Google Inc.
       3                 :  * All rights reserved.
       4                 :  *
       5                 :  * Redistribution and use in source and binary forms, with or without
       6                 :  * modification, are permitted provided that the following conditions are
       7                 :  * met:
       8                 :  *
       9                 :  *     * Redistributions of source code must retain the above copyright
      10                 :  * notice, this list of conditions and the following disclaimer.
      11                 :  *     * Redistributions in binary form must reproduce the above
      12                 :  * copyright notice, this list of conditions and the following disclaimer
      13                 :  * in the documentation and/or other materials provided with the
      14                 :  * distribution.
      15                 :  *     * Neither the name of Google Inc. nor the names of its
      16                 :  * contributors may be used to endorse or promote products derived from
      17                 :  * this software without specific prior written permission.
      18                 :  *
      19                 :  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
      20                 :  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
      21                 :  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
      22                 :  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
      23                 :  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
      24                 :  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
      25                 :  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
      26                 :  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
      27                 :  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
      28                 :  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
      29                 :  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
      30                 :  */
      31                 : 
      32                 : 
      33                 : #ifndef NATIVE_CLIENT_SRC_INCLUDE_OSX_ATOMIC_OPS_OSX_H_
      34                 : #define NATIVE_CLIENT_SRC_INCLUDE_OSX_ATOMIC_OPS_OSX_H_ 1
      35                 : 
      36                 : #include "native_client/src/include/portability.h"
      37                 : #include <libkern/OSAtomic.h>
      38                 : #include <stdint.h>
      39                 : 
      40                 : typedef int32_t Atomic32;
      41                 : 
      42                 : static INLINE Atomic32
      43                 : CompareAndSwap(volatile Atomic32 *ptr,
      44                 :                Atomic32 old_value,
      45          940595 :                Atomic32 new_value) {
      46                 :   Atomic32 prev_value;
      47                 :   do {
      48          940595 :     if (OSAtomicCompareAndSwap32(old_value, new_value,
      49                 :                                  (Atomic32*) ptr)) {
      50              25 :       return old_value;
      51                 :     }
      52         1328720 :     prev_value = *ptr;
      53         1328720 :   } while (prev_value == old_value);
      54         1632230 :   return prev_value;
      55                 : }
      56                 : 
      57                 : static INLINE Atomic32
      58                 : AtomicExchange(volatile Atomic32 *ptr,
      59              25 :                Atomic32 new_value) {
      60                 :   Atomic32 old_value;
      61                 :   do {
      62              25 :     old_value = *ptr;
      63              25 :   } while (!OSAtomicCompareAndSwap32(old_value, new_value,
      64              25 :                                      (Atomic32*) ptr));
      65              25 :   return old_value;
      66                 : }
      67                 : 
      68                 : static INLINE Atomic32
      69           46439 : AtomicIncrement(volatile Atomic32 *ptr, Atomic32 increment) {
      70           46439 :   return OSAtomicAdd32(increment, (Atomic32*) ptr);
      71                 : }
      72                 : 
      73                 : #endif  // NATIVE_CLIENT_SRC_INCLUDE_OSX_ATOMIC_OPS_OSX_H_

Generated by: LCOV version 1.7