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 header file implements atomic operations.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/System/Atomic.h"
15 #include "llvm/Config/config.h"
23 void sys::MemoryFence() {
24 #if LLVM_MULTITHREADED==0
27 # if defined(__GNUC__)
29 # elif defined(_MSC_VER)
32 # error No memory fence implementation for your platform!
37 sys::cas_flag sys::CompareAndSwap(volatile sys::cas_flag* ptr,
38 sys::cas_flag new_value,
39 sys::cas_flag old_value) {
40 #if LLVM_MULTITHREADED==0
41 sys::cas_flag result = *ptr;
42 if (result == old_value)
45 #elif defined(__GNUC__)
46 return __sync_val_compare_and_swap(ptr, old_value, new_value);
47 #elif defined(_MSC_VER)
48 return InterlockedCompareExchange(ptr, new_value, old_value);
50 # error No compare-and-swap implementation for your platform!