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 LLVM_MULTITHREADED==0
29 # if defined(__GNUC__)
31 # elif defined(_MSC_VER)
34 # error No memory fence implementation for your platform!
39 #if LLVM_MULTITHREADED==0
40 typedef unsigned long cas_flag;
42 inline T CompareAndSwap(volatile T* dest,
49 #elif defined(__GNUC__)
50 typedef unsigned long cas_flag;
52 inline T CompareAndSwap(volatile T* ptr,
55 return __sync_val_compare_and_swap(ptr, old_value, new_value);
57 #elif defined(_MSC_VER)
58 typedef LONG cas_flag;
60 inline T CompareAndSwap(volatile T* ptr,
64 return InterlockedCompareExchange(ptr, new_value, old_value);
65 else if (sizeof(T) == 8)
66 return InterlockedCompareExchange64(ptr, new_value, old_value);
68 assert(0 && "Unsupported compare-and-swap size!");
72 inline T* CompareAndSwap<T*>(volatile T** ptr,
75 return InterlockedCompareExchangePtr(ptr, new_value, old_value);
80 # error No compare-and-swap implementation for your platform!