1 //===-- Atomic.cpp - Atomic Operations --------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements atomic operations.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/Support/Atomic.h"
15 #include "llvm/Config/llvm-config.h"
25 #if defined(__GNUC__) || (defined(__IBMCPP__) && __IBMCPP__ >= 1210)
29 void sys::MemoryFence() {
30 #if LLVM_HAS_ATOMICS == 0
33 # if defined(GNU_ATOMICS)
35 # elif defined(_MSC_VER)
38 # error No memory fence implementation for your platform!
43 sys::cas_flag sys::CompareAndSwap(volatile sys::cas_flag* ptr,
44 sys::cas_flag new_value,
45 sys::cas_flag old_value) {
46 #if LLVM_HAS_ATOMICS == 0
47 sys::cas_flag result = *ptr;
48 if (result == old_value)
51 #elif defined(GNU_ATOMICS)
52 return __sync_val_compare_and_swap(ptr, old_value, new_value);
53 #elif defined(_MSC_VER)
54 return InterlockedCompareExchange(ptr, new_value, old_value);
56 # error No compare-and-swap implementation for your platform!