Author: enrico Date: Fri Oct 18 13:57:49 2013 New Revision: 192993 URL: http://llvm.org/viewvc/llvm-project?rev=192993&view=rev Log: <rdar://problem/15182550>
Removing Host/Atomic.h This header file was not being copied as part of our public API headers and this in turn was causing any plugin to link against LLDB.framework, since SharingPtr.h depends on it Out of several possible options to fix this issue, the cleanest one is to revert LLDB to use std::atomic<>, as we are a C++11 project and should take advantage of it The original rationale for going from std::atomic to Host/Atomic.h was that MSVC++ fails to link in CLR mode when std::atomic is used This is a very Visual Studio/.net specific issue, which hopefully will be fixed Until them, to allow Windows development to proceed, we are going with a targeted solution where we #ifdef include the Windows specific calls, and let everyone else use the proper atomic support, as should be If there is an unavoidable need for a LLDB-specific atomic header, the right way to go at it would be to make an API/lldb-atomic.h header and #ifdef the Windows dependency there The FormatManager should not need to conditionalize use of std::atomic<>, as other parts of the LLDB internals are successfully using atomic (Address and IRExecutionUnit), so this Win-specific hack is limited to SharingPtr Removed: lldb/trunk/include/lldb/Host/Atomic.h Modified: lldb/trunk/include/lldb/DataFormatters/FormatManager.h lldb/trunk/include/lldb/Utility/SharingPtr.h lldb/trunk/source/Utility/SharingPtr.cpp Modified: lldb/trunk/include/lldb/DataFormatters/FormatManager.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/DataFormatters/FormatManager.h?rev=192993&r1=192992&r2=192993&view=diff ============================================================================== --- lldb/trunk/include/lldb/DataFormatters/FormatManager.h (original) +++ lldb/trunk/include/lldb/DataFormatters/FormatManager.h Fri Oct 18 13:57:49 2013 @@ -23,7 +23,7 @@ #include "lldb/DataFormatters/TypeCategory.h" #include "lldb/DataFormatters/TypeCategoryMap.h" -#include "lldb/Host/Atomic.h" +#include <atomic> namespace lldb_private { @@ -199,7 +199,7 @@ public: void Changed () { - AtomicIncrement((cas_flag*)&m_last_revision); + ++m_last_revision; m_format_cache.Clear (); } @@ -216,7 +216,7 @@ public: private: FormatCache m_format_cache; NamedSummariesMap m_named_summaries_map; - uint32_t m_last_revision; + std::atomic<uint32_t> m_last_revision; TypeCategoryMap m_categories_map; ConstString m_default_category_name; Removed: lldb/trunk/include/lldb/Host/Atomic.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/Atomic.h?rev=192992&view=auto ============================================================================== --- lldb/trunk/include/lldb/Host/Atomic.h (original) +++ lldb/trunk/include/lldb/Host/Atomic.h (removed) @@ -1,47 +0,0 @@ -//===-- Atomic.h ------------------------------------------------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#ifndef liblldb_Atomic_h_ -#define liblldb_Atomic_h_ - -#ifdef _MSC_VER -#include <intrin.h> -#endif - -namespace lldb_private { - -#ifdef _MSC_VER -typedef long cas_flag; -#else -typedef uint32_t cas_flag; -#endif - -inline cas_flag -AtomicIncrement(volatile cas_flag* ptr) -{ -#ifdef _MSC_VER - return _InterlockedIncrement(ptr); -#else - return __sync_add_and_fetch(ptr, 1); -#endif -} - -inline cas_flag -AtomicDecrement(volatile cas_flag* ptr) -{ -#ifdef _MSC_VER - return _InterlockedDecrement(ptr); -#else - return __sync_add_and_fetch(ptr, -1); -#endif -} - -} - -#endif Modified: lldb/trunk/include/lldb/Utility/SharingPtr.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Utility/SharingPtr.h?rev=192993&r1=192992&r2=192993&view=diff ============================================================================== --- lldb/trunk/include/lldb/Utility/SharingPtr.h (original) +++ lldb/trunk/include/lldb/Utility/SharingPtr.h Fri Oct 18 13:57:49 2013 @@ -12,7 +12,15 @@ #include <algorithm> #include <memory> -#include "lldb/Host/Atomic.h" + +// Microsoft Visual C++ currently does not enable std::atomic to work +// in CLR mode - as such we need to "hack around it" for MSVC++ builds only +// using Windows specific instrinsics instead of the C++11 atomic support +#ifdef _MSC_VER +#include <intrin.h> +#else +#include <atomic> +#endif //#define ENABLE_SP_LOGGING 1 // DON'T CHECK THIS LINE IN UNLESS COMMENTED OUT #if defined (ENABLE_SP_LOGGING) @@ -25,27 +33,17 @@ namespace lldb_private { namespace imp { -template <class T> -inline T -increment(T& t) -{ - return AtomicIncrement((cas_flag*)&t); -} - -template <class T> -inline T -decrement(T& t) -{ - return AtomicDecrement((cas_flag*)&t); -} - class shared_count { shared_count(const shared_count&); shared_count& operator=(const shared_count&); protected: +#ifdef _MSC_VER long shared_owners_; +#else + std::atomic<long> shared_owners_; +#endif virtual ~shared_count(); private: virtual void on_zero_shared() = 0; @@ -593,14 +591,22 @@ private: void lldb_private::ReferenceCountedBase<T>::add_shared() { - imp::increment(shared_owners_); +#ifdef _MSC_VER + _InterlockedIncrement(&shared_owners_); +#else + ++shared_owners_; +#endif } template <class T> void lldb_private::ReferenceCountedBase<T>::release_shared() { - if (imp::decrement(shared_owners_) == -1) +#ifdef _MSC_VER + if (_InterlockedDecrement(&shared_owners_) == -1) +#else + if (--shared_owners_ == -1) +#endif delete static_cast<T*>(this); } Modified: lldb/trunk/source/Utility/SharingPtr.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Utility/SharingPtr.cpp?rev=192993&r1=192992&r2=192993&view=diff ============================================================================== --- lldb/trunk/source/Utility/SharingPtr.cpp (original) +++ lldb/trunk/source/Utility/SharingPtr.cpp Fri Oct 18 13:57:49 2013 @@ -138,13 +138,21 @@ namespace imp void shared_count::add_shared() { - increment(shared_owners_); +#ifdef _MSC_VER + _InterlockedIncrement(&shared_owners_); +#else + ++shared_owners_; +#endif } void shared_count::release_shared() { - if (decrement(shared_owners_) == -1) +#ifdef _MSC_VER + if (_InterlockedDecrement(&shared_owners_) == -1) +#else + if (--shared_owners_ == -1) +#endif { on_zero_shared(); delete this; _______________________________________________ lldb-commits mailing list lldb-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits