<div>don't inlcude platform dependent header here. please include "llvm/Support/DataTypes.h" instead.</div>
<div> </div>
<div>Also, please update CMakeLists file also to add Atomic.cpp.<br><br></div>
<div class="gmail_quote">On Thu, May 21, 2009 at 2:26 AM, Owen Anderson <span dir="ltr"><<a href="mailto:resistor@mac.com">resistor@mac.com</a>></span> wrote:<br>
<blockquote style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" class="gmail_quote">Author: resistor<br>Date: Wed May 20 13:26:15 2009<br>New Revision: 72174<br><br>URL: <a href="http://llvm.org/viewvc/llvm-project?rev=72174&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=72174&view=rev</a><br>
Log:<br>Move atomic operations' definitions out of line. While this seems kind of silly,<br>all kinds of problems caused by including windows.h and/or config.h in an LLVM header.<br><br>Added:<br> llvm/trunk/lib/System/Atomic.cpp<br>
Modified:<br> llvm/trunk/include/llvm/System/Atomic.h<br><br>Modified: llvm/trunk/include/llvm/System/Atomic.h<br>URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/System/Atomic.h?rev=72174&r1=72173&r2=72174&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/System/Atomic.h?rev=72174&r1=72173&r2=72174&view=diff</a><br>
<br>==============================================================================<br>--- llvm/trunk/include/llvm/System/Atomic.h (original)<br>+++ llvm/trunk/include/llvm/System/Atomic.h Wed May 20 13:26:15 2009<br>@@ -14,75 +14,16 @@<br>
#ifndef LLVM_SYSTEM_ATOMIC_H<br> #define LLVM_SYSTEM_ATOMIC_H<br><br>-#include "llvm/Config/config.h"<br>-<br>-#if defined(_MSC_VER)<br>-#define NOMINMAX<br>-#include <windows.h><br>-#endif<br>-<br>+#include <stdint.h><br>
<br> namespace llvm {<br> namespace sys {<br>-<br>- inline void MemoryFence() {<br>-#if LLVM_MULTITHREADED==0<br>- return;<br>-#else<br>-# if defined(__GNUC__)<br>- __sync_synchronize();<br>-# elif defined(_MSC_VER)<br>
- MemoryBarrier();<br>-# else<br>-# error No memory fence implementation for your platform!<br>-# endif<br>-#endif<br>-}<br>-<br>-#if LLVM_MULTITHREADED==0<br>- typedef unsigned long cas_flag;<br>- template<typename T><br>
- inline T CompareAndSwap(volatile T* dest,<br>- T exc, T c) {<br>- T result = *dest;<br>- if (result == c)<br>- *dest = exc;<br>- return result;<br>- }<br>-#elif defined(__GNUC__)<br>
- typedef unsigned long cas_flag;<br>- template<typename T><br>- inline T CompareAndSwap(volatile T* ptr,<br>- T new_value,<br>- T old_value) {<br>- return __sync_val_compare_and_swap(ptr, old_value, new_value);<br>
- }<br>-#elif defined(_MSC_VER)<br>- typedef LONG cas_flag;<br>- template<typename T><br>- inline T CompareAndSwap(volatile T* ptr,<br>- T new_value,<br>- T old_value) {<br>
- if (sizeof(T) == 4)<br>- return InterlockedCompareExchange(ptr, new_value, old_value);<br>- else if (sizeof(T) == 8)<br>- return InterlockedCompareExchange64(ptr, new_value, old_value);<br>- else<br>
- assert(0 && "Unsupported compare-and-swap size!");<br>- }<br>-<br>- template<typename T><br>- inline T* CompareAndSwap<T*>(volatile T** ptr,<br>- T* new_value,<br>
- T* old_value) {<br>- return InterlockedCompareExchangePtr(ptr, new_value, old_value);<br>- }<br>-<br>-<br>-#else<br>-# error No compare-and-swap implementation for your platform!<br>
-#endif<br>+ void MemoryFence();<br><br>+ typedef uint32_t cas_flag;<br>+ cas_flag CompareAndSwap(volatile cas_flag* ptr,<br>+ cas_flag new_value,<br>+ cas_flag old_value);<br>
}<br> }<br><br><br>Added: llvm/trunk/lib/System/Atomic.cpp<br>URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/System/Atomic.cpp?rev=72174&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/System/Atomic.cpp?rev=72174&view=auto</a><br>
<br>==============================================================================<br>--- llvm/trunk/lib/System/Atomic.cpp (added)<br>+++ llvm/trunk/lib/System/Atomic.cpp Wed May 20 13:26:15 2009<br>@@ -0,0 +1,52 @@<br>+//===-- Atomic.cpp - Atomic Operations --------------------------*- C++ -*-===//<br>
+//<br>+// The LLVM Compiler Infrastructure<br>+//<br>+// This file is distributed under the University of Illinois Open Source<br>+// License. See LICENSE.TXT for details.<br>+//<br>+//===----------------------------------------------------------------------===//<br>
+//<br>+// This header file implements atomic operations.<br>+//<br>+//===----------------------------------------------------------------------===//<br>+<br>+#include "llvm/System/Atomic.h"<br>+#include "llvm/Config/config.h"<br>
+<br>+using namespace llvm;<br>+<br>+#if defined(_MSC_VER)<br>+#include <windows.h><br>+#endif<br>+<br>+void sys::MemoryFence() {<br>+#if LLVM_MULTITHREADED==0<br>+ return;<br>+#else<br>+# if defined(__GNUC__)<br>
+ __sync_synchronize();<br>+# elif defined(_MSC_VER)<br>+ MemoryBarrier();<br>+# else<br>+# error No memory fence implementation for your platform!<br>+# endif<br>+#endif<br>+}<br>+<br>+sys::cas_flag sys::CompareAndSwap(volatile sys::cas_flag* ptr,<br>
+ sys::cas_flag new_value,<br>+ sys::cas_flag old_value) {<br>+#if LLVM_MULTITHREADED==0<br>+ T result = *dest;<br>+ if (result == c)<br>+ *dest = exc;<br>
+ return result;<br>+#elif defined(__GNUC__)<br>+ return __sync_val_compare_and_swap(ptr, old_value, new_value);<br>+#elif defined(_MSC_VER)<br>+ return InterlockedCompareExchange(ptr, new_value, old_value);<br>+#else<br>
+# error No compare-and-swap implementation for your platform!<br>+#endif<br>+}<br>\ No newline at end of file<br><br><br>_______________________________________________<br>llvm-commits mailing list<br><a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br></blockquote></div><br><br clear="all">
<div></div><br>-- <br>-Howard<br>