1 //===- llvm/System/Atomic.h - 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 declares the llvm::sys atomic operations.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_SYSTEM_ATOMIC_H
15 #define LLVM_SYSTEM_ATOMIC_H
25 inline void MemoryFence() {
26 #if !defined(ENABLE_THREADS) || ENABLE_THREADS == 0
27 # if defined(__GNUC__)
28 __asm__ __volatile__("" : : : "memory");
29 # elif defined(_MSC_VER)
32 # error No memory fence implementation for your platform!
35 # if defined(__GNUC__)
37 # elif defined(_MSC_VER)
40 # error No memory fence implementation for your platform!
45 #if !defined(ENABLE_THREADS) || ENABLE_THREADS == 0
46 typedef unsigned long cas_flag;
47 inline cas_flag CompareAndSwap(cas_flag* dest, cas_flag exc, cas_flag c) {
48 cas_flag result = *dest;
53 #elif defined(__GNUC__)
54 typedef unsigned long cas_flag;
55 inline cas_flag CompareAndSwap(cas_flag* ptr,
58 return __sync_val_compare_and_swap(ptr, old_value, new_value);
60 #elif defined(_MSC_VER) && _M_IX86 > 400
61 typedef LONG cas_flag;
62 inline cas_flag CompareAndSwap(cas_flag* ptr,
65 return InterlockedCompareExchange(addr, new_value, old_value);
68 # error No compare-and-swap implementation for your platform!