[llvm-commits] [llvm] r71795 - /llvm/trunk/include/llvm/System/Atomic.h
Nick Lewycky
nicholas at mxc.ca
Thu May 14 20:08:59 PDT 2009
Owen Anderson wrote:
> Author: resistor
> Date: Thu May 14 16:24:15 2009
> New Revision: 71795
>
> URL: http://llvm.org/viewvc/llvm-project?rev=71795&view=rev
> Log:
> Add CompareAndSwap.
>
> Modified:
> llvm/trunk/include/llvm/System/Atomic.h
>
> Modified: llvm/trunk/include/llvm/System/Atomic.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/System/Atomic.h?rev=71795&r1=71794&r2=71795&view=diff
>
> ==============================================================================
> --- llvm/trunk/include/llvm/System/Atomic.h (original)
> +++ llvm/trunk/include/llvm/System/Atomic.h Thu May 14 16:24:15 2009
> @@ -11,34 +11,70 @@
> //
> //===----------------------------------------------------------------------===//
>
> +#ifndef LLVM_SYSTEM_ATOMIC_H
> +#define LLVM_SYSTEM_ATOMIC_H
> +
> #include "llvm/Config/config.h"
> +#include <stdint.h>
>
> #ifdef __APPLE__
> -#include <libkern/OSAtomic.h>
> +
> #elif LLVM_ON_WIN32
> #include <windows.h>
> #endif
>
>
> -#ifndef LLVM_SYSTEM_ATOMIC_H
> -#define LLVM_SYSTEM_ATOMIC_H
> -
> namespace llvm {
> namespace sys {
> - inline void MemoryFence() {
> +
> #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 UInt32 cas_flag;
> + inline cas_flag CompareAndSwap(cas_flag* dest, cas_flag exc, cas_flag c) {
> + cas_flag old = *dest;
> + OSCompareAndSwap(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) {
My GCC complains about this.
In file included from
/home/nicholas/llvm-commit/include/llvm/Support/ManagedStatic.h:17,
from BasicAliasAnalysis.cpp:31:
/home/nicholas/llvm-commit/include/llvm/System/Atomic.h:49: warning:
type qualifiers ignored on function return type
Because nearly everything uses ManagedStatic this shows up everywhere.
Please fix.
> + return _InterlockedCompareExchange(dest, exc, c);
> + }
> #else
> -#warning No memory fence implementation found for you platform!
> +#error No memory atomics implementation for your platform!
> #endif
> - }
> +
> }
> }
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
More information about the llvm-commits
mailing list