aboutsummaryrefslogtreecommitdiffstats
path: root/include/llvm/System
diff options
context:
space:
mode:
authorOwen Anderson <resistor@mac.com>2009-05-14 05:54:36 +0000
committerOwen Anderson <resistor@mac.com>2009-05-14 05:54:36 +0000
commitc082324e1940851f8db720d064d2b31915910d4e (patch)
tree939bb10dd02e7173abf2a7312ea5bc83b9f0bac9 /include/llvm/System
parenta7c9deaa2b1df30808db376bdfcba7f2e54e59d1 (diff)
downloadexternal_llvm-c082324e1940851f8db720d064d2b31915910d4e.zip
external_llvm-c082324e1940851f8db720d064d2b31915910d4e.tar.gz
external_llvm-c082324e1940851f8db720d064d2b31915910d4e.tar.bz2
Add an Atomic.h to the System library, for providing a platform independent API
to low-level sync operations. The only one present at the moment is MemoryFence(), and only for the platforms for which I could easily discern the proper way to do it. If your favorite platform isn't represented, patches are welcome! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@71770 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/System')
-rw-r--r--include/llvm/System/Atomic.h45
1 files changed, 45 insertions, 0 deletions
diff --git a/include/llvm/System/Atomic.h b/include/llvm/System/Atomic.h
new file mode 100644
index 0000000..7db31d5
--- /dev/null
+++ b/include/llvm/System/Atomic.h
@@ -0,0 +1,45 @@
+//===- 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.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Config/config.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
+ return;
+#elif __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1)
+ __sync_synchronize();
+#elif defined(__APPLE__)
+ OSMemoryBarrier();
+#elif defined(LLVM_ON_WIN32)
+#warning Memory fence implementation requires Windows 2003 or later.
+ MemoryBarrier();
+#else
+#warning No memory fence implementation found for you platform!
+#endif
+ }
+ }
+}
+
+#endif \ No newline at end of file