mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-20 09:30:43 +00:00
8064c8b86d
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@71849 91177308-0d34-0410-b5e6-96231b3b80d8
82 lines
2.1 KiB
C++
82 lines
2.1 KiB
C++
//===- llvm/System/Atomic.h - Atomic Operations -----------------*- C++ -*-===//
|
|
//
|
|
// The LLVM Compiler Infrastructure
|
|
//
|
|
// This file is distributed under the University of Illinois Open Source
|
|
// License. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This file declares the llvm::sys atomic operations.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef LLVM_SYSTEM_ATOMIC_H
|
|
#define LLVM_SYSTEM_ATOMIC_H
|
|
|
|
#include <stdint.h>
|
|
|
|
#if defined(__APPLE__)
|
|
#if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ == 0)
|
|
#include <libkern/OSAtomic.h>
|
|
#endif
|
|
#elif LLVM_ON_WIN32
|
|
#include <windows.h>
|
|
#endif
|
|
|
|
|
|
namespace llvm {
|
|
namespace sys {
|
|
|
|
#if !defined(ENABLE_THREADS) || ENABLE_THREADS == 0
|
|
inline void MemoryFence() {
|
|
return;
|
|
}
|
|
|
|
typedef uint32_t cas_flag;
|
|
inline cas_flag CompareAndSwap(cas_flag* dest, cas_flag exc, cas_flag c) {
|
|
cas_flag result = *dest;
|
|
if (result == c)
|
|
*dest = exc;
|
|
return result;
|
|
}
|
|
|
|
#elif __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1)
|
|
inline void MemoryFence() {
|
|
__sync_synchronize();
|
|
}
|
|
|
|
typedef volatile uint32_t cas_flag;
|
|
inline cas_flag CompareAndSwap(cas_flag* dest, cas_flag exc, cas_flag c) {
|
|
return __sync_val_compare_and_swap(dest, exc, c);
|
|
}
|
|
|
|
#elif defined(__APPLE__)
|
|
inline void MemoryFence() {
|
|
OSMemoryBarrier();
|
|
}
|
|
|
|
typedef volatile int32_t cas_flag;
|
|
inline cas_flag CompareAndSwap(cas_flag* dest, cas_flag exc, cas_flag c) {
|
|
cas_flag old = *dest;
|
|
OSAtomicCompareAndSwap32(c, exc, dest);
|
|
return old;
|
|
}
|
|
#elif defined(LLVM_ON_WIN32)
|
|
#warning Memory fence implementation requires Windows 2003 or later.
|
|
inline void MemoryFence() {
|
|
MemoryBarrier();
|
|
}
|
|
|
|
typedef volatile long cas_flag;
|
|
inline cas_flag CompareAndSwap(cas_flag* dest, cas_flag exc, cas_flag c) {
|
|
return _InterlockedCompareExchange(dest, exc, c);
|
|
}
|
|
#else
|
|
#error No memory atomics implementation for your platform!
|
|
#endif
|
|
|
|
}
|
|
}
|
|
|
|
#endif |