diff options
139 files changed, 1680 insertions, 1806 deletions
diff --git a/lldb/include/lldb/Breakpoint/BreakpointLocationList.h b/lldb/include/lldb/Breakpoint/BreakpointLocationList.h index 81526089b42..1fbfa43a40f 100644 --- a/lldb/include/lldb/Breakpoint/BreakpointLocationList.h +++ b/lldb/include/lldb/Breakpoint/BreakpointLocationList.h @@ -13,13 +13,13 @@ // C Includes // C++ Includes #include <map> +#include <mutex> #include <vector> // Other libraries and framework includes // Project includes #include "lldb/lldb-private.h" #include "lldb/Core/Address.h" -#include "lldb/Host/Mutex.h" #include "lldb/Utility/Iterable.h" namespace lldb_private { @@ -270,7 +270,7 @@ protected: Breakpoint &m_owner; collection m_locations; // Vector of locations, sorted by ID addr_map m_address_to_location; - mutable Mutex m_mutex; + mutable std::recursive_mutex m_mutex; lldb::break_id_t m_next_id; BreakpointLocationCollection *m_new_location_recorder; diff --git a/lldb/include/lldb/Breakpoint/BreakpointSite.h b/lldb/include/lldb/Breakpoint/BreakpointSite.h index 6cebcab8e2d..27a23527d9f 100644 --- a/lldb/include/lldb/Breakpoint/BreakpointSite.h +++ b/lldb/include/lldb/Breakpoint/BreakpointSite.h @@ -14,12 +14,12 @@ // C++ Includes #include <list> +#include <mutex> // Other libraries and framework includes // Project includes #include "lldb/lldb-forward.h" -#include "lldb/Host/Mutex.h" #include "lldb/Core/UserID.h" #include "lldb/Breakpoint/StoppointLocation.h" #include "lldb/Breakpoint/BreakpointLocationCollection.h" @@ -297,7 +297,7 @@ private: // Consider adding an optimization where if there is only one // owner, we don't store a list. The usual case will be only one owner... BreakpointLocationCollection m_owners; ///< This has the BreakpointLocations that share this breakpoint site. - Mutex m_owners_mutex; ///< This mutex protects the owners collection. + std::recursive_mutex m_owners_mutex; ///< This mutex protects the owners collection. static lldb::break_id_t GetNextID(); diff --git a/lldb/include/lldb/Breakpoint/BreakpointSiteList.h b/lldb/include/lldb/Breakpoint/BreakpointSiteList.h index d7bb8fd777e..e681aa3599f 100644 --- a/lldb/include/lldb/Breakpoint/BreakpointSiteList.h +++ b/lldb/include/lldb/Breakpoint/BreakpointSiteList.h @@ -12,12 +12,13 @@ // C Includes // C++ Includes -#include <map> #include <functional> +#include <map> +#include <mutex> + // Other libraries and framework includes // Project includes #include "lldb/Breakpoint/BreakpointSite.h" -#include "lldb/Host/Mutex.h" namespace lldb_private { @@ -189,16 +190,17 @@ public: size_t GetSize() const { - Mutex::Locker locker(m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); return m_bp_site_list.size(); } bool IsEmpty() const { - Mutex::Locker locker(m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); return m_bp_site_list.empty(); } + protected: typedef std::map<lldb::addr_t, lldb::BreakpointSiteSP> collection; @@ -208,7 +210,7 @@ protected: collection::const_iterator GetIDConstIterator(lldb::break_id_t breakID) const; - mutable Mutex m_mutex; + mutable std::recursive_mutex m_mutex; collection m_bp_site_list; // The breakpoint site list. }; diff --git a/lldb/include/lldb/Core/Broadcaster.h b/lldb/include/lldb/Core/Broadcaster.h index 11dfe44be74..33172fa7378 100644 --- a/lldb/include/lldb/Core/Broadcaster.h +++ b/lldb/include/lldb/Core/Broadcaster.h @@ -15,6 +15,7 @@ #include <functional> #include <list> #include <map> +#include <mutex> #include <string> #include <vector> @@ -22,7 +23,6 @@ // Project includes #include "lldb/lldb-private.h" #include "lldb/Core/ConstString.h" -#include "lldb/Host/Mutex.h" namespace lldb_private { @@ -126,8 +126,8 @@ private: typedef std::set<lldb::ListenerSP> listener_collection; collection m_event_map; listener_collection m_listeners; - - Mutex m_manager_mutex; + + mutable std::recursive_mutex m_manager_mutex; // A couple of comparator classes for find_if: @@ -625,7 +625,7 @@ protected: Broadcaster &m_broadcaster; ///< The broadcsater that this implements event_names_map m_event_names; ///< Optionally define event names for readability and logging for each event bit collection m_listeners; ///< A list of Listener / event_mask pairs that are listening to this broadcaster. - Mutex m_listeners_mutex; ///< A mutex that protects \a m_listeners. + std::recursive_mutex m_listeners_mutex; ///< A mutex that protects \a m_listeners. std::vector<lldb::ListenerSP> m_hijacking_listeners; // A simple mechanism to intercept events from a broadcaster std::vector<uint32_t> m_hijacking_masks; // At some point we may want to have a stack or Listener // collections, but for now this is just for private hijacking. diff --git a/lldb/include/lldb/Core/Communication.h b/lldb/include/lldb/Core/Communication.h index d29aaca9c2e..8913f1631a8 100644 --- a/lldb/include/lldb/Core/Communication.h +++ b/lldb/include/lldb/Core/Communication.h @@ -13,6 +13,7 @@ // C Includes // C++ Includes #include <atomic> +#include <mutex> #include <string> // Other libraries and framework includes @@ -21,7 +22,6 @@ #include "lldb/Core/Broadcaster.h" #include "lldb/Core/Error.h" #include "lldb/Host/HostThread.h" -#include "lldb/Host/Mutex.h" #include "lldb/lldb-private.h" namespace lldb_private { @@ -358,10 +358,10 @@ protected: HostThread m_read_thread; ///< The read thread handle in case we need to cancel the thread. std::atomic<bool> m_read_thread_enabled; std::atomic<bool> m_read_thread_did_exit; - std::string m_bytes; ///< A buffer to cache bytes read in the ReadThread function. - Mutex m_bytes_mutex; ///< A mutex to protect multi-threaded access to the cached bytes. - Mutex m_write_mutex; ///< Don't let multiple threads write at the same time... - Mutex m_synchronize_mutex; + std::string m_bytes; ///< A buffer to cache bytes read in the ReadThread function. + std::recursive_mutex m_bytes_mutex; ///< A mutex to protect multi-threaded access to the cached bytes. + std::mutex m_write_mutex; ///< Don't let multiple threads write at the same time... + std::mutex m_synchronize_mutex; ReadThreadBytesReceived m_callback; void *m_callback_baton; bool m_close_on_eof; diff --git a/lldb/include/lldb/Core/History.h b/lldb/include/lldb/Core/History.h index fbb7bd8b0c1..164d1bfb651 100644 --- a/lldb/include/lldb/Core/History.h +++ b/lldb/include/lldb/Core/History.h @@ -14,13 +14,13 @@ #include <stdint.h> // C++ Includes +#include <mutex> #include <stack> #include <string> // Other libraries and framework includes // Project includes #include "lldb/lldb-public.h" -#include "lldb/Host/Mutex.h" namespace lldb_private { @@ -34,11 +34,7 @@ class HistorySource public: typedef const void * HistoryEvent; - HistorySource () : - m_mutex (Mutex::eMutexTypeRecursive), - m_events () - { - } + HistorySource() : m_mutex(), m_events() {} virtual ~HistorySource() @@ -50,20 +46,20 @@ public: // onto the end of the history stack. virtual HistoryEvent - CreateHistoryEvent () = 0; - + CreateHistoryEvent () = 0; + virtual void DeleteHistoryEvent (HistoryEvent event) = 0; - + virtual void DumpHistoryEvent (Stream &strm, HistoryEvent event) = 0; virtual size_t GetHistoryEventCount() = 0; - + virtual HistoryEvent GetHistoryEventAtIndex (uint32_t idx) = 0; - + virtual HistoryEvent GetCurrentHistoryEvent () = 0; @@ -71,16 +67,16 @@ public: virtual int CompareHistoryEvents (const HistoryEvent lhs, const HistoryEvent rhs) = 0; - + virtual bool IsCurrentHistoryEvent (const HistoryEvent event) = 0; private: typedef std::stack<HistoryEvent> collection; - Mutex m_mutex; + std::recursive_mutex m_mutex; collection m_events; - + DISALLOW_COPY_AND_ASSIGN (HistorySource); }; diff --git a/lldb/include/lldb/Core/IOHandler.h b/lldb/include/lldb/Core/IOHandler.h index 3eba1c3cc9d..63b931cdde5 100644 --- a/lldb/include/lldb/Core/IOHandler.h +++ b/lldb/include/lldb/Core/IOHandler.h @@ -15,6 +15,7 @@ // C++ Includes #include <memory> +#include <mutex> #include <string> #include <vector> @@ -709,75 +710,70 @@ namespace lldb_private { class IOHandlerStack { public: - IOHandlerStack () : - m_stack(), - m_mutex(Mutex::eMutexTypeRecursive), - m_top (nullptr) - { - } - + IOHandlerStack() : m_stack(), m_mutex(), m_top(nullptr) {} + ~IOHandlerStack() = default; - + size_t - GetSize () const + GetSize() const { - Mutex::Locker locker (m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); return m_stack.size(); } - + void - Push (const lldb::IOHandlerSP& sp) + Push(const lldb::IOHandlerSP &sp) { if (sp) { - Mutex::Locker locker (m_mutex); - sp->SetPopped (false); - m_stack.push_back (sp); + std::lock_guard<std::recursive_mutex> guard(m_mutex); + sp->SetPopped(false); + m_stack.push_back(sp); // Set m_top the non-locking IsTop() call m_top = sp.get(); } } - + bool - IsEmpty () const + IsEmpty() const { - Mutex::Locker locker (m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); return m_stack.empty(); } - + lldb::IOHandlerSP - Top () + Top() { lldb::IOHandlerSP sp; { - Mutex::Locker locker (m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); if (!m_stack.empty()) sp = m_stack.back(); } return sp; } - + void - Pop () + Pop() { - Mutex::Locker locker (m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); if (!m_stack.empty()) { - lldb::IOHandlerSP sp (m_stack.back()); + lldb::IOHandlerSP sp(m_stack.back()); m_stack.pop_back(); - sp->SetPopped (true); + sp->SetPopped(true); } // Set m_top the non-locking IsTop() call m_top = (m_stack.empty() ? nullptr : m_stack.back().get()); } - Mutex & + std::recursive_mutex & GetMutex() { return m_mutex; } - + bool IsTop (const lldb::IOHandlerSP &io_handler_sp) const { @@ -785,13 +781,12 @@ namespace lldb_private { } bool - CheckTopIOHandlerTypes (IOHandler::Type top_type, IOHandler::Type second_top_type) + CheckTopIOHandlerTypes(IOHandler::Type top_type, IOHandler::Type second_top_type) { - Mutex::Locker locker (m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); const size_t num_io_handlers = m_stack.size(); - return (num_io_handlers >= 2 && - m_stack[num_io_handlers-1]->GetType() == top_type && - m_stack[num_io_handlers-2]->GetType() == second_top_type); + return (num_io_handlers >= 2 && m_stack[num_io_handlers - 1]->GetType() == top_type && + m_stack[num_io_handlers - 2]->GetType() == second_top_type); } ConstString @@ -818,9 +813,9 @@ namespace lldb_private { protected: typedef std::vector<lldb::IOHandlerSP> collection; collection m_stack; - mutable Mutex m_mutex; + mutable std::recursive_mutex m_mutex; IOHandler *m_top; - + private: DISALLOW_COPY_AND_ASSIGN (IOHandlerStack); }; diff --git a/lldb/include/lldb/Core/Listener.h b/lldb/include/lldb/Core/Listener.h index 2e7f7f5269b..1057cf35c6d 100644 --- a/lldb/include/lldb/Core/Listener.h +++ b/lldb/include/lldb/Core/Listener.h @@ -14,6 +14,7 @@ // C++ Includes #include <list> #include <map> +#include <mutex> #include <string> #include <vector> @@ -175,7 +176,7 @@ private: std::string m_name; broadcaster_collection m_broadcasters; - Mutex m_broadcasters_mutex; // Protects m_broadcasters + std::recursive_mutex m_broadcasters_mutex; // Protects m_broadcasters event_collection m_events; Mutex m_events_mutex; // Protects m_broadcasters and m_events Condition m_events_condition; diff --git a/lldb/include/lldb/Core/Module.h b/lldb/include/lldb/Core/Module.h index 70c10fd084d..819d7110526 100644 --- a/lldb/include/lldb/Core/Module.h +++ b/lldb/include/lldb/Core/Module.h @@ -13,6 +13,7 @@ // C Includes // C++ Includes #include <atomic> +#include <mutex> #include <string> #include <vector> @@ -22,7 +23,6 @@ #include "lldb/Core/ArchSpec.h" #include "lldb/Core/UUID.h" #include "lldb/Host/FileSpec.h" -#include "lldb/Host/Mutex.h" #include "lldb/Host/TimeValue.h" #include "lldb/Symbol/SymbolContextScope.h" #include "lldb/Symbol/TypeSystem.h" @@ -68,7 +68,7 @@ public: static Module * GetAllocatedModuleAtIndex (size_t idx); - static Mutex * + static std::recursive_mutex & GetAllocationModuleCollectionMutex(); //------------------------------------------------------------------ @@ -986,8 +986,8 @@ public: // SymbolVendor, SymbolFile and ObjectFile member objects should // lock the module mutex to avoid deadlocks. //------------------------------------------------------------------ - Mutex & - GetMutex () const + std::recursive_mutex & + GetMutex() const { return m_mutex; } @@ -1106,7 +1106,7 @@ protected: //------------------------------------------------------------------ // Member Variables //------------------------------------------------------------------ - mutable Mutex m_mutex; ///< A mutex to keep this object happy in multi-threaded environments. + mutable std::recursive_mutex m_mutex; ///< A mutex to keep this object happy in multi-threaded environments. TimeValue m_mod_time; ///< The modification time for this module when it was created. ArchSpec m_arch; ///< The architecture for this module. UUID m_uuid; ///< Each module is assumed to have a unique identifier to help match it up to debug symbols. diff --git a/lldb/include/lldb/Core/ModuleSpec.h b/lldb/include/lldb/Core/ModuleSpec.h index 95de7f37573..245cb2365b2 100644 --- a/lldb/include/lldb/Core/ModuleSpec.h +++ b/lldb/include/lldb/Core/ModuleSpec.h @@ -12,6 +12,7 @@ // C Includes // C++ Includes +#include <mutex> #include <vector> // Other libraries and framework includes @@ -20,7 +21,6 @@ #include "lldb/Core/Stream.h" #include "lldb/Core/UUID.h" #include "lldb/Host/FileSpec.h" -#include "lldb/Host/Mutex.h" #include "lldb/Target/PathMappingList.h" namespace lldb_private { @@ -447,30 +447,24 @@ protected: class ModuleSpecList { public: - ModuleSpecList () : - m_specs(), - m_mutex(Mutex::eMutexTypeRecursive) - { - } + ModuleSpecList() : m_specs(), m_mutex() {} - ModuleSpecList (const ModuleSpecList &rhs) : - m_specs(), - m_mutex(Mutex::eMutexTypeRecursive) + ModuleSpecList(const ModuleSpecList &rhs) : m_specs(), m_mutex() { - Mutex::Locker lhs_locker(m_mutex); - Mutex::Locker rhs_locker(rhs.m_mutex); + std::lock_guard<std::recursive_mutex> lhs_guard(m_mutex); + std::lock_guard<std::recursive_mutex> rhs_guard(rhs.m_mutex); m_specs = rhs.m_specs; } ~ModuleSpecList() = default; ModuleSpecList & - operator = (const ModuleSpecList &rhs) + operator=(const ModuleSpecList &rhs) { if (this != &rhs) { - Mutex::Locker lhs_locker(m_mutex); - Mutex::Locker rhs_locker(rhs.m_mutex); + std::lock_guard<std::recursive_mutex> lhs_guard(m_mutex); + std::lock_guard<std::recursive_mutex> rhs_guard(rhs.m_mutex); m_specs = rhs.m_specs; } return *this; @@ -479,29 +473,29 @@ public: size_t GetSize() const { - Mutex::Locker locker(m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); return m_specs.size(); } void - Clear () + Clear() { - Mutex::Locker locker(m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); m_specs.clear(); } void - Append (const ModuleSpec &spec) + Append(const ModuleSpec &spec) { - Mutex::Locker locker(m_mutex); - m_specs.push_back (spec); + std::lock_guard<std::recursive_mutex> guard(m_mutex); + m_specs.push_back(spec); } void - Append (const ModuleSpecList &rhs) + Append(const ModuleSpecList &rhs) { - Mutex::Locker lhs_locker(m_mutex); - Mutex::Locker rhs_locker(rhs.m_mutex); + std::lock_guard<std::recursive_mutex> lhs_guard(m_mutex); + std::lock_guard<std::recursive_mutex> rhs_guard(rhs.m_mutex); m_specs.insert(m_specs.end(), rhs.m_specs.begin(), rhs.m_specs.end()); } @@ -514,9 +508,9 @@ public: } bool - GetModuleSpecAtIndex (size_t i, ModuleSpec &module_spec) const + GetModuleSpecAtIndex(size_t i, ModuleSpec &module_spec) const { - Mutex::Locker locker(m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); if (i < m_specs.size()) { module_spec = m_specs[i]; @@ -527,11 +521,11 @@ public: } bool - FindMatchingModuleSpec (const ModuleSpec &module_spec, ModuleSpec &match_module_spec) const + FindMatchingModuleSpec(const ModuleSpec &module_spec, ModuleSpec &match_module_spec) const { - Mutex::Locker locker(m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); bool exact_arch_match = true; - for (auto spec: m_specs) + for (auto spec : m_specs) { if (spec.Matches(module_spec, exact_arch_match)) { @@ -539,12 +533,12 @@ public: return true; } } - + // If there was an architecture, retry with a compatible arch if (module_spec.GetArchitecturePtr()) { exact_arch_match = false; - for (auto spec: m_specs) + for (auto spec : m_specs) { if (spec.Matches(module_spec, exact_arch_match)) { @@ -556,41 +550,41 @@ public: match_module_spec.Clear(); return false; } - + size_t - FindMatchingModuleSpecs (const ModuleSpec &module_spec, ModuleSpecList &matching_list) const + FindMatchingModuleSpecs(const ModuleSpec &module_spec, ModuleSpecList &matching_list) const { - Mutex::Locker locker(m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); bool exact_arch_match = true; const size_t initial_match_count = matching_list.GetSize(); - for (auto spec: m_specs) + for (auto spec : m_specs) { if (spec.Matches(module_spec, exact_arch_match)) - matching_list.Append (spec); + matching_list.Append(spec); } - + // If there was an architecture, retry with a compatible arch if no matches were found if (module_spec.GetArchitecturePtr() && (initial_match_count == matching_list.GetSize())) { exact_arch_match = false; - for (auto spec: m_specs) + for (auto spec : m_specs) { if (spec.Matches(module_spec, exact_arch_match)) - matching_list.Append (spec); + matching_list.Append(spec); } } return matching_list.GetSize() - initial_match_count; } void - Dump (Stream &strm) + Dump(Stream &strm) { - Mutex::Locker locker(m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); uint32_t idx = 0; - for (auto spec: m_specs) + for (auto spec : m_specs) { strm.Printf("[%u] ", idx); - spec.Dump (strm); + spec.Dump(strm); strm.EOL(); ++idx; } @@ -599,7 +593,7 @@ public: protected: typedef std::vector<ModuleSpec> collection; ///< The module collection type. collection m_specs; ///< The collection of modules. - mutable Mutex m_mutex; + mutable std::recursive_mutex m_mutex; }; } // namespace lldb_private diff --git a/lldb/include/lldb/Core/StreamCallback.h b/lldb/include/lldb/Core/StreamCallback.h index e5a9da7512b..9e91eb94a74 100644 --- a/lldb/include/lldb/Core/StreamCallback.h +++ b/lldb/include/lldb/Core/StreamCallback.h @@ -10,11 +10,11 @@ #ifndef liblldb_StreamCallback_h_ #define liblldb_StreamCallback_h_ +#include <mutex> #include <string> #include "lldb/Core/Stream.h" #include "lldb/Core/StreamString.h" -#include "lldb/Host/Mutex.h" namespace lldb_private { @@ -37,8 +37,8 @@ private: lldb::LogOutputCallback m_callback; void *m_baton; collection m_accumulated_data; - Mutex m_collection_mutex; - + std::mutex m_collection_mutex; + StreamString &FindStreamForThread(lldb::tid_t cur_tid); }; diff --git a/lldb/include/lldb/Core/StreamTee.h b/lldb/include/lldb/Core/StreamTee.h index 7ab619b3bb7..6059e0e1f8e 100644 --- a/lldb/include/lldb/Core/StreamTee.h +++ b/lldb/include/lldb/Core/StreamTee.h @@ -12,50 +12,37 @@ #include <limits.h> +#include <mutex> + #include "lldb/Core/Stream.h" -#include "lldb/Host/Mutex.h" namespace lldb_private { class StreamTee : public Stream { public: - StreamTee () : - Stream (), - m_streams_mutex (Mutex::eMutexTypeRecursive), - m_streams () - { - } + StreamTee() : Stream(), m_streams_mutex(), m_streams() {} - StreamTee (lldb::StreamSP &stream_sp): - Stream (), - m_streams_mutex (Mutex::eMutexTypeRecursive), - m_streams () + StreamTee(lldb::StreamSP &stream_sp) : Stream(), m_streams_mutex(), m_streams() { // No need to lock mutex during construction if (stream_sp) - m_streams.push_back (stream_sp); + m_streams.push_back(stream_sp); } - - StreamTee (lldb::StreamSP &stream_sp, lldb::StreamSP &stream_2_sp) : - Stream (), - m_streams_mutex (Mutex::eMutexTypeRecursive), - m_streams () + StreamTee(lldb::StreamSP &stream_sp, lldb::StreamSP &stream_2_sp) : Stream(), m_streams_mutex(), m_streams() { // No need to lock mutex during construction if (stream_sp) - m_streams.push_back (stream_sp); + m_streams.push_back(stream_sp); if (stream_2_sp) - m_streams.push_back (stream_2_sp); + m_streams.push_back(stream_2_sp); } - - StreamTee (const StreamTee &rhs) : - Stream (rhs), - m_streams_mutex (Mutex::eMutexTypeRecursive), - m_streams() // Don't copy until we lock down "rhs" + + StreamTee(const StreamTee &rhs) : Stream(rhs), m_streams_mutex(), m_streams() { - Mutex::Locker locker (rhs.m_streams_mutex); + // Don't copy until we lock down "rhs" + std::lock_guard<std::recursive_mutex> guard(rhs.m_streams_mutex); m_streams = rhs.m_streams; } @@ -64,21 +51,22 @@ public: } StreamTee & - operator = (const StreamTee &rhs) + operator=(const StreamTee &rhs) { - if (this != &rhs) { + if (this != &rhs) + { Stream::operator=(rhs); - Mutex::Locker lhs_locker (m_streams_mutex); - Mutex::Locker rhs_locker (rhs.m_streams_mutex); - m_streams = rhs.m_streams; + std::lock_guard<std::recursive_mutex> lhs_locker(m_streams_mutex); + std::lock_guard<std::recursive_mutex> rhs_locker(rhs.m_streams_mutex); + m_streams = rhs.m_streams; } return *this; } void - Flush () override + Flush() override { - Mutex::Locker locker (m_streams_mutex); + std::lock_guard<std::recursive_mutex> guard(m_streams_mutex); collection::iterator pos, end; for (pos = m_streams.begin(), end = m_streams.end(); pos != end; ++pos) { @@ -88,17 +76,17 @@ public: // to valid values. Stream *strm = pos->get(); if (strm) - strm->Flush (); + strm->Flush(); } } size_t - Write (const void *s, size_t length) override + Write(const void *s, size_t length) override { - Mutex::Locker locker (m_streams_mutex); + std::lock_guard<std::recursive_mutex> guard(m_streams_mutex); if (m_streams.empty()) return 0; - + size_t min_bytes_written = SIZE_MAX; collection::iterator pos, end; for (pos = m_streams.begin(), end = m_streams.end(); pos != end; ++pos) @@ -110,7 +98,7 @@ public: Stream *strm = pos->get(); if (strm) { - const size_t bytes_written = strm->Write (s, length); + const size_t bytes_written = strm->Write(s, length); if (min_bytes_written > bytes_written) min_bytes_written = bytes_written; } @@ -121,39 +109,39 @@ public: } size_t - AppendStream (const lldb::StreamSP &stream_sp) + AppendStream(const lldb::StreamSP &stream_sp) { size_t new_idx = m_streams.size(); - Mutex::Locker locker (m_streams_mutex); - m_streams.push_back (stream_sp); + std::lock_guard<std::recursive_mutex> guard(m_streams_mutex); + m_streams.push_back(stream_sp); return new_idx; } size_t - GetNumStreams () const + GetNumStreams() const { size_t result = 0; { - Mutex::Locker locker (m_streams_mutex); + std::lock_guard<std::recursive_mutex> guard(m_streams_mutex); result = m_streams.size(); } return result; } lldb::StreamSP - GetStreamAtIndex (uint32_t idx) + GetStreamAtIndex(uint32_t idx) { lldb::StreamSP stream_sp; - Mutex::Locker locker (m_streams_mutex); + std::lock_guard<std::recursive_mutex> guard(m_streams_mutex); if (idx < m_streams.size()) stream_sp = m_streams[idx]; return stream_sp; } void - SetStreamAtIndex (uint32_t idx, const lldb::StreamSP& stream_sp) + SetStreamAtIndex(uint32_t idx, const lldb::StreamSP &stream_sp) { - Mutex::Locker locker (m_streams_mutex); + std::lock_guard<std::recursive_mutex> guard(m_streams_mutex); // Resize our stream vector as necessary to fit as many streams // as needed. This also allows this class to be used with hard // coded indexes that can be used contain many streams, not all @@ -162,10 +150,10 @@ public: m_streams.resize(idx + 1); m_streams[idx] = stream_sp; } - + protected: typedef std::vector<lldb::StreamSP> collection; - mutable Mutex m_streams_mutex; + mutable std::recursive_mutex m_streams_mutex; collection m_streams; }; diff --git a/lldb/include/lldb/Core/ThreadSafeSTLMap.h b/lldb/include/lldb/Core/ThreadSafeSTLMap.h index 4235edc92ad..4a885ff1a48 100644 --- a/lldb/include/lldb/Core/ThreadSafeSTLMap.h +++ b/lldb/include/lldb/Core/ThreadSafeSTLMap.h @@ -13,11 +13,11 @@ // C Includes // C++ Includes #include <map> +#include <mutex> // Other libraries and framework includes // Project includes #include "lldb/lldb-defines.h" -#include "lldb/Host/Mutex.h" namespace lldb_private { @@ -31,11 +31,7 @@ public: //------------------------------------------------------------------ // Constructors and Destructors //------------------------------------------------------------------ - ThreadSafeSTLMap() : - m_collection (), - m_mutex (Mutex::eMutexTypeRecursive) - { - } + ThreadSafeSTLMap() : m_collection(), m_mutex() {} ~ThreadSafeSTLMap() { @@ -44,22 +40,22 @@ public: bool IsEmpty() const { - Mutex::Locker locker(m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); return m_collection.empty(); } - + void Clear() { - Mutex::Locker locker(m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); return m_collection.clear(); } size_t - Erase (const _Key& key) + Erase(const _Key &key) { - Mutex::Locker locker(m_mutex); - return EraseNoLock (key); + std::lock_guard<std::recursive_mutex> guard(m_mutex); + return EraseNoLock(key); } size_t @@ -69,10 +65,10 @@ public: } bool - GetValueForKey (const _Key& key, _Tp &value) const + GetValueForKey(const _Key &key, _Tp &value) const { - Mutex::Locker locker(m_mutex); - return GetValueForKeyNoLock (key, value); + std::lock_guard<std::recursive_mutex> guard(m_mutex); + return GetValueForKeyNoLock(key, value); } // Call this if you have already manually locked the mutex using the @@ -90,10 +86,10 @@ public: } bool - GetFirstKeyForValue (const _Tp &value, _Key& key) const + GetFirstKeyForValue(const _Tp &value, _Key &key) const { - Mutex::Locker locker(m_mutex); - return GetFirstKeyForValueNoLock (value, key); + std::lock_guard<std::recursive_mutex> guard(m_mutex); + return GetFirstKeyForValueNoLock(value, key); } bool @@ -112,13 +108,10 @@ public: } bool - LowerBound (const _Key& key, - _Key& match_key, - _Tp &match_value, - bool decrement_if_not_equal) const + LowerBound(const _Key &key, _Key &match_key, _Tp &match_value, bool decrement_if_not_equal) const { - Mutex::Locker locker(m_mutex); - return LowerBoundNoLock (key, match_key, match_value, decrement_if_not_equal); + std::lock_guard<std::recursive_mutex> guard(m_mutex); + return LowerBoundNoLock(key, match_key, match_value, decrement_if_not_equal); } bool @@ -149,10 +142,10 @@ public: } void - SetValueForKey (const _Key& key, const _Tp &value) + SetValueForKey(const _Key &key, const _Tp &value) { - Mutex::Locker locker(m_mutex); - SetValueForKeyNoLock (key, value); + std::lock_guard<std::recursive_mutex> guard(m_mutex); + SetValueForKeyNoLock(key, value); } // Call this if you have already manually locked the mutex using the @@ -163,15 +156,15 @@ public: m_collection[key] = value; } - Mutex & - GetMutex () + std::recursive_mutex & + GetMutex() { return m_mutex; } private: collection m_collection; - mutable Mutex m_mutex; + mutable std::recursive_mutex m_mutex; //------------------------------------------------------------------ // For ThreadSafeSTLMap only diff --git a/lldb/include/lldb/Core/ThreadSafeValue.h b/lldb/include/lldb/Core/ThreadSafeValue.h index 42a5a5c6725..cad36a0c163 100644 --- a/lldb/include/lldb/Core/ThreadSafeValue.h +++ b/lldb/include/lldb/Core/ThreadSafeValue.h @@ -11,10 +11,12 @@ #define liblldb_ThreadSafeValue_h_ // C Includes + // C++ Includes +#include <mutex> + // Other libraries and framework includes // Project includes -#include "lldb/Host/Mutex.h" namespace lldb_private { @@ -25,28 +27,20 @@ public: //------------------------------------------------------------------ // Constructors and Destructors //------------------------------------------------------------------ - ThreadSafeValue() : - m_value (), - m_mutex (Mutex::eMutexTypeRecursive) - { - } + ThreadSafeValue() : m_value(), m_mutex() {} - ThreadSafeValue(const T& value) : - m_value (value), - m_mutex (Mutex::eMutexTypeRecursive) - { - } + ThreadSafeValue(const T &value) : m_value(value), m_mutex() {} ~ThreadSafeValue() { } T - GetValue () const + GetValue() const { T value; { - Mutex::Locker locker(m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); value = m_value; } return value; @@ -61,9 +55,9 @@ public: } void - SetValue (const T& value) + SetValue(const T &value) { - Mutex::Locker locker(m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); m_value = value; } @@ -75,15 +69,15 @@ public: m_value = value; } - Mutex & - GetMutex () + std::recursive_mutex & + GetMutex() { return m_mutex; } private: T m_value; - mutable Mutex m_mutex; + mutable std::recursive_mutex m_mutex; //------------------------------------------------------------------ // For ThreadSafeValue only diff --git a/lldb/include/lldb/Core/UserSettingsController.h b/lldb/include/lldb/Core/UserSettingsController.h index 7e72b89ad8e..1c0288574cc 100644 --- a/lldb/include/lldb/Core/UserSettingsController.h +++ b/lldb/include/lldb/Core/UserSettingsController.h @@ -24,7 +24,6 @@ #include "lldb/Core/StringList.h" #include "lldb/Core/Stream.h" #include "lldb/Core/StreamString.h" -#include "lldb/Host/Mutex.h" #include "lldb/Interpreter/OptionValue.h" namespace lldb_private { diff --git a/lldb/include/lldb/Core/ValueObject.h b/lldb/include/lldb/Core/ValueObject.h index fc99278ba2a..b3f6ff82f3d 100644 --- a/lldb/include/lldb/Core/ValueObject.h +++ b/lldb/include/lldb/Core/ValueObject.h @@ -1034,35 +1034,32 @@ protected: class ChildrenManager { public: - ChildrenManager() : - m_mutex(Mutex::eMutexTypeRecursive), - m_children(), - m_children_count(0) - {} - + ChildrenManager() : m_mutex(), m_children(), m_children_count(0) {} + bool - HasChildAtIndex (size_t idx) + HasChildAtIndex(size_t idx) { - Mutex::Locker locker(m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); return (m_children.find(idx) != m_children.end()); } - - ValueObject* - GetChildAtIndex (size_t idx) + + ValueObject * + GetChildAtIndex(size_t idx) { - Mutex::Locker locker(m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); const auto iter = m_children.find(idx); return ((iter == m_children.end()) ? nullptr : iter->second); } - + void - SetChildAtIndex (size_t idx, ValueObject* valobj) + SetChildAtIndex(size_t idx, ValueObject *valobj) { - ChildrenPair pair(idx,valobj); // we do not need to be mutex-protected to make a pair - Mutex::Locker locker(m_mutex); + // we do not need to be mutex-protected to make a pair + ChildrenPair pair(idx, valobj); + std::lock_guard<std::recursive_mutex> guard(m_mutex); m_children.insert(pair); } - + void SetChildrenCount (size_t count) { @@ -1074,20 +1071,20 @@ protected: { return m_children_count; } - + void Clear(size_t new_count = 0) { - Mutex::Locker locker(m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); m_children_count = new_count; m_children.clear(); } - + private: typedef std::map<size_t, ValueObject*> ChildrenMap; typedef ChildrenMap::iterator ChildrenIterator; typedef ChildrenMap::value_type ChildrenPair; - Mutex m_mutex; + std::recursive_mutex m_mutex; ChildrenMap m_children; size_t m_children_count; }; diff --git a/lldb/include/lldb/DataFormatters/FormatCache.h b/lldb/include/lldb/DataFormatters/FormatCache.h index 9f1e078f719..645fbc7ddf1 100644 --- a/lldb/include/lldb/DataFormatters/FormatCache.h +++ b/lldb/include/lldb/DataFormatters/FormatCache.h @@ -13,12 +13,12 @@ // C Includes // C++ Includes #include <map> +#include <mutex> // Other libraries and framework includes // Project includes #include "lldb/lldb-public.h" #include "lldb/Core/ConstString.h" -#include "lldb/Host/Mutex.h" namespace lldb_private { class FormatCache @@ -82,8 +82,8 @@ private: }; typedef std::map<ConstString,Entry> CacheMap; CacheMap m_map; - Mutex m_mutex; - + std::recursive_mutex m_mutex; + uint64_t m_cache_hits; uint64_t m_cache_misses; diff --git a/lldb/include/lldb/DataFormatters/FormatManager.h b/lldb/include/lldb/DataFormatters/FormatManager.h index 24ba5a7f0aa..27dc31d259d 100644 --- a/lldb/include/lldb/DataFormatters/FormatManager.h +++ b/lldb/include/lldb/DataFormatters/FormatManager.h @@ -15,6 +15,7 @@ #include <atomic> #include <initializer_list> #include <map> +#include <mutex> #include <vector> // Other libraries and framework includes @@ -289,7 +290,7 @@ private: std::atomic<uint32_t> m_last_revision; FormatCache m_format_cache; - Mutex m_language_categories_mutex; + std::recursive_mutex m_language_categories_mutex; LanguageCategories m_language_categories_map; NamedSummariesMap m_named_summaries_map; TypeCategoryMap m_categories_map; diff --git a/lldb/include/lldb/DataFormatters/FormattersContainer.h b/lldb/include/lldb/DataFormatters/FormattersContainer.h index dcd08211f19..c4694463b67 100644 --- a/lldb/include/lldb/DataFormatters/FormattersContainer.h +++ b/lldb/include/lldb/DataFormatters/FormattersContainer.h @@ -15,6 +15,7 @@ #include <functional> #include <map> #include <memory> +#include <mutex> #include <string> // Other libraries and framework includes @@ -81,33 +82,27 @@ public: typedef std::map<KeyType, ValueSP> MapType; typedef typename MapType::iterator MapIterator; typedef std::function<bool(KeyType, const ValueSP&)> ForEachCallback; - - FormatMap(IFormatChangeListener* lst) : - m_map(), - m_map_mutex(Mutex::eMutexTypeRecursive), - listener(lst) - { - } - + + FormatMap(IFormatChangeListener *lst) : m_map(), m_map_mutex(), listener(lst) {} + void - Add(KeyType name, - const ValueSP& entry) + Add(KeyType name, const ValueSP &entry) { if (listener) entry->GetRevision() = listener->GetCurrentRevision(); else entry->GetRevision() = 0; - Mutex::Locker locker(m_map_mutex); + std::lock_guard<std::recursive_mutex> guard(m_map_mutex); m_map[name] = entry; if (listener) listener->Changed(); } - + bool - Delete (KeyType name) + Delete(KeyType name) { - Mutex::Locker locker(m_map_mutex); + std::lock_guard<std::recursive_mutex> guard(m_map_mutex); MapIterator iter = m_map.find(name); if (iter == m_map.end()) return false; @@ -116,34 +111,33 @@ public: listener->Changed(); return true; } - + void - Clear () + Clear() { - Mutex::Locker locker(m_map_mutex); + std::lock_guard<std::recursive_mutex> guard(m_map_mutex); m_map.clear(); if (listener) listener->Changed(); } - + bool - Get(KeyType name, - ValueSP& entry) + Get(KeyType name, ValueSP &entry) { - Mutex::Locker locker(m_map_mutex); + std::lock_guard<std::recursive_mutex> guard(m_map_mutex); MapIterator iter = m_map.find(name); if (iter == m_map.end()) return false; entry = iter->second; return true; } - + void - ForEach (ForEachCallback callback) + ForEach(ForEachCallback callback) { if (callback) { - Mutex::Locker locker(m_map_mutex); + std::lock_guard<std::recursive_mutex> guard(m_map_mutex); MapIterator pos, end = m_map.end(); for (pos = m_map.begin(); pos != end; pos++) { @@ -153,17 +147,17 @@ public: } } } - + uint32_t GetCount () { return m_map.size(); } - + ValueSP - GetValueAtIndex (size_t index) + GetValueAtIndex(size_t index) { - Mutex::Locker locker(m_map_mutex); + std::lock_guard<std::recursive_mutex> guard(m_map_mutex); MapIterator iter = m_map.begin(); MapIterator end = m_map.end(); while (index > 0) @@ -175,11 +169,11 @@ public: } return iter->second; } - + KeyType - GetKeyAtIndex (size_t index) + GetKeyAtIndex(size_t index) { - Mutex::Locker locker(m_map_mutex); + std::lock_guard<std::recursive_mutex> guard(m_map_mutex); MapIterator iter = m_map.begin(); MapIterator end = m_map.end(); while (index > 0) @@ -191,24 +185,24 @@ public: } return iter->first; } - + protected: - MapType m_map; - Mutex m_map_mutex; + MapType m_map; + std::recursive_mutex m_map_mutex; IFormatChangeListener* listener; - + MapType& map () { return m_map; } - - Mutex& - mutex () + + std::recursive_mutex & + mutex() { return m_map_mutex; } - + friend class FormattersContainer<KeyType, ValueType>; friend class FormatManager; }; @@ -332,24 +326,23 @@ protected: } bool - Delete_Impl (ConstString type, lldb::RegularExpressionSP *dummy) - { - Mutex& x_mutex = m_format_map.mutex(); - lldb_private::Mutex::Locker locker(x_mutex); - MapIterator pos, end = m_format_map.map().end(); - for (pos = m_format_map.map().begin(); pos != end; pos++) - { - lldb::RegularExpressionSP regex = pos->first; - if ( ::strcmp(type.AsCString(),regex->GetText()) == 0) - { - m_format_map.map().erase(pos); - if (m_format_map.listener) - m_format_map.listener->Changed(); - return true; - } - } - return false; - } + Delete_Impl(ConstString type, lldb::RegularExpressionSP *dummy) + { + std::lock_guard<std::recursive_mutex> guard(m_format_map.mutex()); + MapIterator pos, end = m_format_map.map().end(); + for (pos = m_format_map.map().begin(); pos != end; pos++) + { + lldb::RegularExpressionSP regex = pos->first; + if (::strcmp(type.AsCString(), regex->GetText()) == 0) + { + m_format_map.map().erase(pos); + if (m_format_map.listener) + m_format_map.listener->Changed(); + return true; + } + } + return false; + } bool Get_Impl (ConstString type, MapValueType& entry, ConstString *dummy) @@ -385,36 +378,34 @@ protected: } bool - Get_Impl (ConstString key, MapValueType& value, lldb::RegularExpressionSP *dummy) - { - const char* key_cstr = key.AsCString(); - if (!key_cstr) - return false; - Mutex& x_mutex = m_format_map.mutex(); - lldb_private::Mutex::Locker locker(x_mutex); - MapIterator pos, end = m_format_map.map().end(); - for (pos = m_format_map.map().begin(); pos != end; pos++) - { - lldb::RegularExpressionSP regex = pos->first; - if (regex->Execute(key_cstr)) - { - value = pos->second; - return true; - } - } - return false; + Get_Impl(ConstString key, MapValueType &value, lldb::RegularExpressionSP *dummy) + { + const char *key_cstr = key.AsCString(); + if (!key_cstr) + return false; + std::lock_guard<std::recursive_mutex> guard(m_format_map.mutex()); + MapIterator pos, end = m_format_map.map().end(); + for (pos = m_format_map.map().begin(); pos != end; pos++) + { + lldb::RegularExpressionSP regex = pos->first; + if (regex->Execute(key_cstr)) + { + value = pos->second; + return true; + } + } + return false; } - + bool - GetExact_Impl (ConstString key, MapValueType& value, lldb::RegularExpressionSP *dummy) + GetExact_Impl(ConstString key, MapValueType &value, lldb::RegularExpressionSP *dummy) { - Mutex& x_mutex = m_format_map.mutex(); - lldb_private::Mutex::Locker locker(x_mutex); + std::lock_guard<std::recursive_mutex> guard(m_format_map.mutex()); MapIterator pos, end = m_format_map.map().end(); for (pos = m_format_map.map().begin(); pos != end; pos++) { lldb::RegularExpressionSP regex = pos->first; - if (strcmp(regex->GetText(),key.AsCString()) == 0) + if (strcmp(regex->GetText(), key.AsCString()) == 0) { value = pos->second; return true; diff --git a/lldb/include/lldb/DataFormatters/TypeCategory.h b/lldb/include/lldb/DataFormatters/TypeCategory.h index 075d31d1cf6..c6d7d7b0f87 100644 --- a/lldb/include/lldb/DataFormatters/TypeCategory.h +++ b/lldb/include/lldb/DataFormatters/TypeCategory.h @@ -14,6 +14,7 @@ // C++ Includes #include <initializer_list> #include <memory> +#include <mutex> #include <string> #include <vector> @@ -519,9 +520,9 @@ namespace lldb_private { bool m_enabled; IFormatChangeListener* m_change_listener; - - Mutex m_mutex; - + + std::recursive_mutex m_mutex; + ConstString m_name; std::vector<lldb::LanguageType> m_languages; diff --git a/lldb/include/lldb/DataFormatters/TypeCategoryMap.h b/lldb/include/lldb/DataFormatters/TypeCategoryMap.h index 8afeaf87cec..2cc589809a7 100644 --- a/lldb/include/lldb/DataFormatters/TypeCategoryMap.h +++ b/lldb/include/lldb/DataFormatters/TypeCategoryMap.h @@ -15,6 +15,7 @@ #include <functional> #include <list> #include <map> +#include <mutex> // Other libraries and framework includes // Project includes @@ -131,8 +132,8 @@ namespace lldb_private { return ptr.get() == other.get(); } }; - - Mutex m_map_mutex; + + std::recursive_mutex m_map_mutex; IFormatChangeListener* listener; MapType m_map; @@ -147,12 +148,13 @@ namespace lldb_private { { return m_active_categories; } - - Mutex& mutex () + + std::recursive_mutex & + mutex() { return m_map_mutex; } - + friend class FormattersContainer<KeyType, ValueType>; friend class FormatManager; }; diff --git a/lldb/include/lldb/Expression/IRExecutionUnit.h b/lldb/include/lldb/Expression/IRExecutionUnit.h index e59bb06ec68..937a5165cd3 100644 --- a/lldb/include/lldb/Expression/IRExecutionUnit.h +++ b/lldb/include/lldb/Expression/IRExecutionUnit.h @@ -26,7 +26,6 @@ #include "lldb/lldb-private.h" #include "lldb/Core/DataBufferHeap.h" #include "lldb/Expression/IRMemoryMap.h" -#include "lldb/Host/Mutex.h" #include "lldb/Symbol/ObjectFile.h" #include "lldb/Symbol/SymbolContext.h" diff --git a/lldb/include/lldb/Host/Editline.h b/lldb/include/lldb/Host/Editline.h index 22eb9c213a9..9d72333780c 100644 --- a/lldb/include/lldb/Host/Editline.h +++ b/lldb/include/lldb/Host/Editline.h @@ -50,13 +50,13 @@ #endif #endif +#include <mutex> #include <string> #include <vector> #include "lldb/Host/Condition.h" #include "lldb/Host/ConnectionFileDescriptor.h" #include "lldb/Host/FileSpec.h" -#include "lldb/Host/Mutex.h" #include "lldb/Host/Predicate.h" namespace lldb_private { @@ -359,7 +359,7 @@ namespace lldb_private { CompleteCallbackType m_completion_callback = nullptr; void * m_completion_callback_baton = nullptr; - Mutex m_output_mutex; + std::mutex m_output_mutex; }; } diff --git a/lldb/include/lldb/Host/ProcessRunLock.h b/lldb/include/lldb/Host/ProcessRunLock.h index ceb1e90be75..797939a7ede 100644 --- a/lldb/include/lldb/Host/ProcessRunLock.h +++ b/lldb/include/lldb/Host/ProcessRunLock.h @@ -18,7 +18,6 @@ // Other libraries and framework includes // Project includes #include "lldb/lldb-defines.h" -#include "lldb/Host/Mutex.h" #include "lldb/Host/Condition.h" //---------------------------------------------------------------------- diff --git a/lldb/include/lldb/Host/common/NativeBreakpointList.h b/lldb/include/lldb/Host/common/NativeBreakpointList.h index aba2f8a74cd..bd1a9ae09db 100644 --- a/lldb/include/lldb/Host/common/NativeBreakpointList.h +++ b/lldb/include/lldb/Host/common/NativeBreakpointList.h @@ -12,11 +12,11 @@ #include "lldb/lldb-private-forward.h" #include "lldb/Core/Error.h" -#include "lldb/Host/Mutex.h" // #include "lldb/Host/NativeBreakpoint.h" #include <functional> #include <map> +#include <mutex> namespace lldb_private { @@ -48,7 +48,7 @@ namespace lldb_private private: typedef std::map<lldb::addr_t, NativeBreakpointSP> BreakpointMap; - Mutex m_mutex; + std::recursive_mutex m_mutex; BreakpointMap m_breakpoints; }; } diff --git a/lldb/include/lldb/Host/common/NativeProcessProtocol.h b/lldb/include/lldb/Host/common/NativeProcessProtocol.h index 7236bf65904..d306a58f3ca 100644 --- a/lldb/include/lldb/Host/common/NativeProcessProtocol.h +++ b/lldb/include/lldb/Host/common/NativeProcessProtocol.h @@ -10,12 +10,12 @@ #ifndef liblldb_NativeProcessProtocol_h_ #define liblldb_NativeProcessProtocol_h_ +#include <mutex> #include <vector> #include "lldb/lldb-private-forward.h" #include "lldb/lldb-types.h" #include "lldb/Core/Error.h" -#include "lldb/Host/Mutex.h" #include "lldb/Host/MainLoop.h" #include "llvm/ADT/StringRef.h" @@ -364,15 +364,15 @@ namespace lldb_private std::vector<NativeThreadProtocolSP> m_threads; lldb::tid_t m_current_thread_id; - mutable Mutex m_threads_mutex; + mutable std::recursive_mutex m_threads_mutex; lldb::StateType m_state; - mutable Mutex m_state_mutex; + mutable std::recursive_mutex m_state_mutex; lldb_private::ExitType m_exit_type; int m_exit_status; std::string m_exit_description; - Mutex m_delegates_mutex; + std::recursive_mutex m_delegates_mutex; std::vector<NativeDelegate*> m_delegates; NativeBreakpointList m_breakpoint_list; NativeWatchpointList m_watchpoint_list; diff --git a/lldb/include/lldb/Host/posix/ConnectionFileDescriptorPosix.h b/lldb/include/lldb/Host/posix/ConnectionFileDescriptorPosix.h index 7e7904cd5fa..0d3ec35ce46 100644 --- a/lldb/include/lldb/Host/posix/ConnectionFileDescriptorPosix.h +++ b/lldb/include/lldb/Host/posix/ConnectionFileDescriptorPosix.h @@ -13,13 +13,13 @@ // C++ Includes #include <atomic> #include <memory> +#include <mutex> #include "lldb/lldb-forward.h" // Other libraries and framework includes // Project includes #include "lldb/Core/Connection.h" -#include "lldb/Host/Mutex.h" #include "lldb/Host/Pipe.h" #include "lldb/Host/Predicate.h" #include "lldb/Host/IOObject.h" @@ -105,7 +105,7 @@ class ConnectionFileDescriptor : public Connection // the port number. Pipe m_pipe; - Mutex m_mutex; + std::recursive_mutex m_mutex; std::atomic<bool> m_shutting_down; // This marks that we are shutting down so if we get woken up from // BytesAvailable to disconnect, we won't try to read again. bool m_waiting_for_accept; diff --git a/lldb/include/lldb/Initialization/SystemLifetimeManager.h b/lldb/include/lldb/Initialization/SystemLifetimeManager.h index 843ec282067..2dd7b22c240 100644 --- a/lldb/include/lldb/Initialization/SystemLifetimeManager.h +++ b/lldb/include/lldb/Initialization/SystemLifetimeManager.h @@ -11,9 +11,9 @@ #define LLDB_INITIALIZATION_SYSTEM_LIFETIME_MANAGER_H #include "lldb/lldb-private-types.h" -#include "lldb/Host/Mutex.h" #include <memory> +#include <mutex> namespace lldb_private { @@ -29,13 +29,14 @@ class SystemLifetimeManager void Terminate(); private: - Mutex m_mutex; - std::unique_ptr<SystemInitializer> m_initializer; - bool m_initialized; - - // Noncopyable. - SystemLifetimeManager(const SystemLifetimeManager &other) = delete; - SystemLifetimeManager &operator=(const SystemLifetimeManager &other) = delete; + std::recursive_mutex m_mutex; + std::unique_ptr<SystemInitializer> m_initializer; + bool m_initialized; + + // Noncopyable. + SystemLifetimeManager(const SystemLifetimeManager &other) = delete; + SystemLifetimeManager & + operator=(const SystemLifetimeManager &other) = delete; }; } diff --git a/lldb/include/lldb/Interpreter/CommandHistory.h b/lldb/include/lldb/Interpreter/CommandHistory.h index db5db15fc1e..ff05f6da6c3 100644 --- a/lldb/include/lldb/Interpreter/CommandHistory.h +++ b/lldb/include/lldb/Interpreter/CommandHistory.h @@ -12,6 +12,7 @@ // C Includes // C++ Includes +#include <mutex> #include <string> #include <vector> @@ -19,7 +20,6 @@ // Project includes #include "lldb/lldb-private.h" #include "lldb/Core/Stream.h" -#include "lldb/Host/Mutex.h" namespace lldb_private { @@ -66,7 +66,7 @@ private: DISALLOW_COPY_AND_ASSIGN(CommandHistory); typedef std::vector<std::string> History; - mutable Mutex m_mutex; + mutable std::recursive_mutex m_mutex; History m_history; }; diff --git a/lldb/include/lldb/Symbol/ArmUnwindInfo.h b/lldb/include/lldb/Symbol/ArmUnwindInfo.h index b19af23744a..8c40f19d285 100644 --- a/lldb/include/lldb/Symbol/ArmUnwindInfo.h +++ b/lldb/include/lldb/Symbol/ArmUnwindInfo.h @@ -14,7 +14,6 @@ #include "lldb/Core/DataExtractor.h" #include "lldb/Core/RangeMap.h" -#include "lldb/Host/Mutex.h" #include "lldb/Symbol/ObjectFile.h" #include "lldb/lldb-private.h" diff --git a/lldb/include/lldb/Symbol/FuncUnwinders.h b/lldb/include/lldb/Symbol/FuncUnwinders.h index 728b4c6fcb3..47520f2fa24 100644 --- a/lldb/include/lldb/Symbol/FuncUnwinders.h +++ b/lldb/include/lldb/Symbol/FuncUnwinders.h @@ -1,12 +1,12 @@ #ifndef liblldb_FuncUnwinders_h #define liblldb_FuncUnwinders_h +#include <mutex> #include <vector> #include "lldb/Core/AddressRange.h" #include "lldb/Core/ArchSpec.h" #include "lldb/Core/AddressRange.h" -#include "lldb/Host/Mutex.h" namespace lldb_private { @@ -119,7 +119,7 @@ private: UnwindTable& m_unwind_table; AddressRange m_range; - Mutex m_mutex; + std::recursive_mutex m_mutex; lldb::UnwindPlanSP m_unwind_plan_assembly_sp; lldb::UnwindPlanSP m_unwind_plan_eh_frame_sp; diff --git a/lldb/include/lldb/Target/JITLoaderList.h b/lldb/include/lldb/Target/JITLoaderList.h index f933a61e995..c86043c5cf1 100644 --- a/lldb/include/lldb/Target/JITLoaderList.h +++ b/lldb/include/lldb/Target/JITLoaderList.h @@ -10,10 +10,10 @@ #ifndef liblldb_JITLoaderList_h_ #define liblldb_JITLoaderList_h_ +#include <mutex> #include <vector> #include "lldb/lldb-forward.h" -#include "lldb/Host/Mutex.h" namespace lldb_private { @@ -52,7 +52,7 @@ public: private: std::vector<lldb::JITLoaderSP> m_jit_loaders_vec; - lldb_private::Mutex m_jit_loaders_mutex; + std::recursive_mutex m_jit_loaders_mutex; }; } // namespace lldb_private diff --git a/lldb/include/lldb/Target/Platform.h b/lldb/include/lldb/Target/Platform.h index c0262a248a2..6fdd92db568 100644 --- a/lldb/include/lldb/Target/Platform.h +++ b/lldb/include/lldb/Target/Platform.h @@ -15,6 +15,7 @@ #include <functional> #include <map> #include <memory> +#include <mutex> #include <string> #include <vector> @@ -28,7 +29,6 @@ #include "lldb/Core/UserSettingsController.h" #include "lldb/Interpreter/Options.h" #include "lldb/Host/FileSpec.h" -#include "lldb/Host/Mutex.h" // TODO pull NativeDelegate class out of NativeProcessProtocol so we // can just forward ref the NativeDelegate rather than include it here. @@ -1079,7 +1079,8 @@ class ModuleCache; uint32_t m_update_os_version; ArchSpec m_system_arch; // The architecture of the kernel or the remote platform typedef std::map<uint32_t, ConstString> IDToNameMap; - Mutex m_mutex; // Mutex for modifying Platform data structures that should only be used for non-reentrant code + // Mutex for modifying Platform data structures that should only be used for non-reentrant code + std::mutex m_mutex; IDToNameMap m_uid_map; IDToNameMap m_gid_map; size_t m_max_uid_name_len; @@ -1112,9 +1113,9 @@ class ModuleCache; CalculateTrapHandlerSymbolNames () = 0; const char * - GetCachedUserName (uint32_t uid) + GetCachedUserName(uint32_t uid) { - Mutex::Locker locker (m_mutex); + std::lock_guard<std::mutex> guard(m_mutex); // return the empty string if our string is NULL // so we can tell when things were in the negative // cached (didn't find a valid user name, don't keep @@ -1124,35 +1125,35 @@ class ModuleCache; } const char * - SetCachedUserName (uint32_t uid, const char *name, size_t name_len) + SetCachedUserName(uint32_t uid, const char *name, size_t name_len) { - Mutex::Locker locker (m_mutex); - ConstString const_name (name); + std::lock_guard<std::mutex> guard(m_mutex); + ConstString const_name(name); m_uid_map[uid] = const_name; if (m_max_uid_name_len < name_len) m_max_uid_name_len = name_len; // Const strings lives forever in our const string pool, so we can return the const char * - return const_name.GetCString(); + return const_name.GetCString(); } void - SetUserNameNotFound (uint32_t uid) + SetUserNameNotFound(uint32_t uid) { - Mutex::Locker locker (m_mutex); + std::lock_guard<std::mutex> guard(m_mutex); m_uid_map[uid] = ConstString(); } void - ClearCachedUserNames () + ClearCachedUserNames() { - Mutex::Locker locker (m_mutex); + std::lock_guard<std::mutex> guard(m_mutex); m_uid_map.clear(); } - + const char * - GetCachedGroupName (uint32_t gid) + GetCachedGroupName(uint32_t gid) { - Mutex::Locker locker (m_mutex); + std::lock_guard<std::mutex> guard(m_mutex); // return the empty string if our string is NULL // so we can tell when things were in the negative // cached (didn't find a valid group name, don't keep @@ -1162,28 +1163,28 @@ class ModuleCache; } const char * - SetCachedGroupName (uint32_t gid, const char *name, size_t name_len) + SetCachedGroupName(uint32_t gid, const char *name, size_t name_len) { - Mutex::Locker locker (m_mutex); - ConstString const_name (name); + std::lock_guard<std::mutex> guard(m_mutex); + ConstString const_name(name); m_gid_map[gid] = const_name; if (m_max_gid_name_len < name_len) m_max_gid_name_len = name_len; // Const strings lives forever in our const string pool, so we can return the const char * - return const_name.GetCString(); + return const_name.GetCString(); } void - SetGroupNameNotFound (uint32_t gid) + SetGroupNameNotFound(uint32_t gid) { - Mutex::Locker locker (m_mutex); + std::lock_guard<std::mutex> guard(m_mutex); m_gid_map[gid] = ConstString(); } void - ClearCachedGroupNames () + ClearCachedGroupNames() { - Mutex::Locker locker (m_mutex); + std::lock_guard<std::mutex> guard(m_mutex); m_gid_map.clear(); } @@ -1236,20 +1237,15 @@ class ModuleCache; class PlatformList { public: - PlatformList() : - m_mutex (Mutex::eMutexTypeRecursive), - m_platforms (), - m_selected_platform_sp() - { - } + PlatformList() : m_mutex(), m_platforms(), m_selected_platform_sp() {} ~PlatformList() = default; void - Append (const lldb::PlatformSP &platform_sp, bool set_selected) + Append(const lldb::PlatformSP &platform_sp, bool set_selected) { - Mutex::Locker locker (m_mutex); - m_platforms.push_back (platform_sp); + std::lock_guard<std::recursive_mutex> guard(m_mutex); + m_platforms.push_back(platform_sp); if (set_selected) m_selected_platform_sp = m_platforms.back(); } @@ -1257,16 +1253,16 @@ class ModuleCache; size_t GetSize() { - Mutex::Locker locker (m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); return m_platforms.size(); } lldb::PlatformSP - GetAtIndex (uint32_t idx) + GetAtIndex(uint32_t idx) { lldb::PlatformSP platform_sp; { - Mutex::Locker locker (m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); if (idx < m_platforms.size()) platform_sp = m_platforms[idx]; } @@ -1283,23 +1279,23 @@ class ModuleCache; /// processes. //------------------------------------------------------------------ lldb::PlatformSP - GetSelectedPlatform () + GetSelectedPlatform() { - Mutex::Locker locker (m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); if (!m_selected_platform_sp && !m_platforms.empty()) m_selected_platform_sp = m_platforms.front(); - + return m_selected_platform_sp; } void - SetSelectedPlatform (const lldb::PlatformSP &platform_sp) + SetSelectedPlatform(const lldb::PlatformSP &platform_sp) { if (platform_sp) { - Mutex::Locker locker (m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); const size_t num_platforms = m_platforms.size(); - for (size_t idx=0; idx<num_platforms; ++idx) + for (size_t idx = 0; idx < num_platforms; ++idx) { if (m_platforms[idx].get() == platform_sp.get()) { @@ -1307,21 +1303,21 @@ class ModuleCache; return; } } - m_platforms.push_back (platform_sp); + m_platforms.push_back(platform_sp); m_selected_platform_sp = m_platforms.back(); } } protected: typedef std::vector<lldb::PlatformSP> collection; - mutable Mutex m_mutex; + mutable std::recursive_mutex m_mutex; collection m_platforms; lldb::PlatformSP m_selected_platform_sp; private: DISALLOW_COPY_AND_ASSIGN (PlatformList); }; - + class OptionGroupPlatformRSync : public lldb_private::OptionGroup { public: diff --git a/lldb/include/lldb/Target/SectionLoadHistory.h b/lldb/include/lldb/Target/SectionLoadHistory.h index ddf46a1861c..2494b7fd277 100644 --- a/lldb/include/lldb/Target/SectionLoadHistory.h +++ b/lldb/include/lldb/Target/SectionLoadHistory.h @@ -13,10 +13,10 @@ // C Includes // C++ Includes #include <map> +#include <mutex> // Project includes #include "lldb/lldb-public.h" -#include "lldb/Host/Mutex.h" namespace lldb_private { @@ -31,11 +31,7 @@ public: //------------------------------------------------------------------ // Constructors and Destructors //------------------------------------------------------------------ - SectionLoadHistory () : - m_stop_id_to_section_load_list(), - m_mutex (Mutex::eMutexTypeRecursive) - { - } + SectionLoadHistory() : m_stop_id_to_section_load_list(), m_mutex() {} ~SectionLoadHistory() { @@ -98,7 +94,7 @@ protected: typedef std::map<uint32_t, lldb::SectionLoadListSP> StopIDToSectionLoadList; StopIDToSectionLoadList m_stop_id_to_section_load_list; - mutable Mutex m_mutex; + mutable std::recursive_mutex m_mutex; private: DISALLOW_COPY_AND_ASSIGN (SectionLoadHistory); diff --git a/lldb/include/lldb/Target/SectionLoadList.h b/lldb/include/lldb/Target/SectionLoadList.h index 5f5d39e2b24..1326d6007f2 100644 --- a/lldb/include/lldb/Target/SectionLoadList.h +++ b/lldb/include/lldb/Target/SectionLoadList.h @@ -13,13 +13,13 @@ // C Includes // C++ Includes #include <map> +#include <mutex> // Other libraries and framework includes #include "llvm/ADT/DenseMap.h" // Project includes #include "lldb/lldb-public.h" #include "lldb/Core/Section.h" -#include "lldb/Host/Mutex.h" namespace lldb_private { @@ -29,13 +29,7 @@ public: //------------------------------------------------------------------ // Constructors and Destructors //------------------------------------------------------------------ - SectionLoadList () : - m_addr_to_sect (), - m_sect_to_addr (), - m_mutex (Mutex::eMutexTypeRecursive) - - { - } + SectionLoadList() : m_addr_to_sect(), m_sect_to_addr(), m_mutex() {} SectionLoadList (const SectionLoadList& rhs); @@ -84,7 +78,7 @@ protected: typedef llvm::DenseMap<const Section *, lldb::addr_t> sect_to_addr_collection; addr_to_sect_collection m_addr_to_sect; sect_to_addr_collection m_sect_to_addr; - mutable Mutex m_mutex; + mutable std::recursive_mutex m_mutex; }; } // namespace lldb_private diff --git a/lldb/include/lldb/Target/TargetList.h b/lldb/include/lldb/Target/TargetList.h index fddb715b46f..d96d2f1b0e7 100644 --- a/lldb/include/lldb/Target/TargetList.h +++ b/lldb/include/lldb/Target/TargetList.h @@ -12,12 +12,12 @@ // C Includes // C++ Includes +#include <mutex> #include <vector> // Other libraries and framework includes // Project includes #include "lldb/Core/Broadcaster.h" -#include "lldb/Host/Mutex.h" #include "lldb/Target/Target.h" namespace lldb_private { @@ -229,7 +229,7 @@ protected: //------------------------------------------------------------------ collection m_target_list; lldb::TargetSP m_dummy_target_sp; - mutable Mutex m_target_list_mutex; + mutable std::recursive_mutex m_target_list_mutex; uint32_t m_selected_target_idx; private: diff --git a/lldb/include/lldb/Target/Thread.h b/lldb/include/lldb/Target/Thread.h index ba73e0b49da..1e0e54746e6 100644 --- a/lldb/include/lldb/Target/Thread.h +++ b/lldb/include/lldb/Target/Thread.h @@ -13,13 +13,13 @@ // C Includes // C++ Includes #include <memory> +#include <mutex> #include <string> #include <vector> // Other libraries and framework includes // Project includes #include "lldb/lldb-private.h" -#include "lldb/Host/Mutex.h" #include "lldb/Core/Broadcaster.h" #include "lldb/Core/Event.h" #include "lldb/Core/StructuredData.h" @@ -1446,11 +1446,11 @@ protected: const uint32_t m_index_id; ///< A unique 1 based index assigned to each thread for easy UI/command line access. lldb::RegisterContextSP m_reg_context_sp; ///< The register context for this thread's current register state. lldb::StateType m_state; ///< The state of our process. - mutable Mutex m_state_mutex; ///< Multithreaded protection for m_state. + mutable std::recursive_mutex m_state_mutex; ///< Multithreaded protection for m_state. plan_stack m_plan_stack; ///< The stack of plans this thread is executing. plan_stack m_completed_plan_stack; ///< Plans that have been completed by this stop. They get deleted when the thread resumes. plan_stack m_discarded_plan_stack; ///< Plans that have been discarded by this stop. They get deleted when the thread resumes. - mutable Mutex m_frame_mutex; ///< Multithreaded protection for m_state. + mutable std::recursive_mutex m_frame_mutex; ///< Multithreaded protection for m_state. lldb::StackFrameListSP m_curr_frames_sp; ///< The stack frames that get lazily populated after a thread stops. lldb::StackFrameListSP m_prev_frames_sp; ///< The previous stack frames from the last time this thread stopped. int m_resume_signal; ///< The signal that should be used when continuing this thread. diff --git a/lldb/include/lldb/Target/ThreadPlan.h b/lldb/include/lldb/Target/ThreadPlan.h index e6f9aeb78dd..6dac4a299e5 100644 --- a/lldb/include/lldb/Target/ThreadPlan.h +++ b/lldb/include/lldb/Target/ThreadPlan.h @@ -12,13 +12,13 @@ // C Includes // C++ Includes +#include <mutex> #include <string> // Other libraries and framework includes // Project includes #include "lldb/lldb-private.h" #include "lldb/Core/UserID.h" -#include "lldb/Host/Mutex.h" #include "lldb/Target/Process.h" #include "lldb/Target/Target.h" #include "lldb/Target/Thread.h" @@ -632,7 +632,7 @@ private: ThreadPlanKind m_kind; std::string m_name; - Mutex m_plan_complete_mutex; + std::recursive_mutex m_plan_complete_mutex; LazyBool m_cached_plan_explains_stop; bool m_plan_complete; bool m_plan_private; diff --git a/lldb/include/lldb/Target/ThreadPlanPython.h b/lldb/include/lldb/Target/ThreadPlanPython.h index ab3fbbdf6fb..8d5b217226f 100644 --- a/lldb/include/lldb/Target/ThreadPlanPython.h +++ b/lldb/include/lldb/Target/ThreadPlanPython.h @@ -19,7 +19,6 @@ #include "lldb/lldb-private.h" #include "lldb/Core/StructuredData.h" #include "lldb/Core/UserID.h" -#include "lldb/Host/Mutex.h" #include "lldb/Target/Process.h" #include "lldb/Target/Target.h" #include "lldb/Target/Thread.h" diff --git a/lldb/include/lldb/Target/Unwind.h b/lldb/include/lldb/Target/Unwind.h index 17c6c0df820..09ba87a42bb 100644 --- a/lldb/include/lldb/Target/Unwind.h +++ b/lldb/include/lldb/Target/Unwind.h @@ -12,10 +12,11 @@ // C Includes // C++ Includes +#include <mutex> + // Other libraries and framework includes // Project includes #include "lldb/lldb-private.h" -#include "lldb/Host/Mutex.h" namespace lldb_private { @@ -25,11 +26,7 @@ protected: //------------------------------------------------------------------ // Classes that inherit from Unwind can see and modify these //------------------------------------------------------------------ - Unwind(Thread &thread) : - m_thread (thread), - m_unwind_mutex(Mutex::eMutexTypeRecursive) - { - } + Unwind(Thread &thread) : m_thread(thread), m_unwind_mutex() {} public: virtual @@ -40,18 +37,17 @@ public: void Clear() { - Mutex::Locker locker(m_unwind_mutex); + std::lock_guard<std::recursive_mutex> guard(m_unwind_mutex); DoClear(); - } uint32_t GetFrameCount() { - Mutex::Locker locker(m_unwind_mutex); + std::lock_guard<std::recursive_mutex> guard(m_unwind_mutex); return DoGetFrameCount(); } - + uint32_t GetFramesUpTo (uint32_t end_idx) { @@ -70,21 +66,19 @@ public: } bool - GetFrameInfoAtIndex (uint32_t frame_idx, - lldb::addr_t& cfa, - lldb::addr_t& pc) + GetFrameInfoAtIndex(uint32_t frame_idx, lldb::addr_t &cfa, lldb::addr_t &pc) { - Mutex::Locker locker(m_unwind_mutex); - return DoGetFrameInfoAtIndex (frame_idx, cfa, pc); + std::lock_guard<std::recursive_mutex> guard(m_unwind_mutex); + return DoGetFrameInfoAtIndex(frame_idx, cfa, pc); } - + lldb::RegisterContextSP - CreateRegisterContextForFrame (StackFrame *frame) + CreateRegisterContextForFrame(StackFrame *frame) { - Mutex::Locker locker(m_unwind_mutex); - return DoCreateRegisterContextForFrame (frame); + std::lock_guard<std::recursive_mutex> guard(m_unwind_mutex); + return DoCreateRegisterContextForFrame(frame); } - + Thread & GetThread() { @@ -110,7 +104,8 @@ protected: DoCreateRegisterContextForFrame (StackFrame *frame) = 0; Thread &m_thread; - Mutex m_unwind_mutex; + std::recursive_mutex m_unwind_mutex; + private: DISALLOW_COPY_AND_ASSIGN (Unwind); }; diff --git a/lldb/include/lldb/Utility/SharedCluster.h b/lldb/include/lldb/Utility/SharedCluster.h index 2c03c409d97..0057844549f 100644 --- a/lldb/include/lldb/Utility/SharedCluster.h +++ b/lldb/include/lldb/Utility/SharedCluster.h @@ -11,7 +11,6 @@ #define utility_SharedCluster_h_ #include "lldb/Utility/SharingPtr.h" -#include "lldb/Host/Mutex.h" #include "llvm/ADT/SmallPtrSet.h" @@ -46,14 +45,12 @@ template <class T> class ClusterManager { public: - ClusterManager () : - m_objects(), - m_external_ref(0), - m_mutex(Mutex::eMutexTypeNormal) {} - - ~ClusterManager () + ClusterManager() : m_objects(), m_external_ref(0), m_mutex() {} + + ~ClusterManager() { - for (typename llvm::SmallPtrSet<T *, 16>::iterator pos = m_objects.begin(), end = m_objects.end(); pos != end; ++pos) + for (typename llvm::SmallPtrSet<T *, 16>::iterator pos = m_objects.begin(), end = m_objects.end(); pos != end; + ++pos) { T *object = *pos; delete object; @@ -62,42 +59,44 @@ public: // Decrement refcount should have been called on this ClusterManager, // and it should have locked the mutex, now we will unlock it before // we destroy it... - m_mutex.Unlock(); + m_mutex.unlock(); } - - void ManageObject (T *new_object) + + void + ManageObject(T *new_object) { - Mutex::Locker locker (m_mutex); - m_objects.insert (new_object); + std::lock_guard<std::mutex> guard(m_mutex); + m_objects.insert(new_object); } - - typename lldb_private::SharingPtr<T> GetSharedPointer(T *desired_object) + + typename lldb_private::SharingPtr<T> + GetSharedPointer(T *desired_object) { { - Mutex::Locker locker (m_mutex); + std::lock_guard<std::mutex> guard(m_mutex); m_external_ref++; - assert (m_objects.count(desired_object)); + assert(m_objects.count(desired_object)); } - return typename lldb_private::SharingPtr<T> (desired_object, new imp::shared_ptr_refcount<ClusterManager> (this)); + return typename lldb_private::SharingPtr<T>(desired_object, new imp::shared_ptr_refcount<ClusterManager>(this)); } - + private: - - void DecrementRefCount () + void + DecrementRefCount() { - m_mutex.Lock(); + m_mutex.lock(); m_external_ref--; if (m_external_ref == 0) delete this; else - m_mutex.Unlock(); + m_mutex.unlock(); } - + friend class imp::shared_ptr_refcount<ClusterManager>; - + llvm::SmallPtrSet<T *, 16> m_objects; int m_external_ref; - Mutex m_mutex; + std::mutex m_mutex; }; } // namespace lldb_private diff --git a/lldb/source/API/SBDebugger.cpp b/lldb/source/API/SBDebugger.cpp index f03262e2454..a1d19d44bad 100644 --- a/lldb/source/API/SBDebugger.cpp +++ b/lldb/source/API/SBDebugger.cpp @@ -191,8 +191,8 @@ SBDebugger::Create(bool source_init_files, lldb::LogOutputCallback callback, voi // uses global collections and having two threads parsing the .lldbinit files can cause // mayhem. So to get around this for now we need to use a mutex to prevent bad things // from happening. - static Mutex g_mutex(Mutex::eMutexTypeRecursive); - Mutex::Locker locker(g_mutex); + static std::recursive_mutex g_mutex; + std::lock_guard<std::recursive_mutex> guard(g_mutex); debugger.reset(Debugger::CreateInstance(callback, baton)); diff --git a/lldb/source/Breakpoint/BreakpointLocationList.cpp b/lldb/source/Breakpoint/BreakpointLocationList.cpp index d57cfa68fb8..5e56299bfe7 100644 --- a/lldb/source/Breakpoint/BreakpointLocationList.cpp +++ b/lldb/source/Breakpoint/BreakpointLocationList.cpp @@ -24,13 +24,8 @@ using namespace lldb; using namespace lldb_private; -BreakpointLocationList::BreakpointLocationList(Breakpoint &owner) : - m_owner (owner), - m_locations(), - m_address_to_location (), - m_mutex (Mutex::eMutexTypeRecursive), - m_next_id (0), - m_new_location_recorder (nullptr) +BreakpointLocationList::BreakpointLocationList(Breakpoint &owner) + : m_owner(owner), m_locations(), m_address_to_location(), m_mutex(), m_next_id(0), m_new_location_recorder(nullptr) { } @@ -39,7 +34,7 @@ BreakpointLocationList::~BreakpointLocationList() = default; BreakpointLocationSP BreakpointLocationList::Create (const Address &addr, bool resolve_indirect_symbols) { - Mutex::Locker locker (m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); // The location ID is just the size of the location list + 1 lldb::break_id_t bp_loc_id = ++m_next_id; BreakpointLocationSP bp_loc_sp (new BreakpointLocation (bp_loc_id, m_owner, addr, LLDB_INVALID_THREAD_ID, m_owner.IsHardware(), resolve_indirect_symbols)); @@ -84,7 +79,7 @@ Compare (BreakpointLocationSP lhs, lldb::break_id_t val) BreakpointLocationSP BreakpointLocationList::FindByID (lldb::break_id_t break_id) const { - Mutex::Locker locker (m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); collection::const_iterator end = m_locations.end(); collection::const_iterator pos = std::lower_bound(m_locations.begin(), end, break_id, Compare); if (pos != end && (*pos)->GetID() == break_id) @@ -97,7 +92,7 @@ size_t BreakpointLocationList::FindInModule (Module *module, BreakpointLocationCollection& bp_loc_list) { - Mutex::Locker locker (m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); const size_t orig_size = bp_loc_list.GetSize(); collection::iterator pos, end = m_locations.end(); @@ -116,7 +111,7 @@ BreakpointLocationList::FindInModule (Module *module, const BreakpointLocationSP BreakpointLocationList::FindByAddress (const Address &addr) const { - Mutex::Locker locker (m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); BreakpointLocationSP bp_loc_sp; if (!m_locations.empty()) { @@ -150,7 +145,7 @@ BreakpointLocationList::Dump (Stream *s) const { s->Printf("%p: ", static_cast<const void*>(this)); //s->Indent(); - Mutex::Locker locker (m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); s->Printf("BreakpointLocationList with %" PRIu64 " BreakpointLocations:\n", (uint64_t)m_locations.size()); s->IndentMore(); collection::const_iterator pos, end = m_locations.end(); @@ -162,7 +157,7 @@ BreakpointLocationList::Dump (Stream *s) const BreakpointLocationSP BreakpointLocationList::GetByIndex (size_t i) { - Mutex::Locker locker (m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); BreakpointLocationSP bp_loc_sp; if (i < m_locations.size()) bp_loc_sp = m_locations[i]; @@ -173,7 +168,7 @@ BreakpointLocationList::GetByIndex (size_t i) const BreakpointLocationSP BreakpointLocationList::GetByIndex (size_t i) const { - Mutex::Locker locker (m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); BreakpointLocationSP bp_loc_sp; if (i < m_locations.size()) bp_loc_sp = m_locations[i]; @@ -184,7 +179,7 @@ BreakpointLocationList::GetByIndex (size_t i) const void BreakpointLocationList::ClearAllBreakpointSites () { - Mutex::Locker locker (m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); collection::iterator pos, end = m_locations.end(); for (pos = m_locations.begin(); pos != end; ++pos) (*pos)->ClearBreakpointSite(); @@ -193,7 +188,7 @@ BreakpointLocationList::ClearAllBreakpointSites () void BreakpointLocationList::ResolveAllBreakpointSites () { - Mutex::Locker locker (m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); collection::iterator pos, end = m_locations.end(); for (pos = m_locations.begin(); pos != end; ++pos) @@ -207,7 +202,7 @@ uint32_t BreakpointLocationList::GetHitCount () const { uint32_t hit_count = 0; - Mutex::Locker locker (m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); collection::const_iterator pos, end = m_locations.end(); for (pos = m_locations.begin(); pos != end; ++pos) hit_count += (*pos)->GetHitCount(); @@ -217,7 +212,7 @@ BreakpointLocationList::GetHitCount () const size_t BreakpointLocationList::GetNumResolvedLocations() const { - Mutex::Locker locker (m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); size_t resolve_count = 0; collection::const_iterator pos, end = m_locations.end(); for (pos = m_locations.begin(); pos != end; ++pos) @@ -231,7 +226,7 @@ BreakpointLocationList::GetNumResolvedLocations() const void BreakpointLocationList::GetDescription (Stream *s, lldb::DescriptionLevel level) { - Mutex::Locker locker (m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); collection::iterator pos, end = m_locations.end(); for (pos = m_locations.begin(); pos != end; ++pos) @@ -244,7 +239,7 @@ BreakpointLocationList::GetDescription (Stream *s, lldb::DescriptionLevel level) BreakpointLocationSP BreakpointLocationList::AddLocation (const Address &addr, bool resolve_indirect_symbols, bool *new_location) { - Mutex::Locker locker (m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); if (new_location) *new_location = false; @@ -285,8 +280,8 @@ BreakpointLocationList::RemoveLocation (const lldb::BreakpointLocationSP &bp_loc { if (bp_loc_sp) { - Mutex::Locker locker (m_mutex); - + std::lock_guard<std::recursive_mutex> guard(m_mutex); + m_address_to_location.erase (bp_loc_sp->GetAddress()); collection::iterator pos, end = m_locations.end(); @@ -305,7 +300,7 @@ BreakpointLocationList::RemoveLocation (const lldb::BreakpointLocationSP &bp_loc void BreakpointLocationList::RemoveInvalidLocations (const ArchSpec &arch) { - Mutex::Locker locker (m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); size_t idx = 0; // Don't cache m_location.size() as it will change since we might // remove locations from our vector... @@ -341,7 +336,7 @@ BreakpointLocationList::RemoveInvalidLocations (const ArchSpec &arch) void BreakpointLocationList::StartRecordingNewLocations (BreakpointLocationCollection &new_locations) { - Mutex::Locker locker (m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); assert(m_new_location_recorder == nullptr); m_new_location_recorder = &new_locations; } @@ -349,7 +344,7 @@ BreakpointLocationList::StartRecordingNewLocations (BreakpointLocationCollection void BreakpointLocationList::StopRecordingNewLocations () { - Mutex::Locker locker (m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); m_new_location_recorder = nullptr; } diff --git a/lldb/source/Breakpoint/BreakpointSite.cpp b/lldb/source/Breakpoint/BreakpointSite.cpp index d2aaea098cd..b4112f7fc01 100644 --- a/lldb/source/Breakpoint/BreakpointSite.cpp +++ b/lldb/source/Breakpoint/BreakpointSite.cpp @@ -23,17 +23,15 @@ using namespace lldb; using namespace lldb_private; -BreakpointSite::BreakpointSite(BreakpointSiteList *list, - const BreakpointLocationSP& owner, - lldb::addr_t addr, - bool use_hardware) : - StoppointLocation(GetNextID(), addr, 0, use_hardware), - m_type (eSoftware), // Process subclasses need to set this correctly using SetType() - m_saved_opcode(), - m_trap_opcode(), - m_enabled(false), // Need to create it disabled, so the first enable turns it on. - m_owners(), - m_owners_mutex(Mutex::eMutexTypeRecursive) +BreakpointSite::BreakpointSite(BreakpointSiteList *list, const BreakpointLocationSP &owner, lldb::addr_t addr, + bool use_hardware) + : StoppointLocation(GetNextID(), addr, 0, use_hardware), + m_type(eSoftware), // Process subclasses need to set this correctly using SetType() + m_saved_opcode(), + m_trap_opcode(), + m_enabled(false), // Need to create it disabled, so the first enable turns it on. + m_owners(), + m_owners_mutex() { m_owners.Add(owner); } @@ -61,7 +59,7 @@ BreakpointSite::GetNextID() bool BreakpointSite::ShouldStop (StoppointCallbackContext *context) { - Mutex::Locker locker(m_owners_mutex); + std::lock_guard<std::recursive_mutex> guard(m_owners_mutex); IncrementHitCount(); return m_owners.ShouldStop (context); } @@ -69,7 +67,7 @@ BreakpointSite::ShouldStop (StoppointCallbackContext *context) bool BreakpointSite::IsBreakpointAtThisSite (lldb::break_id_t bp_id) { - Mutex::Locker locker(m_owners_mutex); + std::lock_guard<std::recursive_mutex> guard(m_owners_mutex); const size_t owner_count = m_owners.GetSize(); for (size_t i = 0; i < owner_count; i++) { @@ -96,7 +94,7 @@ BreakpointSite::Dump(Stream *s) const void BreakpointSite::GetDescription (Stream *s, lldb::DescriptionLevel level) { - Mutex::Locker locker(m_owners_mutex); + std::lock_guard<std::recursive_mutex> guard(m_owners_mutex); if (level != lldb::eDescriptionLevelBrief) s->Printf ("breakpoint site: %d at 0x%8.8" PRIx64, GetID(), GetLoadAddress()); m_owners.GetDescription (s, level); @@ -166,14 +164,14 @@ BreakpointSite::SetEnabled (bool enabled) void BreakpointSite::AddOwner (const BreakpointLocationSP &owner) { - Mutex::Locker locker(m_owners_mutex); + std::lock_guard<std::recursive_mutex> guard(m_owners_mutex); m_owners.Add(owner); } size_t BreakpointSite::RemoveOwner (lldb::break_id_t break_id, lldb::break_id_t break_loc_id) { - Mutex::Locker locker(m_owners_mutex); + std::lock_guard<std::recursive_mutex> guard(m_owners_mutex); m_owners.Remove(break_id, break_loc_id); return m_owners.GetSize(); } @@ -181,28 +179,28 @@ BreakpointSite::RemoveOwner (lldb::break_id_t break_id, lldb::break_id_t break_l size_t BreakpointSite::GetNumberOfOwners () { - Mutex::Locker locker(m_owners_mutex); + std::lock_guard<std::recursive_mutex> guard(m_owners_mutex); return m_owners.GetSize(); } BreakpointLocationSP BreakpointSite::GetOwnerAtIndex (size_t index) { - Mutex::Locker locker(m_owners_mutex); + std::lock_guard<std::recursive_mutex> guard(m_owners_mutex); return m_owners.GetByIndex (index); } bool BreakpointSite::ValidForThisThread (Thread *thread) { - Mutex::Locker locker(m_owners_mutex); + std::lock_guard<std::recursive_mutex> guard(m_owners_mutex); return m_owners.ValidForThisThread(thread); } void BreakpointSite::BumpHitCounts() { - Mutex::Locker locker(m_owners_mutex); + std::lock_guard<std::recursive_mutex> guard(m_owners_mutex); for (BreakpointLocationSP loc_sp : m_owners.BreakpointLocations()) { loc_sp->BumpHitCount(); @@ -255,7 +253,7 @@ BreakpointSite::IntersectsRange(lldb::addr_t addr, size_t size, lldb::addr_t *in size_t BreakpointSite::CopyOwnersList (BreakpointLocationCollection &out_collection) { - Mutex::Locker locker(m_owners_mutex); + std::lock_guard<std::recursive_mutex> guard(m_owners_mutex); for (BreakpointLocationSP loc_sp : m_owners.BreakpointLocations()) { out_collection.Add(loc_sp); diff --git a/lldb/source/Breakpoint/BreakpointSiteList.cpp b/lldb/source/Breakpoint/BreakpointSiteList.cpp index 1eaadb62a38..de9a5ad0b31 100644 --- a/lldb/source/Breakpoint/BreakpointSiteList.cpp +++ b/lldb/source/Breakpoint/BreakpointSiteList.cpp @@ -19,9 +19,7 @@ using namespace lldb; using namespace lldb_private; -BreakpointSiteList::BreakpointSiteList() : - m_mutex (Mutex::eMutexTypeRecursive), - m_bp_site_list() +BreakpointSiteList::BreakpointSiteList() : m_mutex(), m_bp_site_list() { } @@ -36,7 +34,7 @@ lldb::break_id_t BreakpointSiteList::Add(const BreakpointSiteSP &bp) { lldb::addr_t bp_site_load_addr = bp->GetLoadAddress(); - Mutex::Locker locker(m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); collection::iterator iter = m_bp_site_list.find (bp_site_load_addr); if (iter == m_bp_site_list.end()) @@ -81,7 +79,7 @@ BreakpointSiteList::FindIDByAddress (lldb::addr_t addr) bool BreakpointSiteList::Remove (lldb::break_id_t break_id) { - Mutex::Locker locker(m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); collection::iterator pos = GetIDIterator(break_id); // Predicate if (pos != m_bp_site_list.end()) { @@ -94,7 +92,7 @@ BreakpointSiteList::Remove (lldb::break_id_t break_id) bool BreakpointSiteList::RemoveByAddress (lldb::addr_t address) { - Mutex::Locker locker(m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); collection::iterator pos = m_bp_site_list.find(address); if (pos != m_bp_site_list.end()) { @@ -124,7 +122,7 @@ private: BreakpointSiteList::collection::iterator BreakpointSiteList::GetIDIterator (lldb::break_id_t break_id) { - Mutex::Locker locker(m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); return std::find_if(m_bp_site_list.begin(), m_bp_site_list.end(), // Search full range BreakpointSiteIDMatches(break_id)); // Predicate } @@ -132,7 +130,7 @@ BreakpointSiteList::GetIDIterator (lldb::break_id_t break_id) BreakpointSiteList::collection::const_iterator BreakpointSiteList::GetIDConstIterator (lldb::break_id_t break_id) const { - Mutex::Locker locker(m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); return std::find_if(m_bp_site_list.begin(), m_bp_site_list.end(), // Search full range BreakpointSiteIDMatches(break_id)); // Predicate } @@ -140,7 +138,7 @@ BreakpointSiteList::GetIDConstIterator (lldb::break_id_t break_id) const BreakpointSiteSP BreakpointSiteList::FindByID (lldb::break_id_t break_id) { - Mutex::Locker locker(m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); BreakpointSiteSP stop_sp; collection::iterator pos = GetIDIterator(break_id); if (pos != m_bp_site_list.end()) @@ -152,7 +150,7 @@ BreakpointSiteList::FindByID (lldb::break_id_t break_id) const BreakpointSiteSP BreakpointSiteList::FindByID (lldb::break_id_t break_id) const { - Mutex::Locker locker(m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); BreakpointSiteSP stop_sp; collection::const_iterator pos = GetIDConstIterator(break_id); if (pos != m_bp_site_list.end()) @@ -165,7 +163,7 @@ BreakpointSiteSP BreakpointSiteList::FindByAddress (lldb::addr_t addr) { BreakpointSiteSP found_sp; - Mutex::Locker locker(m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); collection::iterator iter = m_bp_site_list.find(addr); if (iter != m_bp_site_list.end()) found_sp = iter->second; @@ -175,7 +173,7 @@ BreakpointSiteList::FindByAddress (lldb::addr_t addr) bool BreakpointSiteList::BreakpointSiteContainsBreakpoint (lldb::break_id_t bp_site_id, lldb::break_id_t bp_id) { - Mutex::Locker locker(m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); collection::const_iterator pos = GetIDConstIterator(bp_site_id); if (pos != m_bp_site_list.end()) return pos->second->IsBreakpointAtThisSite (bp_id); @@ -200,7 +198,7 @@ BreakpointSiteList::Dump (Stream *s) const void BreakpointSiteList::ForEach (std::function <void(BreakpointSite *)> const &callback) { - Mutex::Locker locker(m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); for (auto pair : m_bp_site_list) callback (pair.second.get()); } @@ -210,8 +208,8 @@ BreakpointSiteList::FindInRange (lldb::addr_t lower_bound, lldb::addr_t upper_bo { if (lower_bound > upper_bound) return false; - - Mutex::Locker locker(m_mutex); + + std::lock_guard<std::recursive_mutex> guard(m_mutex); collection::const_iterator lower, upper, pos; lower = m_bp_site_list.lower_bound(lower_bound); if (lower == m_bp_site_list.end() diff --git a/lldb/source/Commands/CommandObjectTarget.cpp b/lldb/source/Commands/CommandObjectTarget.cpp index 1d92f317f95..1e7f1e54cc6 100644 --- a/lldb/source/Commands/CommandObjectTarget.cpp +++ b/lldb/source/Commands/CommandObjectTarget.cpp @@ -1978,7 +1978,7 @@ FindModulesByName (Target *target, if (check_global_list) { // Check the global list - Mutex::Locker locker(Module::GetAllocationModuleCollectionMutex()); + std::lock_guard<std::recursive_mutex> guard(Module::GetAllocationModuleCollectionMutex()); const size_t num_modules = Module::GetNumberAllocatedModules(); ModuleSP module_sp; for (size_t image_idx = 0; image_idx<num_modules; ++image_idx) @@ -2470,7 +2470,7 @@ protected: else { // Check the global list - Mutex::Locker locker(Module::GetAllocationModuleCollectionMutex()); + std::lock_guard<std::recursive_mutex> guard(Module::GetAllocationModuleCollectionMutex()); result.AppendWarningWithFormat("Unable to find an image that matches '%s'.\n", arg_cstr); } @@ -3291,16 +3291,20 @@ protected: } size_t num_modules = 0; - Mutex::Locker locker; // This locker will be locked on the mutex in module_list_ptr if it is non-nullptr. - // Otherwise it will lock the AllocationModuleCollectionMutex when accessing - // the global module list directly. + + // This locker will be locked on the mutex in module_list_ptr if it is non-nullptr. + // Otherwise it will lock the AllocationModuleCollectionMutex when accessing + // the global module list directly. + std::unique_lock<std::recursive_mutex> guard(Module::GetAllocationModuleCollectionMutex(), std::defer_lock); + Mutex::Locker locker; + const ModuleList *module_list_ptr = nullptr; const size_t argc = command.GetArgumentCount(); if (argc == 0) { if (use_global_module_list) { - locker.Lock (Module::GetAllocationModuleCollectionMutex()); + guard.lock(); num_modules = Module::GetNumberAllocatedModules(); } else @@ -3331,6 +3335,7 @@ protected: if (module_list_ptr != nullptr) { + assert(use_global_module_list == false && "locking violation"); locker.Lock(module_list_ptr->GetMutex()); num_modules = module_list_ptr->GetSize(); } diff --git a/lldb/source/Core/Broadcaster.cpp b/lldb/source/Core/Broadcaster.cpp index ec91f8d8a7f..30bc78b4822 100644 --- a/lldb/source/Core/Broadcaster.cpp +++ b/lldb/source/Core/Broadcaster.cpp @@ -32,12 +32,8 @@ Broadcaster::Broadcaster(BroadcasterManagerSP manager_sp, const char *name) : static_cast<void*>(this), GetBroadcasterName().AsCString()); } -Broadcaster::BroadcasterImpl::BroadcasterImpl (Broadcaster &broadcaster) : - m_broadcaster(broadcaster), - m_listeners (), - m_listeners_mutex (Mutex::eMutexTypeRecursive), - m_hijacking_listeners(), - m_hijacking_masks() +Broadcaster::BroadcasterImpl::BroadcasterImpl(Broadcaster &broadcaster) + : m_broadcaster(broadcaster), m_listeners(), m_listeners_mutex(), m_hijacking_listeners(), m_hijacking_masks() { } @@ -90,8 +86,8 @@ Broadcaster::BroadcasterImpl::ListenerIterator (std::function <bool (const lldb: void Broadcaster::BroadcasterImpl::Clear() { - Mutex::Locker listeners_locker(m_listeners_mutex); - + std::lock_guard<std::recursive_mutex> guard(m_listeners_mutex); + // Make sure the listener forgets about this broadcaster. We do // this in the broadcaster in case the broadcaster object initiates // the removal. @@ -152,7 +148,7 @@ Broadcaster::BroadcasterImpl::AddListener (const lldb::ListenerSP &listener_sp, if (!listener_sp) return 0; - Mutex::Locker locker(m_listeners_mutex); + std::lock_guard<std::recursive_mutex> guard(m_listeners_mutex); // See if we already have this listener, and if so, update its mask @@ -186,8 +182,8 @@ Broadcaster::BroadcasterImpl::AddListener (const lldb::ListenerSP &listener_sp, bool Broadcaster::BroadcasterImpl::EventTypeHasListeners (uint32_t event_type) { - Mutex::Locker locker (m_listeners_mutex); - + std::lock_guard<std::recursive_mutex> guard(m_listeners_mutex); + if (!m_hijacking_listeners.empty() && event_type & m_hijacking_masks.back()) return true; @@ -215,7 +211,7 @@ Broadcaster::BroadcasterImpl::RemoveListener (lldb_private::Listener *listener, { if (listener) { - Mutex::Locker locker(m_listeners_mutex); + std::lock_guard<std::recursive_mutex> guard(m_listeners_mutex); collection::iterator pos = m_listeners.begin(); // See if we already have this listener, and if so, update its mask while (pos != m_listeners.end()) @@ -275,7 +271,7 @@ Broadcaster::BroadcasterImpl::PrivateBroadcastEvent (EventSP &event_sp, bool uni const uint32_t event_type = event_sp->GetType(); - Mutex::Locker locker(m_listeners_mutex); + std::lock_guard<std::recursive_mutex> guard(m_listeners_mutex); ListenerSP hijacking_listener_sp; @@ -343,7 +339,7 @@ Broadcaster::BroadcasterImpl::BroadcastEventIfUnique (uint32_t event_type, Event bool Broadcaster::BroadcasterImpl::HijackBroadcaster (const lldb::ListenerSP &listener_sp, uint32_t event_mask) { - Mutex::Locker locker(m_listeners_mutex); + std::lock_guard<std::recursive_mutex> guard(m_listeners_mutex); Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_EVENTS)); if (log) @@ -358,7 +354,7 @@ Broadcaster::BroadcasterImpl::HijackBroadcaster (const lldb::ListenerSP &listene bool Broadcaster::BroadcasterImpl::IsHijackedForEvent (uint32_t event_mask) { - Mutex::Locker locker(m_listeners_mutex); + std::lock_guard<std::recursive_mutex> guard(m_listeners_mutex); if (!m_hijacking_listeners.empty()) return (event_mask & m_hijacking_masks.back()) != 0; @@ -381,7 +377,7 @@ Broadcaster::BroadcasterImpl::GetHijackingListenerName() void Broadcaster::BroadcasterImpl::RestoreBroadcaster () { - Mutex::Locker locker(m_listeners_mutex); + std::lock_guard<std::recursive_mutex> guard(m_listeners_mutex); if (!m_hijacking_listeners.empty()) { @@ -425,8 +421,7 @@ BroadcastEventSpec::operator< (const BroadcastEventSpec &rhs) const BroadcastEventSpec & BroadcastEventSpec::operator=(const BroadcastEventSpec &rhs) = default; -BroadcasterManager::BroadcasterManager() : - m_manager_mutex(Mutex::eMutexTypeRecursive) +BroadcasterManager::BroadcasterManager() : m_manager_mutex() { } @@ -439,8 +434,8 @@ BroadcasterManager::MakeBroadcasterManager() uint32_t BroadcasterManager::RegisterListenerForEvents (const lldb::ListenerSP &listener_sp, BroadcastEventSpec event_spec) { - Mutex::Locker locker(m_manager_mutex); - + std::lock_guard<std::recursive_mutex> guard(m_manager_mutex); + collection::iterator iter = m_event_map.begin(), end_iter = m_event_map.end(); uint32_t available_bits = event_spec.GetEventBits(); @@ -463,7 +458,7 @@ BroadcasterManager::RegisterListenerForEvents (const lldb::ListenerSP &listener_ bool BroadcasterManager::UnregisterListenerForEvents (const lldb::ListenerSP &listener_sp, BroadcastEventSpec event_spec) { - Mutex::Locker locker(m_manager_mutex); + std::lock_guard<std::recursive_mutex> guard(m_manager_mutex); bool removed_some = false; if (m_listeners.erase(listener_sp) == 0) @@ -508,8 +503,8 @@ BroadcasterManager::UnregisterListenerForEvents (const lldb::ListenerSP &listene ListenerSP BroadcasterManager::GetListenerForEventSpec (BroadcastEventSpec event_spec) const { - Mutex::Locker locker(*(const_cast<Mutex *> (&m_manager_mutex))); - + std::lock_guard<std::recursive_mutex> guard(m_manager_mutex); + collection::const_iterator iter, end_iter = m_event_map.end(); iter = find_if (m_event_map.begin(), end_iter, BroadcastEventSpecMatches (event_spec)); if (iter != end_iter) @@ -521,7 +516,7 @@ BroadcasterManager::GetListenerForEventSpec (BroadcastEventSpec event_spec) cons void BroadcasterManager::RemoveListener(Listener *listener) { - Mutex::Locker locker(m_manager_mutex); + std::lock_guard<std::recursive_mutex> guard(m_manager_mutex); ListenerMatchesPointer predicate (listener); listener_collection::iterator iter = m_listeners.begin(), end_iter = m_listeners.end(); @@ -543,7 +538,7 @@ BroadcasterManager::RemoveListener(Listener *listener) void BroadcasterManager::RemoveListener (const lldb::ListenerSP &listener_sp) { - Mutex::Locker locker(m_manager_mutex); + std::lock_guard<std::recursive_mutex> guard(m_manager_mutex); ListenerMatches predicate (listener_sp); if (m_listeners.erase (listener_sp) == 0) @@ -563,8 +558,8 @@ BroadcasterManager::RemoveListener (const lldb::ListenerSP &listener_sp) void BroadcasterManager::SignUpListenersForBroadcaster (Broadcaster &broadcaster) { - Mutex::Locker locker(m_manager_mutex); - + std::lock_guard<std::recursive_mutex> guard(m_manager_mutex); + collection::iterator iter = m_event_map.begin(), end_iter = m_event_map.end(); while (iter != end_iter @@ -578,7 +573,7 @@ BroadcasterManager::SignUpListenersForBroadcaster (Broadcaster &broadcaster) void BroadcasterManager::Clear () { - Mutex::Locker locker(m_manager_mutex); + std::lock_guard<std::recursive_mutex> guard(m_manager_mutex); listener_collection::iterator end_iter = m_listeners.end(); for (listener_collection::iterator iter = m_listeners.begin(); iter != end_iter; iter++) diff --git a/lldb/source/Core/Communication.cpp b/lldb/source/Core/Communication.cpp index 557fb95df69..f1dcb95e8af 100644 --- a/lldb/source/Core/Communication.cpp +++ b/lldb/source/Core/Communication.cpp @@ -33,31 +33,30 @@ Communication::GetStaticBroadcasterClass () return class_name; } -Communication::Communication(const char *name) : - Broadcaster(nullptr, name), - m_connection_sp(), - m_read_thread_enabled(false), - m_read_thread_did_exit(false), - m_bytes(), - m_bytes_mutex(Mutex::eMutexTypeRecursive), - m_write_mutex(Mutex::eMutexTypeNormal), - m_synchronize_mutex(Mutex::eMutexTypeNormal), - m_callback(nullptr), - m_callback_baton(nullptr), - m_close_on_eof(true) +Communication::Communication(const char *name) + : Broadcaster(nullptr, name), + m_connection_sp(), + m_read_thread_enabled(false), + m_read_thread_did_exit(false), + m_bytes(), + m_bytes_mutex(), + m_write_mutex(), + m_synchronize_mutex(), + m_callback(nullptr), + m_callback_baton(nullptr), + m_close_on_eof(true) { - lldb_private::LogIfAnyCategoriesSet (LIBLLDB_LOG_OBJECT | LIBLLDB_LOG_COMMUNICATION, - "%p Communication::Communication (name = %s)", - this, name); - - SetEventName (eBroadcastBitDisconnected, "disconnected"); - SetEventName (eBroadcastBitReadThreadGotBytes, "got bytes"); - SetEventName (eBroadcastBitReadThreadDidExit, "read thread did exit"); - SetEventName (eBroadcastBitReadThreadShouldExit, "read thread should exit"); - SetEventName (eBroadcastBitPacketAvailable, "packet available"); - SetEventName (eBroadcastBitNoMorePendingInput, "no more pending input"); - + lldb_private::LogIfAnyCategoriesSet(LIBLLDB_LOG_OBJECT | LIBLLDB_LOG_COMMUNICATION, + "%p Communication::Communication (name = %s)", this, name); + + SetEventName(eBroadcastBitDisconnected, "disconnected"); + SetEventName(eBroadcastBitReadThreadGotBytes, "got bytes"); + SetEventName(eBroadcastBitReadThreadDidExit, "read thread did exit"); + SetEventName(eBroadcastBitReadThreadShouldExit, "read thread should exit"); + SetEventName(eBroadcastBitPacketAvailable, "packet available"); + SetEventName(eBroadcastBitNoMorePendingInput, "no more pending input"); + CheckInWithManager(); } @@ -205,7 +204,7 @@ Communication::Write (const void *src, size_t src_len, ConnectionStatus &status, { lldb::ConnectionSP connection_sp (m_connection_sp); - Mutex::Locker locker(m_write_mutex); + std::lock_guard<std::mutex> guard(m_write_mutex); lldb_private::LogIfAnyCategoriesSet (LIBLLDB_LOG_COMMUNICATION, "%p Communication::Write (src = %p, src_len = %" PRIu64 ") connection = %p", this, @@ -277,7 +276,7 @@ Communication::JoinReadThread (Error *error_ptr) size_t Communication::GetCachedBytes (void *dst, size_t dst_len) { - Mutex::Locker locker(m_bytes_mutex); + std::lock_guard<std::recursive_mutex> guard(m_bytes_mutex); if (!m_bytes.empty()) { // If DST is nullptr and we have a thread, then return the number @@ -311,7 +310,7 @@ Communication::AppendBytesToCache (const uint8_t * bytes, size_t len, bool broad } else if (bytes != nullptr && len > 0) { - Mutex::Locker locker(m_bytes_mutex); + std::lock_guard<std::recursive_mutex> guard(m_bytes_mutex); m_bytes.append ((const char *)bytes, len); if (broadcast) BroadcastEventIfUnique (eBroadcastBitReadThreadGotBytes); @@ -425,7 +424,7 @@ void Communication::SynchronizeWithReadThread () { // Only one thread can do the synchronization dance at a time. - Mutex::Locker locker(m_synchronize_mutex); + std::lock_guard<std::mutex> guard(m_synchronize_mutex); // First start listening for the synchronization event. ListenerSP listener_sp(Listener::MakeListener("Communication::SyncronizeWithReadThread")); diff --git a/lldb/source/Core/Debugger.cpp b/lldb/source/Core/Debugger.cpp index 16502159b6b..d5727efe6a3 100644 --- a/lldb/source/Core/Debugger.cpp +++ b/lldb/source/Core/Debugger.cpp @@ -12,6 +12,7 @@ // C Includes // C++ Includes #include <map> +#include <mutex> // Other libraries and framework includes #include "llvm/ADT/StringRef.h" @@ -67,10 +68,10 @@ static size_t g_debugger_event_thread_stack_bytes = 8 * 1024 * 1024; #pragma mark Static Functions -static Mutex & -GetDebuggerListMutex () +static std::recursive_mutex & +GetDebuggerListMutex() { - static Mutex g_mutex(Mutex::eMutexTypeRecursive); + static std::recursive_mutex g_mutex; return g_mutex; } @@ -469,7 +470,7 @@ Debugger::Terminate () assert(lldb_initialized && "Debugger::Terminate called without a matching Debugger::Initialize!"); // Clear our master list of debugger objects - Mutex::Locker locker (GetDebuggerListMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetDebuggerListMutex()); auto& debuggers = GetDebuggerList(); for (const auto& debugger: debuggers) debugger->Clear(); @@ -605,7 +606,7 @@ Debugger::CreateInstance (lldb::LogOutputCallback log_callback, void *baton) DebuggerSP debugger_sp (new Debugger(log_callback, baton)); if (lldb_initialized) { - Mutex::Locker locker (GetDebuggerListMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetDebuggerListMutex()); GetDebuggerList().push_back(debugger_sp); } debugger_sp->InstanceInitialize (); @@ -622,7 +623,7 @@ Debugger::Destroy (DebuggerSP &debugger_sp) if (lldb_initialized) { - Mutex::Locker locker (GetDebuggerListMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetDebuggerListMutex()); DebuggerList &debugger_list = GetDebuggerList (); DebuggerList::iterator pos, end = debugger_list.end(); for (pos = debugger_list.begin (); pos != end; ++pos) @@ -642,7 +643,7 @@ Debugger::FindDebuggerWithInstanceName (const ConstString &instance_name) DebuggerSP debugger_sp; if (lldb_initialized) { - Mutex::Locker locker (GetDebuggerListMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetDebuggerListMutex()); DebuggerList &debugger_list = GetDebuggerList(); DebuggerList::iterator pos, end = debugger_list.end(); @@ -664,7 +665,7 @@ Debugger::FindTargetWithProcessID (lldb::pid_t pid) TargetSP target_sp; if (lldb_initialized) { - Mutex::Locker locker (GetDebuggerListMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetDebuggerListMutex()); DebuggerList &debugger_list = GetDebuggerList(); DebuggerList::iterator pos, end = debugger_list.end(); for (pos = debugger_list.begin(); pos != end; ++pos) @@ -683,7 +684,7 @@ Debugger::FindTargetWithProcess (Process *process) TargetSP target_sp; if (lldb_initialized) { - Mutex::Locker locker (GetDebuggerListMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetDebuggerListMutex()); DebuggerList &debugger_list = GetDebuggerList(); DebuggerList::iterator pos, end = debugger_list.end(); for (pos = debugger_list.begin(); pos != end; ++pos) @@ -922,33 +923,33 @@ Debugger::GetSelectedExecutionContext () } void -Debugger::DispatchInputInterrupt () +Debugger::DispatchInputInterrupt() { - Mutex::Locker locker (m_input_reader_stack.GetMutex()); - IOHandlerSP reader_sp (m_input_reader_stack.Top()); + std::lock_guard<std::recursive_mutex> guard(m_input_reader_stack.GetMutex()); + IOHandlerSP reader_sp(m_input_reader_stack.Top()); if (reader_sp) reader_sp->Interrupt(); } void -Debugger::DispatchInputEndOfFile () +Debugger::DispatchInputEndOfFile() { - Mutex::Locker locker (m_input_reader_stack.GetMutex()); - IOHandlerSP reader_sp (m_input_reader_stack.Top()); + std::lock_guard<std::recursive_mutex> guard(m_input_reader_stack.GetMutex()); + IOHandlerSP reader_sp(m_input_reader_stack.Top()); if (reader_sp) reader_sp->GotEOF(); } void -Debugger::ClearIOHandlers () +Debugger::ClearIOHandlers() { // The bottom input reader should be the main debugger input reader. We do not want to close that one here. - Mutex::Locker locker (m_input_reader_stack.GetMutex()); + std::lock_guard<std::recursive_mutex> guard(m_input_reader_stack.GetMutex()); while (m_input_reader_stack.GetSize() > 1) { - IOHandlerSP reader_sp (m_input_reader_stack.Top()); + IOHandlerSP reader_sp(m_input_reader_stack.Top()); if (reader_sp) - PopIOHandler (reader_sp); + PopIOHandler(reader_sp); } } @@ -1041,16 +1042,16 @@ Debugger::RunIOHandler (const IOHandlerSP& reader_sp) } void -Debugger::AdoptTopIOHandlerFilesIfInvalid (StreamFileSP &in, StreamFileSP &out, StreamFileSP &err) +Debugger::AdoptTopIOHandlerFilesIfInvalid(StreamFileSP &in, StreamFileSP &out, StreamFileSP &err) { // Before an IOHandler runs, it must have in/out/err streams. // This function is called when one ore more of the streams // are nullptr. We use the top input reader's in/out/err streams, // or fall back to the debugger file handles, or we fall back // onto stdin/stdout/stderr as a last resort. - - Mutex::Locker locker (m_input_reader_stack.GetMutex()); - IOHandlerSP top_reader_sp (m_input_reader_stack.Top()); + + std::lock_guard<std::recursive_mutex> guard(m_input_reader_stack.GetMutex()); + IOHandlerSP top_reader_sp(m_input_reader_stack.Top()); // If no STDIN has been set, then set it appropriately if (!in) { @@ -1058,7 +1059,7 @@ Debugger::AdoptTopIOHandlerFilesIfInvalid (StreamFileSP &in, StreamFileSP &out, in = top_reader_sp->GetInputStreamFile(); else in = GetInputFile(); - + // If there is nothing, use stdin if (!in) in = StreamFileSP(new StreamFile(stdin, false)); @@ -1070,7 +1071,7 @@ Debugger::AdoptTopIOHandlerFilesIfInvalid (StreamFileSP &in, StreamFileSP &out, out = top_reader_sp->GetOutputStreamFile(); else out = GetOutputFile(); - + // If there is nothing, use stdout if (!out) out = StreamFileSP(new StreamFile(stdout, false)); @@ -1082,31 +1083,30 @@ Debugger::AdoptTopIOHandlerFilesIfInvalid (StreamFileSP &in, StreamFileSP &out, err = top_reader_sp->GetErrorStreamFile(); else err = GetErrorFile(); - + // If there is nothing, use stderr if (!err) err = StreamFileSP(new StreamFile(stdout, false)); - } } void -Debugger::PushIOHandler (const IOHandlerSP& reader_sp) +Debugger::PushIOHandler(const IOHandlerSP &reader_sp) { if (!reader_sp) return; - - Mutex::Locker locker (m_input_reader_stack.GetMutex()); + + std::lock_guard<std::recursive_mutex> guard(m_input_reader_stack.GetMutex()); // Get the current top input reader... - IOHandlerSP top_reader_sp (m_input_reader_stack.Top()); - + IOHandlerSP top_reader_sp(m_input_reader_stack.Top()); + // Don't push the same IO handler twice... if (reader_sp == top_reader_sp) return; // Push our new input reader - m_input_reader_stack.Push (reader_sp); + m_input_reader_stack.Push(reader_sp); reader_sp->Activate(); // Interrupt the top input reader to it will exit its Run() function @@ -1119,12 +1119,12 @@ Debugger::PushIOHandler (const IOHandlerSP& reader_sp) } bool -Debugger::PopIOHandler (const IOHandlerSP& pop_reader_sp) +Debugger::PopIOHandler(const IOHandlerSP &pop_reader_sp) { - if (! pop_reader_sp) + if (!pop_reader_sp) return false; - Mutex::Locker locker (m_input_reader_stack.GetMutex()); + std::lock_guard<std::recursive_mutex> guard(m_input_reader_stack.GetMutex()); // The reader on the stop of the stack is done, so let the next // read on the stack refresh its prompt and if there is one... @@ -1138,7 +1138,7 @@ Debugger::PopIOHandler (const IOHandlerSP& pop_reader_sp) reader_sp->Deactivate(); reader_sp->Cancel(); - m_input_reader_stack.Pop (); + m_input_reader_stack.Pop(); reader_sp = m_input_reader_stack.Top(); if (reader_sp) @@ -1164,7 +1164,7 @@ Debugger::GetNumDebuggers() { if (lldb_initialized) { - Mutex::Locker locker (GetDebuggerListMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetDebuggerListMutex()); return GetDebuggerList().size(); } return 0; @@ -1177,9 +1177,9 @@ Debugger::GetDebuggerAtIndex (size_t index) if (lldb_initialized) { - Mutex::Locker locker (GetDebuggerListMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetDebuggerListMutex()); DebuggerList &debugger_list = GetDebuggerList(); - + if (index < debugger_list.size()) debugger_sp = debugger_list[index]; } @@ -1194,7 +1194,7 @@ Debugger::FindDebuggerWithID (lldb::user_id_t id) if (lldb_initialized) { - Mutex::Locker locker (GetDebuggerListMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetDebuggerListMutex()); DebuggerList &debugger_list = GetDebuggerList(); DebuggerList::iterator pos, end = debugger_list.end(); for (pos = debugger_list.begin(); pos != end; ++pos) diff --git a/lldb/source/Core/IOHandler.cpp b/lldb/source/Core/IOHandler.cpp index a73fce8aa45..abc83f25167 100644 --- a/lldb/source/Core/IOHandler.cpp +++ b/lldb/source/Core/IOHandler.cpp @@ -169,13 +169,13 @@ IOHandler::WaitForPop () } void -IOHandlerStack::PrintAsync (Stream *stream, const char *s, size_t len) +IOHandlerStack::PrintAsync(Stream *stream, const char *s, size_t len) { if (stream) { - Mutex::Locker locker (m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); if (m_top) - m_top->PrintAsync (stream, s, len); + m_top->PrintAsync(stream, s, len); } } diff --git a/lldb/source/Core/Listener.cpp b/lldb/source/Core/Listener.cpp index 7c862db1b14..15a69878468 100644 --- a/lldb/source/Core/Listener.cpp +++ b/lldb/source/Core/Listener.cpp @@ -40,12 +40,8 @@ namespace }; } // anonymous namespace -Listener::Listener(const char *name) : - m_name (name), - m_broadcasters(), - m_broadcasters_mutex (Mutex::eMutexTypeRecursive), - m_events (), - m_events_mutex (Mutex::eMutexTypeNormal) +Listener::Listener(const char *name) + : m_name(name), m_broadcasters(), m_broadcasters_mutex(), m_events(), m_events_mutex(Mutex::eMutexTypeNormal) { Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT)); if (log != nullptr) @@ -67,7 +63,7 @@ void Listener::Clear() { Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT)); - Mutex::Locker locker(m_broadcasters_mutex); + std::lock_guard<std::recursive_mutex> guard(m_broadcasters_mutex); broadcaster_collection::iterator pos, end = m_broadcasters.end(); for (pos = m_broadcasters.begin(); pos != end; ++pos) { @@ -100,7 +96,7 @@ Listener::StartListeningForEvents (Broadcaster* broadcaster, uint32_t event_mask // Scope for "locker" // Tell the broadcaster to add this object as a listener { - Mutex::Locker locker(m_broadcasters_mutex); + std::lock_guard<std::recursive_mutex> guard(m_broadcasters_mutex); Broadcaster::BroadcasterImplWP impl_wp(broadcaster->GetBroadcasterImpl()); m_broadcasters.insert(std::make_pair(impl_wp, BroadcasterInfo(event_mask))); } @@ -127,7 +123,7 @@ Listener::StartListeningForEvents (Broadcaster* broadcaster, uint32_t event_mask // Scope for "locker" // Tell the broadcaster to add this object as a listener { - Mutex::Locker locker(m_broadcasters_mutex); + std::lock_guard<std::recursive_mutex> guard(m_broadcasters_mutex); Broadcaster::BroadcasterImplWP impl_wp(broadcaster->GetBroadcasterImpl()); m_broadcasters.insert(std::make_pair(impl_wp, BroadcasterInfo(event_mask, callback, callback_user_data))); @@ -158,7 +154,7 @@ Listener::StopListeningForEvents (Broadcaster* broadcaster, uint32_t event_mask) { // Scope for "locker" { - Mutex::Locker locker(m_broadcasters_mutex); + std::lock_guard<std::recursive_mutex> guard(m_broadcasters_mutex); m_broadcasters.erase (broadcaster->GetBroadcasterImpl()); } // Remove the broadcaster from our set of broadcasters @@ -175,7 +171,7 @@ Listener::BroadcasterWillDestruct (Broadcaster *broadcaster) { // Scope for "broadcasters_locker" { - Mutex::Locker broadcasters_locker(m_broadcasters_mutex); + std::lock_guard<std::recursive_mutex> guard(m_broadcasters_mutex); m_broadcasters.erase (broadcaster->GetBroadcasterImpl()); } @@ -474,7 +470,7 @@ size_t Listener::HandleBroadcastEvent (EventSP &event_sp) { size_t num_handled = 0; - Mutex::Locker locker(m_broadcasters_mutex); + std::lock_guard<std::recursive_mutex> guard(m_broadcasters_mutex); Broadcaster *broadcaster = event_sp->GetBroadcaster(); if (!broadcaster) return 0; @@ -507,8 +503,8 @@ Listener::StartListeningForEventSpec (BroadcasterManagerSP manager_sp, // The BroadcasterManager mutex must be locked before m_broadcasters_mutex // to avoid violating the lock hierarchy (manager before broadcasters). - Mutex::Locker manager_locker(manager_sp->m_manager_mutex); - Mutex::Locker locker(m_broadcasters_mutex); + std::lock_guard<std::recursive_mutex> manager_guard(manager_sp->m_manager_mutex); + std::lock_guard<std::recursive_mutex> guard(m_broadcasters_mutex); uint32_t bits_acquired = manager_sp->RegisterListenerForEvents(this->shared_from_this(), event_spec); if (bits_acquired) @@ -530,8 +526,8 @@ Listener::StopListeningForEventSpec (BroadcasterManagerSP manager_sp, { if (!manager_sp) return false; - - Mutex::Locker locker(m_broadcasters_mutex); + + std::lock_guard<std::recursive_mutex> guard(m_broadcasters_mutex); return manager_sp->UnregisterListenerForEvents (this->shared_from_this(), event_spec); } diff --git a/lldb/source/Core/Log.cpp b/lldb/source/Core/Log.cpp index 9a356e6fce2..a292df3ed52 100644 --- a/lldb/source/Core/Log.cpp +++ b/lldb/source/Core/Log.cpp @@ -9,10 +9,11 @@ // C Includes // C++ Includes -#include <cstdio> #include <cstdarg> +#include <cstdio> #include <cstdlib> #include <map> +#include <mutex> #include <string> // Other libraries and framework includes @@ -26,7 +27,6 @@ #include "lldb/Core/StreamFile.h" #include "lldb/Core/StreamString.h" #include "lldb/Host/Host.h" -#include "lldb/Host/Mutex.h" #include "lldb/Host/ThisThread.h" #include "lldb/Host/TimeValue.h" #include "lldb/Interpreter/Args.h" @@ -147,8 +147,8 @@ Log::VAPrintf(const char *format, va_list args) if (m_options.Test(LLDB_LOG_OPTION_THREADSAFE)) { - static Mutex g_LogThreadedMutex(Mutex::eMutexTypeRecursive); - Mutex::Locker locker(g_LogThreadedMutex); + static std::recursive_mutex g_LogThreadedMutex; + std::lock_guard<std::recursive_mutex> guard(g_LogThreadedMutex); stream_sp->PutCString(header.GetString().c_str()); stream_sp->Flush(); } diff --git a/lldb/source/Core/Module.cpp b/lldb/source/Core/Module.cpp index 0f8ab5d9c9d..f58ec666958 100644 --- a/lldb/source/Core/Module.cpp +++ b/lldb/source/Core/Module.cpp @@ -72,7 +72,7 @@ GetModuleCollection() return *g_module_collection; } -Mutex * +std::recursive_mutex & Module::GetAllocationModuleCollectionMutex() { // NOTE: The mutex below must be leaked since the global module list in @@ -80,23 +80,23 @@ Module::GetAllocationModuleCollectionMutex() // if it will tear itself down before the "g_module_collection_mutex" below // will. So we leak a Mutex object below to safeguard against that - static Mutex *g_module_collection_mutex = nullptr; + static std::recursive_mutex *g_module_collection_mutex = nullptr; if (g_module_collection_mutex == nullptr) - g_module_collection_mutex = new Mutex (Mutex::eMutexTypeRecursive); // NOTE: known leak - return g_module_collection_mutex; + g_module_collection_mutex = new std::recursive_mutex; // NOTE: known leak + return *g_module_collection_mutex; } size_t Module::GetNumberAllocatedModules () { - Mutex::Locker locker (GetAllocationModuleCollectionMutex()); + std::lock_guard<std::recursive_mutex> guard(GetAllocationModuleCollectionMutex()); return GetModuleCollection().size(); } Module * Module::GetAllocatedModuleAtIndex (size_t idx) { - Mutex::Locker locker (GetAllocationModuleCollectionMutex()); + std::lock_guard<std::recursive_mutex> guard(GetAllocationModuleCollectionMutex()); ModuleCollection &modules = GetModuleCollection(); if (idx < modules.size()) return modules[idx]; @@ -140,44 +140,42 @@ namespace lldb { #endif -Module::Module (const ModuleSpec &module_spec) : - m_mutex (Mutex::eMutexTypeRecursive), - m_mod_time (), - m_arch (), - m_uuid (), - m_file (), - m_platform_file(), - m_remote_install_file(), - m_symfile_spec (), - m_object_name (), - m_object_offset (), - m_object_mod_time (), - m_objfile_sp (), - m_symfile_ap (), - m_type_system_map(), - m_source_mappings (), - m_sections_ap(), - m_did_load_objfile (false), - m_did_load_symbol_vendor (false), - m_did_parse_uuid (false), - m_file_has_changed (false), - m_first_file_changed_log (false) +Module::Module(const ModuleSpec &module_spec) + : m_mutex(), + m_mod_time(), + m_arch(), + m_uuid(), + m_file(), + m_platform_file(), + m_remote_install_file(), + m_symfile_spec(), + m_object_name(), + m_object_offset(), + m_object_mod_time(), + m_objfile_sp(), + m_symfile_ap(), + m_type_system_map(), + m_source_mappings(), + m_sections_ap(), + m_did_load_objfile(false), + m_did_load_symbol_vendor(false), + m_did_parse_uuid(false), + m_file_has_changed(false), + m_first_file_changed_log(false) { // Scope for locker below... { - Mutex::Locker locker (GetAllocationModuleCollectionMutex()); + std::lock_guard<std::recursive_mutex> guard(GetAllocationModuleCollectionMutex()); GetModuleCollection().push_back(this); } - Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_OBJECT|LIBLLDB_LOG_MODULES)); + Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_OBJECT | LIBLLDB_LOG_MODULES)); if (log != nullptr) - log->Printf ("%p Module::Module((%s) '%s%s%s%s')", - static_cast<void*>(this), - module_spec.GetArchitecture().GetArchitectureName(), - module_spec.GetFileSpec().GetPath().c_str(), - module_spec.GetObjectName().IsEmpty() ? "" : "(", - module_spec.GetObjectName().IsEmpty() ? "" : module_spec.GetObjectName().AsCString(""), - module_spec.GetObjectName().IsEmpty() ? "" : ")"); + log->Printf("%p Module::Module((%s) '%s%s%s%s')", static_cast<void *>(this), + module_spec.GetArchitecture().GetArchitectureName(), module_spec.GetFileSpec().GetPath().c_str(), + module_spec.GetObjectName().IsEmpty() ? "" : "(", + module_spec.GetObjectName().IsEmpty() ? "" : module_spec.GetObjectName().AsCString(""), + module_spec.GetObjectName().IsEmpty() ? "" : ")"); // First extract all module specifications from the file using the local // file path. If there are no specifications, then don't fill anything in @@ -194,18 +192,18 @@ Module::Module (const ModuleSpec &module_spec) : ModuleSpec matching_module_spec; if (modules_specs.FindMatchingModuleSpec(module_spec, matching_module_spec) == 0) return; - + if (module_spec.GetFileSpec()) m_mod_time = module_spec.GetFileSpec().GetModificationTime(); else if (matching_module_spec.GetFileSpec()) m_mod_time = matching_module_spec.GetFileSpec().GetModificationTime(); - + // Copy the architecture from the actual spec if we got one back, else use the one that was specified if (matching_module_spec.GetArchitecture().IsValid()) m_arch = matching_module_spec.GetArchitecture(); else if (module_spec.GetArchitecture().IsValid()) m_arch = module_spec.GetArchitecture(); - + // Copy the file spec over and use the specified one (if there was one) so we // don't use a path that might have gotten resolved a path in 'matching_module_spec' if (module_spec.GetFileSpec()) @@ -218,57 +216,53 @@ Module::Module (const ModuleSpec &module_spec) : m_platform_file = module_spec.GetPlatformFileSpec(); else if (matching_module_spec.GetPlatformFileSpec()) m_platform_file = matching_module_spec.GetPlatformFileSpec(); - + // Copy the symbol file spec over if (module_spec.GetSymbolFileSpec()) m_symfile_spec = module_spec.GetSymbolFileSpec(); else if (matching_module_spec.GetSymbolFileSpec()) m_symfile_spec = matching_module_spec.GetSymbolFileSpec(); - + // Copy the object name over if (matching_module_spec.GetObjectName()) m_object_name = matching_module_spec.GetObjectName(); else m_object_name = module_spec.GetObjectName(); - + // Always trust the object offset (file offset) and object modification // time (for mod time in a BSD static archive) of from the matching // module specification m_object_offset = matching_module_spec.GetObjectOffset(); m_object_mod_time = matching_module_spec.GetObjectModificationTime(); - } -Module::Module(const FileSpec& file_spec, - const ArchSpec& arch, - const ConstString *object_name, - lldb::offset_t object_offset, - const TimeValue *object_mod_time_ptr) : - m_mutex (Mutex::eMutexTypeRecursive), - m_mod_time (file_spec.GetModificationTime()), - m_arch (arch), - m_uuid (), - m_file (file_spec), - m_platform_file(), - m_remote_install_file (), - m_symfile_spec (), - m_object_name (), - m_object_offset (object_offset), - m_object_mod_time (), - m_objfile_sp (), - m_symfile_ap (), - m_type_system_map(), - m_source_mappings (), - m_sections_ap(), - m_did_load_objfile (false), - m_did_load_symbol_vendor (false), - m_did_parse_uuid (false), - m_file_has_changed (false), - m_first_file_changed_log (false) +Module::Module(const FileSpec &file_spec, const ArchSpec &arch, const ConstString *object_name, + lldb::offset_t object_offset, const TimeValue *object_mod_time_ptr) + : m_mutex(), + m_mod_time(file_spec.GetModificationTime()), + m_arch(arch), + m_uuid(), + m_file(file_spec), + m_platform_file(), + m_remote_install_file(), + m_symfile_spec(), + m_object_name(), + m_object_offset(object_offset), + m_object_mod_time(), + m_objfile_sp(), + m_symfile_ap(), + m_type_system_map(), + m_source_mappings(), + m_sections_ap(), + m_did_load_objfile(false), + m_did_load_symbol_vendor(false), + m_did_parse_uuid(false), + m_file_has_changed(false), + m_first_file_changed_log(false) { // Scope for locker below... { - Mutex::Locker locker (GetAllocationModuleCollectionMutex()); + std::lock_guard<std::recursive_mutex> guard(GetAllocationModuleCollectionMutex()); GetModuleCollection().push_back(this); } @@ -278,40 +272,37 @@ Module::Module(const FileSpec& file_spec, if (object_mod_time_ptr) m_object_mod_time = *object_mod_time_ptr; - Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_OBJECT|LIBLLDB_LOG_MODULES)); + Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_OBJECT | LIBLLDB_LOG_MODULES)); if (log != nullptr) - log->Printf ("%p Module::Module((%s) '%s%s%s%s')", - static_cast<void*>(this), m_arch.GetArchitectureName(), - m_file.GetPath().c_str(), - m_object_name.IsEmpty() ? "" : "(", - m_object_name.IsEmpty() ? "" : m_object_name.AsCString(""), - m_object_name.IsEmpty() ? "" : ")"); -} - -Module::Module () : - m_mutex (Mutex::eMutexTypeRecursive), - m_mod_time (), - m_arch (), - m_uuid (), - m_file (), - m_platform_file(), - m_remote_install_file (), - m_symfile_spec (), - m_object_name (), - m_object_offset (0), - m_object_mod_time (), - m_objfile_sp (), - m_symfile_ap (), - m_type_system_map(), - m_source_mappings (), - m_sections_ap(), - m_did_load_objfile (false), - m_did_load_symbol_vendor (false), - m_did_parse_uuid (false), - m_file_has_changed (false), - m_first_file_changed_log (false) -{ - Mutex::Locker locker (GetAllocationModuleCollectionMutex()); + log->Printf("%p Module::Module((%s) '%s%s%s%s')", static_cast<void *>(this), m_arch.GetArchitectureName(), + m_file.GetPath().c_str(), m_object_name.IsEmpty() ? "" : "(", + m_object_name.IsEmpty() ? "" : m_object_name.AsCString(""), m_object_name.IsEmpty() ? "" : ")"); +} + +Module::Module() + : m_mutex(), + m_mod_time(), + m_arch(), + m_uuid(), + m_file(), + m_platform_file(), + m_remote_install_file(), + m_symfile_spec(), + m_object_name(), + m_object_offset(0), + m_object_mod_time(), + m_objfile_sp(), + m_symfile_ap(), + m_type_system_map(), + m_source_mappings(), + m_sections_ap(), + m_did_load_objfile(false), + m_did_load_symbol_vendor(false), + m_did_parse_uuid(false), + m_file_has_changed(false), + m_first_file_changed_log(false) +{ + std::lock_guard<std::recursive_mutex> guard(GetAllocationModuleCollectionMutex()); GetModuleCollection().push_back(this); } @@ -319,10 +310,10 @@ Module::~Module() { // Lock our module down while we tear everything down to make sure // we don't get any access to the module while it is being destroyed - Mutex::Locker locker (m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); // Scope for locker below... { - Mutex::Locker locker (GetAllocationModuleCollectionMutex()); + std::lock_guard<std::recursive_mutex> guard(GetAllocationModuleCollectionMutex()); ModuleCollection &modules = GetModuleCollection(); ModuleCollection::iterator end = modules.end(); ModuleCollection::iterator pos = std::find(modules.begin(), end, this); @@ -357,7 +348,7 @@ Module::GetMemoryObjectFile (const lldb::ProcessSP &process_sp, lldb::addr_t hea } else { - Mutex::Locker locker (m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); if (process_sp) { m_did_load_objfile = true; @@ -405,7 +396,7 @@ Module::GetUUID() { if (!m_did_parse_uuid.load()) { - Mutex::Locker locker (m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); if (!m_did_parse_uuid.load()) { ObjectFile * obj_file = GetObjectFile (); @@ -429,7 +420,7 @@ Module::GetTypeSystemForLanguage (LanguageType language) void Module::ParseAllDebugSymbols() { - Mutex::Locker locker (m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); size_t num_comp_units = GetNumCompileUnits(); if (num_comp_units == 0) return; @@ -484,7 +475,7 @@ Module::DumpSymbolContext(Stream *s) size_t Module::GetNumCompileUnits() { - Mutex::Locker locker (m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); Timer scoped_timer(__PRETTY_FUNCTION__, "Module::GetNumCompileUnits (module = %p)", static_cast<void*>(this)); @@ -497,7 +488,7 @@ Module::GetNumCompileUnits() CompUnitSP Module::GetCompileUnitAtIndex (size_t index) { - Mutex::Locker locker (m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); size_t num_comp_units = GetNumCompileUnits (); CompUnitSP cu_sp; @@ -513,7 +504,7 @@ Module::GetCompileUnitAtIndex (size_t index) bool Module::ResolveFileAddress (lldb::addr_t vm_addr, Address& so_addr) { - Mutex::Locker locker (m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); Timer scoped_timer(__PRETTY_FUNCTION__, "Module::ResolveFileAddress (vm_addr = 0x%" PRIx64 ")", vm_addr); SectionList *section_list = GetSectionList(); if (section_list) @@ -525,7 +516,7 @@ uint32_t Module::ResolveSymbolContextForAddress (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc, bool resolve_tail_call_address) { - Mutex::Locker locker (m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); uint32_t resolved_flags = 0; // Clear the result symbol context in case we don't find anything, but don't clear the target @@ -675,7 +666,7 @@ Module::ResolveSymbolContextForFilePath uint32_t Module::ResolveSymbolContextsForFileSpec (const FileSpec &file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list) { - Mutex::Locker locker (m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); Timer scoped_timer(__PRETTY_FUNCTION__, "Module::ResolveSymbolContextForFilePath (%s:%u, check_inlines = %s, resolve_scope = 0x%8.8x)", file_spec.GetPath().c_str(), @@ -1037,7 +1028,7 @@ Module::GetSymbolVendor (bool can_create, lldb_private::Stream *feedback_strm) { if (!m_did_load_symbol_vendor.load()) { - Mutex::Locker locker (m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); if (!m_did_load_symbol_vendor.load() && can_create) { ObjectFile *obj_file = GetObjectFile (); @@ -1084,7 +1075,7 @@ Module::GetSpecificationDescription () const void Module::GetDescription (Stream *s, lldb::DescriptionLevel level) { - Mutex::Locker locker (m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); if (level >= eDescriptionLevelFull) { @@ -1245,7 +1236,7 @@ Module::LogMessageVerboseBacktrace (Log *log, const char *format, ...) void Module::Dump(Stream *s) { - Mutex::Locker locker (m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); //s->Printf("%.*p: ", (int)sizeof(void*) * 2, this); s->Indent(); s->Printf("Module %s%s%s%s\n", @@ -1287,7 +1278,7 @@ Module::GetObjectFile() { if (!m_did_load_objfile.load()) { - Mutex::Locker locker (m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); if (!m_did_load_objfile.load()) { Timer scoped_timer(__PRETTY_FUNCTION__, @@ -1710,14 +1701,14 @@ Module::MatchesModuleSpec (const ModuleSpec &module_ref) bool Module::FindSourceFile (const FileSpec &orig_spec, FileSpec &new_spec) const { - Mutex::Locker locker (m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); return m_source_mappings.FindFile (orig_spec, new_spec); } bool Module::RemapSourceFile (const char *path, std::string &new_path) const { - Mutex::Locker locker (m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); return m_source_mappings.RemapPath(path, new_path); } diff --git a/lldb/source/Core/PluginManager.cpp b/lldb/source/Core/PluginManager.cpp index 8f1ab568ae2..500b08b73e9 100644 --- a/lldb/source/Core/PluginManager.cpp +++ b/lldb/source/Core/PluginManager.cpp @@ -12,6 +12,7 @@ // C Includes // C++ Includes #include <climits> +#include <mutex> #include <string> #include <vector> @@ -25,7 +26,6 @@ #include "lldb/Host/FileSpec.h" #include "lldb/Host/Host.h" #include "lldb/Host/HostInfo.h" -#include "lldb/Host/Mutex.h" #include "lldb/Interpreter/OptionValueProperties.h" using namespace lldb; @@ -55,10 +55,10 @@ struct PluginInfo typedef std::map<FileSpec, PluginInfo> PluginTerminateMap; -static Mutex & -GetPluginMapMutex () +static std::recursive_mutex & +GetPluginMapMutex() { - static Mutex g_plugin_map_mutex (Mutex::eMutexTypeRecursive); + static std::recursive_mutex g_plugin_map_mutex; return g_plugin_map_mutex; } @@ -72,7 +72,7 @@ GetPluginMap () static bool PluginIsLoaded (const FileSpec &plugin_file_spec) { - Mutex::Locker locker (GetPluginMapMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetPluginMapMutex()); PluginTerminateMap &plugin_map = GetPluginMap (); return plugin_map.find (plugin_file_spec) != plugin_map.end(); } @@ -80,7 +80,7 @@ PluginIsLoaded (const FileSpec &plugin_file_spec) static void SetPluginInfo (const FileSpec &plugin_file_spec, const PluginInfo &plugin_info) { - Mutex::Locker locker (GetPluginMapMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetPluginMapMutex()); PluginTerminateMap &plugin_map = GetPluginMap (); assert (plugin_map.find (plugin_file_spec) == plugin_map.end()); plugin_map[plugin_file_spec] = plugin_info; @@ -209,7 +209,7 @@ PluginManager::Initialize () void PluginManager::Terminate () { - Mutex::Locker locker (GetPluginMapMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetPluginMapMutex()); PluginTerminateMap &plugin_map = GetPluginMap (); PluginTerminateMap::const_iterator pos, end = plugin_map.end(); @@ -244,10 +244,10 @@ struct ABIInstance typedef std::vector<ABIInstance> ABIInstances; -static Mutex & -GetABIInstancesMutex () +static std::recursive_mutex & +GetABIInstancesMutex() { - static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive); + static std::recursive_mutex g_instances_mutex; return g_instances_mutex; } @@ -271,7 +271,7 @@ PluginManager::RegisterPlugin(const ConstString &name, if (description && description[0]) instance.description = description; instance.create_callback = create_callback; - Mutex::Locker locker (GetABIInstancesMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetABIInstancesMutex()); GetABIInstances ().push_back (instance); return true; } @@ -283,7 +283,7 @@ PluginManager::UnregisterPlugin (ABICreateInstance create_callback) { if (create_callback) { - Mutex::Locker locker (GetABIInstancesMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetABIInstancesMutex()); ABIInstances &instances = GetABIInstances (); ABIInstances::iterator pos, end = instances.end(); @@ -302,7 +302,7 @@ PluginManager::UnregisterPlugin (ABICreateInstance create_callback) ABICreateInstance PluginManager::GetABICreateCallbackAtIndex (uint32_t idx) { - Mutex::Locker locker (GetABIInstancesMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetABIInstancesMutex()); ABIInstances &instances = GetABIInstances (); if (idx < instances.size()) return instances[idx].create_callback; @@ -314,7 +314,7 @@ PluginManager::GetABICreateCallbackForPluginName (const ConstString &name) { if (name) { - Mutex::Locker locker (GetABIInstancesMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetABIInstancesMutex()); ABIInstances &instances = GetABIInstances (); ABIInstances::iterator pos, end = instances.end(); @@ -345,10 +345,10 @@ struct DisassemblerInstance typedef std::vector<DisassemblerInstance> DisassemblerInstances; -static Mutex & -GetDisassemblerMutex () +static std::recursive_mutex & +GetDisassemblerMutex() { - static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive); + static std::recursive_mutex g_instances_mutex; return g_instances_mutex; } @@ -372,7 +372,7 @@ PluginManager::RegisterPlugin(const ConstString &name, if (description && description[0]) instance.description = description; instance.create_callback = create_callback; - Mutex::Locker locker (GetDisassemblerMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetDisassemblerMutex()); GetDisassemblerInstances ().push_back (instance); return true; } @@ -384,7 +384,7 @@ PluginManager::UnregisterPlugin (DisassemblerCreateInstance create_callback) { if (create_callback) { - Mutex::Locker locker (GetDisassemblerMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetDisassemblerMutex()); DisassemblerInstances &instances = GetDisassemblerInstances (); DisassemblerInstances::iterator pos, end = instances.end(); @@ -403,7 +403,7 @@ PluginManager::UnregisterPlugin (DisassemblerCreateInstance create_callback) DisassemblerCreateInstance PluginManager::GetDisassemblerCreateCallbackAtIndex (uint32_t idx) { - Mutex::Locker locker (GetDisassemblerMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetDisassemblerMutex()); DisassemblerInstances &instances = GetDisassemblerInstances (); if (idx < instances.size()) return instances[idx].create_callback; @@ -415,7 +415,7 @@ PluginManager::GetDisassemblerCreateCallbackForPluginName (const ConstString &na { if (name) { - Mutex::Locker locker (GetDisassemblerMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetDisassemblerMutex()); DisassemblerInstances &instances = GetDisassemblerInstances (); DisassemblerInstances::iterator pos, end = instances.end(); @@ -448,10 +448,10 @@ struct DynamicLoaderInstance typedef std::vector<DynamicLoaderInstance> DynamicLoaderInstances; -static Mutex & -GetDynamicLoaderMutex () +static std::recursive_mutex & +GetDynamicLoaderMutex() { - static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive); + static std::recursive_mutex g_instances_mutex; return g_instances_mutex; } @@ -477,7 +477,7 @@ PluginManager::RegisterPlugin(const ConstString &name, instance.description = description; instance.create_callback = create_callback; instance.debugger_init_callback = debugger_init_callback; - Mutex::Locker locker (GetDynamicLoaderMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetDynamicLoaderMutex()); GetDynamicLoaderInstances ().push_back (instance); } return false; @@ -488,7 +488,7 @@ PluginManager::UnregisterPlugin (DynamicLoaderCreateInstance create_callback) { if (create_callback) { - Mutex::Locker locker (GetDynamicLoaderMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetDynamicLoaderMutex()); DynamicLoaderInstances &instances = GetDynamicLoaderInstances (); DynamicLoaderInstances::iterator pos, end = instances.end(); @@ -507,7 +507,7 @@ PluginManager::UnregisterPlugin (DynamicLoaderCreateInstance create_callback) DynamicLoaderCreateInstance PluginManager::GetDynamicLoaderCreateCallbackAtIndex (uint32_t idx) { - Mutex::Locker locker (GetDynamicLoaderMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetDynamicLoaderMutex()); DynamicLoaderInstances &instances = GetDynamicLoaderInstances (); if (idx < instances.size()) return instances[idx].create_callback; @@ -519,7 +519,7 @@ PluginManager::GetDynamicLoaderCreateCallbackForPluginName (const ConstString &n { if (name) { - Mutex::Locker locker (GetDynamicLoaderMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetDynamicLoaderMutex()); DynamicLoaderInstances &instances = GetDynamicLoaderInstances (); DynamicLoaderInstances::iterator pos, end = instances.end(); @@ -552,10 +552,10 @@ struct JITLoaderInstance typedef std::vector<JITLoaderInstance> JITLoaderInstances; -static Mutex & -GetJITLoaderMutex () +static std::recursive_mutex & +GetJITLoaderMutex() { - static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive); + static std::recursive_mutex g_instances_mutex; return g_instances_mutex; } @@ -581,7 +581,7 @@ PluginManager::RegisterPlugin(const ConstString &name, instance.description = description; instance.create_callback = create_callback; instance.debugger_init_callback = debugger_init_callback; - Mutex::Locker locker (GetJITLoaderMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetJITLoaderMutex()); GetJITLoaderInstances ().push_back (instance); } return false; @@ -592,7 +592,7 @@ PluginManager::UnregisterPlugin (JITLoaderCreateInstance create_callback) { if (create_callback) { - Mutex::Locker locker (GetJITLoaderMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetJITLoaderMutex()); JITLoaderInstances &instances = GetJITLoaderInstances (); JITLoaderInstances::iterator pos, end = instances.end(); @@ -611,7 +611,7 @@ PluginManager::UnregisterPlugin (JITLoaderCreateInstance create_callback) JITLoaderCreateInstance PluginManager::GetJITLoaderCreateCallbackAtIndex (uint32_t idx) { - Mutex::Locker locker (GetJITLoaderMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetJITLoaderMutex()); JITLoaderInstances &instances = GetJITLoaderInstances (); if (idx < instances.size()) return instances[idx].create_callback; @@ -623,7 +623,7 @@ PluginManager::GetJITLoaderCreateCallbackForPluginName (const ConstString &name) { if (name) { - Mutex::Locker locker (GetJITLoaderMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetJITLoaderMutex()); JITLoaderInstances &instances = GetJITLoaderInstances (); JITLoaderInstances::iterator pos, end = instances.end(); @@ -654,10 +654,10 @@ struct EmulateInstructionInstance typedef std::vector<EmulateInstructionInstance> EmulateInstructionInstances; -static Mutex & -GetEmulateInstructionMutex () +static std::recursive_mutex & +GetEmulateInstructionMutex() { - static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive); + static std::recursive_mutex g_instances_mutex; return g_instances_mutex; } @@ -681,7 +681,7 @@ PluginManager::RegisterPlugin(const ConstString &name, if (description && description[0]) instance.description = description; instance.create_callback = create_callback; - Mutex::Locker locker (GetEmulateInstructionMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetEmulateInstructionMutex()); GetEmulateInstructionInstances ().push_back (instance); } return false; @@ -692,7 +692,7 @@ PluginManager::UnregisterPlugin (EmulateInstructionCreateInstance create_callbac { if (create_callback) { - Mutex::Locker locker (GetEmulateInstructionMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetEmulateInstructionMutex()); EmulateInstructionInstances &instances = GetEmulateInstructionInstances (); EmulateInstructionInstances::iterator pos, end = instances.end(); @@ -711,7 +711,7 @@ PluginManager::UnregisterPlugin (EmulateInstructionCreateInstance create_callbac EmulateInstructionCreateInstance PluginManager::GetEmulateInstructionCreateCallbackAtIndex (uint32_t idx) { - Mutex::Locker locker (GetEmulateInstructionMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetEmulateInstructionMutex()); EmulateInstructionInstances &instances = GetEmulateInstructionInstances (); if (idx < instances.size()) return instances[idx].create_callback; @@ -723,7 +723,7 @@ PluginManager::GetEmulateInstructionCreateCallbackForPluginName (const ConstStri { if (name) { - Mutex::Locker locker (GetEmulateInstructionMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetEmulateInstructionMutex()); EmulateInstructionInstances &instances = GetEmulateInstructionInstances (); EmulateInstructionInstances::iterator pos, end = instances.end(); @@ -756,10 +756,10 @@ struct OperatingSystemInstance typedef std::vector<OperatingSystemInstance> OperatingSystemInstances; -static Mutex & -GetOperatingSystemMutex () +static std::recursive_mutex & +GetOperatingSystemMutex() { - static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive); + static std::recursive_mutex g_instances_mutex; return g_instances_mutex; } @@ -784,7 +784,7 @@ PluginManager::RegisterPlugin(const ConstString &name, const char *description, instance.description = description; instance.create_callback = create_callback; instance.debugger_init_callback = debugger_init_callback; - Mutex::Locker locker (GetOperatingSystemMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetOperatingSystemMutex()); GetOperatingSystemInstances ().push_back (instance); } return false; @@ -795,7 +795,7 @@ PluginManager::UnregisterPlugin (OperatingSystemCreateInstance create_callback) { if (create_callback) { - Mutex::Locker locker (GetOperatingSystemMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetOperatingSystemMutex()); OperatingSystemInstances &instances = GetOperatingSystemInstances (); OperatingSystemInstances::iterator pos, end = instances.end(); @@ -814,7 +814,7 @@ PluginManager::UnregisterPlugin (OperatingSystemCreateInstance create_callback) OperatingSystemCreateInstance PluginManager::GetOperatingSystemCreateCallbackAtIndex (uint32_t idx) { - Mutex::Locker locker (GetOperatingSystemMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetOperatingSystemMutex()); OperatingSystemInstances &instances = GetOperatingSystemInstances (); if (idx < instances.size()) return instances[idx].create_callback; @@ -826,7 +826,7 @@ PluginManager::GetOperatingSystemCreateCallbackForPluginName (const ConstString { if (name) { - Mutex::Locker locker (GetOperatingSystemMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetOperatingSystemMutex()); OperatingSystemInstances &instances = GetOperatingSystemInstances (); OperatingSystemInstances::iterator pos, end = instances.end(); @@ -857,10 +857,10 @@ struct LanguageInstance typedef std::vector<LanguageInstance> LanguageInstances; -static Mutex & -GetLanguageMutex () +static std::recursive_mutex & +GetLanguageMutex() { - static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive); + static std::recursive_mutex g_instances_mutex; return g_instances_mutex; } @@ -884,7 +884,7 @@ PluginManager::RegisterPlugin(const ConstString &name, if (description && description[0]) instance.description = description; instance.create_callback = create_callback; - Mutex::Locker locker (GetLanguageMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetLanguageMutex()); GetLanguageInstances ().push_back (instance); } return false; @@ -895,7 +895,7 @@ PluginManager::UnregisterPlugin (LanguageCreateInstance create_callback) { if (create_callback) { - Mutex::Locker locker (GetLanguageMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetLanguageMutex()); LanguageInstances &instances = GetLanguageInstances (); LanguageInstances::iterator pos, end = instances.end(); @@ -914,7 +914,7 @@ PluginManager::UnregisterPlugin (LanguageCreateInstance create_callback) LanguageCreateInstance PluginManager::GetLanguageCreateCallbackAtIndex (uint32_t idx) { - Mutex::Locker locker (GetLanguageMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetLanguageMutex()); LanguageInstances &instances = GetLanguageInstances (); if (idx < instances.size()) return instances[idx].create_callback; @@ -926,7 +926,7 @@ PluginManager::GetLanguageCreateCallbackForPluginName (const ConstString &name) { if (name) { - Mutex::Locker locker (GetLanguageMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetLanguageMutex()); LanguageInstances &instances = GetLanguageInstances (); LanguageInstances::iterator pos, end = instances.end(); @@ -958,10 +958,10 @@ struct LanguageRuntimeInstance typedef std::vector<LanguageRuntimeInstance> LanguageRuntimeInstances; -static Mutex & -GetLanguageRuntimeMutex () +static std::recursive_mutex & +GetLanguageRuntimeMutex() { - static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive); + static std::recursive_mutex g_instances_mutex; return g_instances_mutex; } @@ -987,7 +987,7 @@ PluginManager::RegisterPlugin(const ConstString &name, instance.description = description; instance.create_callback = create_callback; instance.command_callback = command_callback; - Mutex::Locker locker (GetLanguageRuntimeMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetLanguageRuntimeMutex()); GetLanguageRuntimeInstances ().push_back (instance); } return false; @@ -998,7 +998,7 @@ PluginManager::UnregisterPlugin (LanguageRuntimeCreateInstance create_callback) { if (create_callback) { - Mutex::Locker locker (GetLanguageRuntimeMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetLanguageRuntimeMutex()); LanguageRuntimeInstances &instances = GetLanguageRuntimeInstances (); LanguageRuntimeInstances::iterator pos, end = instances.end(); @@ -1017,7 +1017,7 @@ PluginManager::UnregisterPlugin (LanguageRuntimeCreateInstance create_callback) LanguageRuntimeCreateInstance PluginManager::GetLanguageRuntimeCreateCallbackAtIndex (uint32_t idx) { - Mutex::Locker locker (GetLanguageRuntimeMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetLanguageRuntimeMutex()); LanguageRuntimeInstances &instances = GetLanguageRuntimeInstances (); if (idx < instances.size()) return instances[idx].create_callback; @@ -1027,7 +1027,7 @@ PluginManager::GetLanguageRuntimeCreateCallbackAtIndex (uint32_t idx) LanguageRuntimeGetCommandObject PluginManager::GetLanguageRuntimeGetCommandObjectAtIndex (uint32_t idx) { - Mutex::Locker locker (GetLanguageRuntimeMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetLanguageRuntimeMutex()); LanguageRuntimeInstances &instances = GetLanguageRuntimeInstances (); if (idx < instances.size()) return instances[idx].command_callback; @@ -1039,7 +1039,7 @@ PluginManager::GetLanguageRuntimeCreateCallbackForPluginName (const ConstString { if (name) { - Mutex::Locker locker (GetLanguageRuntimeMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetLanguageRuntimeMutex()); LanguageRuntimeInstances &instances = GetLanguageRuntimeInstances (); LanguageRuntimeInstances::iterator pos, end = instances.end(); @@ -1070,10 +1070,10 @@ struct SystemRuntimeInstance typedef std::vector<SystemRuntimeInstance> SystemRuntimeInstances; -static Mutex & -GetSystemRuntimeMutex () +static std::recursive_mutex & +GetSystemRuntimeMutex() { - static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive); + static std::recursive_mutex g_instances_mutex; return g_instances_mutex; } @@ -1097,7 +1097,7 @@ PluginManager::RegisterPlugin(const ConstString &name, if (description && description[0]) instance.description = description; instance.create_callback = create_callback; - Mutex::Locker locker (GetSystemRuntimeMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetSystemRuntimeMutex()); GetSystemRuntimeInstances ().push_back (instance); } return false; @@ -1108,7 +1108,7 @@ PluginManager::UnregisterPlugin (SystemRuntimeCreateInstance create_callback) { if (create_callback) { - Mutex::Locker locker (GetSystemRuntimeMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetSystemRuntimeMutex()); SystemRuntimeInstances &instances = GetSystemRuntimeInstances (); SystemRuntimeInstances::iterator pos, end = instances.end(); @@ -1127,7 +1127,7 @@ PluginManager::UnregisterPlugin (SystemRuntimeCreateInstance create_callback) SystemRuntimeCreateInstance PluginManager::GetSystemRuntimeCreateCallbackAtIndex (uint32_t idx) { - Mutex::Locker locker (GetSystemRuntimeMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetSystemRuntimeMutex()); SystemRuntimeInstances &instances = GetSystemRuntimeInstances (); if (idx < instances.size()) return instances[idx].create_callback; @@ -1139,7 +1139,7 @@ PluginManager::GetSystemRuntimeCreateCallbackForPluginName (const ConstString &n { if (name) { - Mutex::Locker locker (GetSystemRuntimeMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetSystemRuntimeMutex()); SystemRuntimeInstances &instances = GetSystemRuntimeInstances (); SystemRuntimeInstances::iterator pos, end = instances.end(); @@ -1176,10 +1176,10 @@ struct ObjectFileInstance typedef std::vector<ObjectFileInstance> ObjectFileInstances; -static Mutex & -GetObjectFileMutex () +static std::recursive_mutex & +GetObjectFileMutex() { - static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive); + static std::recursive_mutex g_instances_mutex; return g_instances_mutex; } @@ -1209,7 +1209,7 @@ PluginManager::RegisterPlugin (const ConstString &name, instance.create_memory_callback = create_memory_callback; instance.save_core = save_core; instance.get_module_specifications = get_module_specifications; - Mutex::Locker locker (GetObjectFileMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetObjectFileMutex()); GetObjectFileInstances ().push_back (instance); } return false; @@ -1220,7 +1220,7 @@ PluginManager::UnregisterPlugin (ObjectFileCreateInstance create_callback) { if (create_callback) { - Mutex::Locker locker (GetObjectFileMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetObjectFileMutex()); ObjectFileInstances &instances = GetObjectFileInstances (); ObjectFileInstances::iterator pos, end = instances.end(); @@ -1239,7 +1239,7 @@ PluginManager::UnregisterPlugin (ObjectFileCreateInstance create_callback) ObjectFileCreateInstance PluginManager::GetObjectFileCreateCallbackAtIndex (uint32_t idx) { - Mutex::Locker locker (GetObjectFileMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetObjectFileMutex()); ObjectFileInstances &instances = GetObjectFileInstances (); if (idx < instances.size()) return instances[idx].create_callback; @@ -1249,7 +1249,7 @@ PluginManager::GetObjectFileCreateCallbackAtIndex (uint32_t idx) ObjectFileCreateMemoryInstance PluginManager::GetObjectFileCreateMemoryCallbackAtIndex (uint32_t idx) { - Mutex::Locker locker (GetObjectFileMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetObjectFileMutex()); ObjectFileInstances &instances = GetObjectFileInstances (); if (idx < instances.size()) return instances[idx].create_memory_callback; @@ -1259,7 +1259,7 @@ PluginManager::GetObjectFileCreateMemoryCallbackAtIndex (uint32_t idx) ObjectFileGetModuleSpecifications PluginManager::GetObjectFileGetModuleSpecificationsCallbackAtIndex (uint32_t idx) { - Mutex::Locker locker (GetObjectFileMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetObjectFileMutex()); ObjectFileInstances &instances = GetObjectFileInstances (); if (idx < instances.size()) return instances[idx].get_module_specifications; @@ -1271,7 +1271,7 @@ PluginManager::GetObjectFileCreateCallbackForPluginName (const ConstString &name { if (name) { - Mutex::Locker locker (GetObjectFileMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetObjectFileMutex()); ObjectFileInstances &instances = GetObjectFileInstances (); ObjectFileInstances::iterator pos, end = instances.end(); @@ -1289,7 +1289,7 @@ PluginManager::GetObjectFileCreateMemoryCallbackForPluginName (const ConstString { if (name) { - Mutex::Locker locker (GetObjectFileMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetObjectFileMutex()); ObjectFileInstances &instances = GetObjectFileInstances (); ObjectFileInstances::iterator pos, end = instances.end(); @@ -1306,7 +1306,7 @@ Error PluginManager::SaveCore (const lldb::ProcessSP &process_sp, const FileSpec &outfile) { Error error; - Mutex::Locker locker (GetObjectFileMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetObjectFileMutex()); ObjectFileInstances &instances = GetObjectFileInstances (); ObjectFileInstances::iterator pos, end = instances.end(); @@ -1339,10 +1339,10 @@ struct ObjectContainerInstance typedef std::vector<ObjectContainerInstance> ObjectContainerInstances; -static Mutex & -GetObjectContainerMutex () +static std::recursive_mutex & +GetObjectContainerMutex() { - static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive); + static std::recursive_mutex g_instances_mutex; return g_instances_mutex; } @@ -1368,7 +1368,7 @@ PluginManager::RegisterPlugin (const ConstString &name, instance.description = description; instance.create_callback = create_callback; instance.get_module_specifications = get_module_specifications; - Mutex::Locker locker (GetObjectContainerMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetObjectContainerMutex()); GetObjectContainerInstances ().push_back (instance); } return false; @@ -1379,7 +1379,7 @@ PluginManager::UnregisterPlugin (ObjectContainerCreateInstance create_callback) { if (create_callback) { - Mutex::Locker locker (GetObjectContainerMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetObjectContainerMutex()); ObjectContainerInstances &instances = GetObjectContainerInstances (); ObjectContainerInstances::iterator pos, end = instances.end(); @@ -1398,7 +1398,7 @@ PluginManager::UnregisterPlugin (ObjectContainerCreateInstance create_callback) ObjectContainerCreateInstance PluginManager::GetObjectContainerCreateCallbackAtIndex (uint32_t idx) { - Mutex::Locker locker (GetObjectContainerMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetObjectContainerMutex()); ObjectContainerInstances &instances = GetObjectContainerInstances (); if (idx < instances.size()) return instances[idx].create_callback; @@ -1410,7 +1410,7 @@ PluginManager::GetObjectContainerCreateCallbackForPluginName (const ConstString { if (name) { - Mutex::Locker locker (GetObjectContainerMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetObjectContainerMutex()); ObjectContainerInstances &instances = GetObjectContainerInstances (); ObjectContainerInstances::iterator pos, end = instances.end(); @@ -1426,7 +1426,7 @@ PluginManager::GetObjectContainerCreateCallbackForPluginName (const ConstString ObjectFileGetModuleSpecifications PluginManager::GetObjectContainerGetModuleSpecificationsCallbackAtIndex (uint32_t idx) { - Mutex::Locker locker (GetObjectContainerMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetObjectContainerMutex()); ObjectContainerInstances &instances = GetObjectContainerInstances (); if (idx < instances.size()) return instances[idx].get_module_specifications; @@ -1451,10 +1451,10 @@ struct LogInstance typedef std::vector<LogInstance> LogInstances; -static Mutex & -GetLogMutex () +static std::recursive_mutex & +GetLogMutex() { - static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive); + static std::recursive_mutex g_instances_mutex; return g_instances_mutex; } @@ -1478,7 +1478,7 @@ PluginManager::RegisterPlugin(const ConstString &name, if (description && description[0]) instance.description = description; instance.create_callback = create_callback; - Mutex::Locker locker (GetLogMutex ()); + std::lock_guard<std::recursive_mutex> gard(GetLogMutex()); GetLogInstances ().push_back (instance); } return false; @@ -1489,7 +1489,7 @@ PluginManager::UnregisterPlugin (LogChannelCreateInstance create_callback) { if (create_callback) { - Mutex::Locker locker (GetLogMutex ()); + std::lock_guard<std::recursive_mutex> gard(GetLogMutex()); LogInstances &instances = GetLogInstances (); LogInstances::iterator pos, end = instances.end(); @@ -1508,7 +1508,7 @@ PluginManager::UnregisterPlugin (LogChannelCreateInstance create_callback) const char * PluginManager::GetLogChannelCreateNameAtIndex (uint32_t idx) { - Mutex::Locker locker (GetLogMutex ()); + std::lock_guard<std::recursive_mutex> gard(GetLogMutex()); LogInstances &instances = GetLogInstances (); if (idx < instances.size()) return instances[idx].name.GetCString(); @@ -1518,7 +1518,7 @@ PluginManager::GetLogChannelCreateNameAtIndex (uint32_t idx) LogChannelCreateInstance PluginManager::GetLogChannelCreateCallbackAtIndex (uint32_t idx) { - Mutex::Locker locker (GetLogMutex ()); + std::lock_guard<std::recursive_mutex> gard(GetLogMutex()); LogInstances &instances = GetLogInstances (); if (idx < instances.size()) return instances[idx].create_callback; @@ -1530,7 +1530,7 @@ PluginManager::GetLogChannelCreateCallbackForPluginName (const ConstString &name { if (name) { - Mutex::Locker locker (GetLogMutex ()); + std::lock_guard<std::recursive_mutex> gard(GetLogMutex()); LogInstances &instances = GetLogInstances (); LogInstances::iterator pos, end = instances.end(); @@ -1563,10 +1563,10 @@ struct PlatformInstance typedef std::vector<PlatformInstance> PlatformInstances; -static Mutex & -GetPlatformInstancesMutex () +static std::recursive_mutex & +GetPlatformInstancesMutex() { - static Mutex g_platform_instances_mutex (Mutex::eMutexTypeRecursive); + static std::recursive_mutex g_platform_instances_mutex; return g_platform_instances_mutex; } @@ -1585,8 +1585,8 @@ PluginManager::RegisterPlugin (const ConstString &name, { if (create_callback) { - Mutex::Locker locker (GetPlatformInstancesMutex ()); - + std::lock_guard<std::recursive_mutex> guard(GetPlatformInstancesMutex()); + PlatformInstance instance; assert ((bool)name); instance.name = name; @@ -1603,7 +1603,7 @@ PluginManager::RegisterPlugin (const ConstString &name, const char * PluginManager::GetPlatformPluginNameAtIndex (uint32_t idx) { - Mutex::Locker locker (GetPlatformInstancesMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetPlatformInstancesMutex()); PlatformInstances &instances = GetPlatformInstances (); if (idx < instances.size()) return instances[idx].name.GetCString(); @@ -1613,7 +1613,7 @@ PluginManager::GetPlatformPluginNameAtIndex (uint32_t idx) const char * PluginManager::GetPlatformPluginDescriptionAtIndex (uint32_t idx) { - Mutex::Locker locker (GetPlatformInstancesMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetPlatformInstancesMutex()); PlatformInstances &instances = GetPlatformInstances (); if (idx < instances.size()) return instances[idx].description.c_str(); @@ -1625,7 +1625,7 @@ PluginManager::UnregisterPlugin (PlatformCreateInstance create_callback) { if (create_callback) { - Mutex::Locker locker (GetPlatformInstancesMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetPlatformInstancesMutex()); PlatformInstances &instances = GetPlatformInstances (); PlatformInstances::iterator pos, end = instances.end(); @@ -1644,7 +1644,7 @@ PluginManager::UnregisterPlugin (PlatformCreateInstance create_callback) PlatformCreateInstance PluginManager::GetPlatformCreateCallbackAtIndex (uint32_t idx) { - Mutex::Locker locker (GetPlatformInstancesMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetPlatformInstancesMutex()); PlatformInstances &instances = GetPlatformInstances (); if (idx < instances.size()) return instances[idx].create_callback; @@ -1656,7 +1656,7 @@ PluginManager::GetPlatformCreateCallbackForPluginName (const ConstString &name) { if (name) { - Mutex::Locker locker (GetPlatformInstancesMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetPlatformInstancesMutex()); PlatformInstances &instances = GetPlatformInstances (); PlatformInstances::iterator pos, end = instances.end(); @@ -1674,7 +1674,7 @@ PluginManager::AutoCompletePlatformName (const char *name, StringList &matches) { if (name) { - Mutex::Locker locker (GetPlatformInstancesMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetPlatformInstancesMutex()); PlatformInstances &instances = GetPlatformInstances (); llvm::StringRef name_sref(name); @@ -1709,10 +1709,10 @@ struct ProcessInstance typedef std::vector<ProcessInstance> ProcessInstances; -static Mutex & -GetProcessMutex () +static std::recursive_mutex & +GetProcessMutex() { - static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive); + static std::recursive_mutex g_instances_mutex; return g_instances_mutex; } @@ -1738,7 +1738,7 @@ PluginManager::RegisterPlugin (const ConstString &name, instance.description = description; instance.create_callback = create_callback; instance.debugger_init_callback = debugger_init_callback; - Mutex::Locker locker (GetProcessMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetProcessMutex()); GetProcessInstances ().push_back (instance); } return false; @@ -1747,7 +1747,7 @@ PluginManager::RegisterPlugin (const ConstString &name, const char * PluginManager::GetProcessPluginNameAtIndex (uint32_t idx) { - Mutex::Locker locker (GetProcessMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetProcessMutex()); ProcessInstances &instances = GetProcessInstances (); if (idx < instances.size()) return instances[idx].name.GetCString(); @@ -1757,7 +1757,7 @@ PluginManager::GetProcessPluginNameAtIndex (uint32_t idx) const char * PluginManager::GetProcessPluginDescriptionAtIndex (uint32_t idx) { - Mutex::Locker locker (GetProcessMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetProcessMutex()); ProcessInstances &instances = GetProcessInstances (); if (idx < instances.size()) return instances[idx].description.c_str(); @@ -1769,7 +1769,7 @@ PluginManager::UnregisterPlugin (ProcessCreateInstance create_callback) { if (create_callback) { - Mutex::Locker locker (GetProcessMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetProcessMutex()); ProcessInstances &instances = GetProcessInstances (); ProcessInstances::iterator pos, end = instances.end(); @@ -1788,7 +1788,7 @@ PluginManager::UnregisterPlugin (ProcessCreateInstance create_callback) ProcessCreateInstance PluginManager::GetProcessCreateCallbackAtIndex (uint32_t idx) { - Mutex::Locker locker (GetProcessMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetProcessMutex()); ProcessInstances &instances = GetProcessInstances (); if (idx < instances.size()) return instances[idx].create_callback; @@ -1800,7 +1800,7 @@ PluginManager::GetProcessCreateCallbackForPluginName (const ConstString &name) { if (name) { - Mutex::Locker locker (GetProcessMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetProcessMutex()); ProcessInstances &instances = GetProcessInstances (); ProcessInstances::iterator pos, end = instances.end(); @@ -1833,10 +1833,10 @@ struct ScriptInterpreterInstance typedef std::vector<ScriptInterpreterInstance> ScriptInterpreterInstances; -static Mutex & +static std::recursive_mutex & GetScriptInterpreterMutex() { - static Mutex g_instances_mutex(Mutex::eMutexTypeRecursive); + static std::recursive_mutex g_instances_mutex; return g_instances_mutex; } @@ -1860,7 +1860,7 @@ PluginManager::RegisterPlugin(const ConstString &name, const char *description, instance.description = description; instance.create_callback = create_callback; instance.language = script_language; - Mutex::Locker locker(GetScriptInterpreterMutex()); + std::lock_guard<std::recursive_mutex> guard(GetScriptInterpreterMutex()); GetScriptInterpreterInstances().push_back(instance); return false; } @@ -1870,7 +1870,7 @@ PluginManager::UnregisterPlugin(ScriptInterpreterCreateInstance create_callback) { if (!create_callback) return false; - Mutex::Locker locker(GetScriptInterpreterMutex()); + std::lock_guard<std::recursive_mutex> guard(GetScriptInterpreterMutex()); ScriptInterpreterInstances &instances = GetScriptInterpreterInstances(); ScriptInterpreterInstances::iterator pos, end = instances.end(); @@ -1888,7 +1888,7 @@ PluginManager::UnregisterPlugin(ScriptInterpreterCreateInstance create_callback) ScriptInterpreterCreateInstance PluginManager::GetScriptInterpreterCreateCallbackAtIndex(uint32_t idx) { - Mutex::Locker locker(GetScriptInterpreterMutex()); + std::lock_guard<std::recursive_mutex> guard(GetScriptInterpreterMutex()); ScriptInterpreterInstances &instances = GetScriptInterpreterInstances(); if (idx < instances.size()) return instances[idx].create_callback; @@ -1898,7 +1898,7 @@ PluginManager::GetScriptInterpreterCreateCallbackAtIndex(uint32_t idx) lldb::ScriptInterpreterSP PluginManager::GetScriptInterpreterForLanguage(lldb::ScriptLanguage script_lang, CommandInterpreter &interpreter) { - Mutex::Locker locker(GetScriptInterpreterMutex()); + std::lock_guard<std::recursive_mutex> guard(GetScriptInterpreterMutex()); ScriptInterpreterInstances &instances = GetScriptInterpreterInstances(); ScriptInterpreterInstances::iterator pos, end = instances.end(); @@ -1937,10 +1937,10 @@ struct SymbolFileInstance typedef std::vector<SymbolFileInstance> SymbolFileInstances; -static Mutex & -GetSymbolFileMutex () +static std::recursive_mutex & +GetSymbolFileMutex() { - static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive); + static std::recursive_mutex g_instances_mutex; return g_instances_mutex; } @@ -1966,7 +1966,7 @@ PluginManager::RegisterPlugin(const ConstString &name, instance.description = description; instance.create_callback = create_callback; instance.debugger_init_callback = debugger_init_callback; - Mutex::Locker locker (GetSymbolFileMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetSymbolFileMutex()); GetSymbolFileInstances ().push_back (instance); } return false; @@ -1977,7 +1977,7 @@ PluginManager::UnregisterPlugin (SymbolFileCreateInstance create_callback) { if (create_callback) { - Mutex::Locker locker (GetSymbolFileMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetSymbolFileMutex()); SymbolFileInstances &instances = GetSymbolFileInstances (); SymbolFileInstances::iterator pos, end = instances.end(); @@ -1996,7 +1996,7 @@ PluginManager::UnregisterPlugin (SymbolFileCreateInstance create_callback) SymbolFileCreateInstance PluginManager::GetSymbolFileCreateCallbackAtIndex (uint32_t idx) { - Mutex::Locker locker (GetSymbolFileMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetSymbolFileMutex()); SymbolFileInstances &instances = GetSymbolFileInstances (); if (idx < instances.size()) return instances[idx].create_callback; @@ -2008,7 +2008,7 @@ PluginManager::GetSymbolFileCreateCallbackForPluginName (const ConstString &name { if (name) { - Mutex::Locker locker (GetSymbolFileMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetSymbolFileMutex()); SymbolFileInstances &instances = GetSymbolFileInstances (); SymbolFileInstances::iterator pos, end = instances.end(); @@ -2039,10 +2039,10 @@ struct SymbolVendorInstance typedef std::vector<SymbolVendorInstance> SymbolVendorInstances; -static Mutex & -GetSymbolVendorMutex () +static std::recursive_mutex & +GetSymbolVendorMutex() { - static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive); + static std::recursive_mutex g_instances_mutex; return g_instances_mutex; } @@ -2066,7 +2066,7 @@ PluginManager::RegisterPlugin(const ConstString &name, if (description && description[0]) instance.description = description; instance.create_callback = create_callback; - Mutex::Locker locker (GetSymbolVendorMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetSymbolVendorMutex()); GetSymbolVendorInstances ().push_back (instance); } return false; @@ -2077,7 +2077,7 @@ PluginManager::UnregisterPlugin (SymbolVendorCreateInstance create_callback) { if (create_callback) { - Mutex::Locker locker (GetSymbolVendorMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetSymbolVendorMutex()); SymbolVendorInstances &instances = GetSymbolVendorInstances (); SymbolVendorInstances::iterator pos, end = instances.end(); @@ -2096,7 +2096,7 @@ PluginManager::UnregisterPlugin (SymbolVendorCreateInstance create_callback) SymbolVendorCreateInstance PluginManager::GetSymbolVendorCreateCallbackAtIndex (uint32_t idx) { - Mutex::Locker locker (GetSymbolVendorMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetSymbolVendorMutex()); SymbolVendorInstances &instances = GetSymbolVendorInstances (); if (idx < instances.size()) return instances[idx].create_callback; @@ -2108,7 +2108,7 @@ PluginManager::GetSymbolVendorCreateCallbackForPluginName (const ConstString &na { if (name) { - Mutex::Locker locker (GetSymbolVendorMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetSymbolVendorMutex()); SymbolVendorInstances &instances = GetSymbolVendorInstances (); SymbolVendorInstances::iterator pos, end = instances.end(); @@ -2139,10 +2139,10 @@ struct UnwindAssemblyInstance typedef std::vector<UnwindAssemblyInstance> UnwindAssemblyInstances; -static Mutex & -GetUnwindAssemblyMutex () +static std::recursive_mutex & +GetUnwindAssemblyMutex() { - static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive); + static std::recursive_mutex g_instances_mutex; return g_instances_mutex; } @@ -2166,7 +2166,7 @@ PluginManager::RegisterPlugin(const ConstString &name, if (description && description[0]) instance.description = description; instance.create_callback = create_callback; - Mutex::Locker locker (GetUnwindAssemblyMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetUnwindAssemblyMutex()); GetUnwindAssemblyInstances ().push_back (instance); } return false; @@ -2177,7 +2177,7 @@ PluginManager::UnregisterPlugin (UnwindAssemblyCreateInstance create_callback) { if (create_callback) { - Mutex::Locker locker (GetUnwindAssemblyMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetUnwindAssemblyMutex()); UnwindAssemblyInstances &instances = GetUnwindAssemblyInstances (); UnwindAssemblyInstances::iterator pos, end = instances.end(); @@ -2196,7 +2196,7 @@ PluginManager::UnregisterPlugin (UnwindAssemblyCreateInstance create_callback) UnwindAssemblyCreateInstance PluginManager::GetUnwindAssemblyCreateCallbackAtIndex (uint32_t idx) { - Mutex::Locker locker (GetUnwindAssemblyMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetUnwindAssemblyMutex()); UnwindAssemblyInstances &instances = GetUnwindAssemblyInstances (); if (idx < instances.size()) return instances[idx].create_callback; @@ -2208,7 +2208,7 @@ PluginManager::GetUnwindAssemblyCreateCallbackForPluginName (const ConstString & { if (name) { - Mutex::Locker locker (GetUnwindAssemblyMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetUnwindAssemblyMutex()); UnwindAssemblyInstances &instances = GetUnwindAssemblyInstances (); UnwindAssemblyInstances::iterator pos, end = instances.end(); @@ -2239,10 +2239,10 @@ struct MemoryHistoryInstance typedef std::vector<MemoryHistoryInstance> MemoryHistoryInstances; -static Mutex & -GetMemoryHistoryMutex () +static std::recursive_mutex & +GetMemoryHistoryMutex() { - static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive); + static std::recursive_mutex g_instances_mutex; return g_instances_mutex; } @@ -2266,7 +2266,7 @@ PluginManager::RegisterPlugin(const ConstString &name, if (description && description[0]) instance.description = description; instance.create_callback = create_callback; - Mutex::Locker locker (GetMemoryHistoryMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetMemoryHistoryMutex()); GetMemoryHistoryInstances ().push_back (instance); } return false; @@ -2277,7 +2277,7 @@ PluginManager::UnregisterPlugin (MemoryHistoryCreateInstance create_callback) { if (create_callback) { - Mutex::Locker locker (GetMemoryHistoryMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetMemoryHistoryMutex()); MemoryHistoryInstances &instances = GetMemoryHistoryInstances (); MemoryHistoryInstances::iterator pos, end = instances.end(); @@ -2296,7 +2296,7 @@ PluginManager::UnregisterPlugin (MemoryHistoryCreateInstance create_callback) MemoryHistoryCreateInstance PluginManager::GetMemoryHistoryCreateCallbackAtIndex (uint32_t idx) { - Mutex::Locker locker (GetMemoryHistoryMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetMemoryHistoryMutex()); MemoryHistoryInstances &instances = GetMemoryHistoryInstances (); if (idx < instances.size()) return instances[idx].create_callback; @@ -2308,7 +2308,7 @@ PluginManager::GetMemoryHistoryCreateCallbackForPluginName (const ConstString &n { if (name) { - Mutex::Locker locker (GetMemoryHistoryMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetMemoryHistoryMutex()); MemoryHistoryInstances &instances = GetMemoryHistoryInstances (); MemoryHistoryInstances::iterator pos, end = instances.end(); @@ -2340,10 +2340,10 @@ struct InstrumentationRuntimeInstance typedef std::vector<InstrumentationRuntimeInstance> InstrumentationRuntimeInstances; -static Mutex & -GetInstrumentationRuntimeMutex () +static std::recursive_mutex & +GetInstrumentationRuntimeMutex() { - static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive); + static std::recursive_mutex g_instances_mutex; return g_instances_mutex; } @@ -2369,7 +2369,7 @@ PluginManager::RegisterPlugin(const ConstString &name, instance.description = description; instance.create_callback = create_callback; instance.get_type_callback = get_type_callback; - Mutex::Locker locker (GetInstrumentationRuntimeMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetInstrumentationRuntimeMutex()); GetInstrumentationRuntimeInstances ().push_back (instance); } return false; @@ -2380,7 +2380,7 @@ PluginManager::UnregisterPlugin (InstrumentationRuntimeCreateInstance create_cal { if (create_callback) { - Mutex::Locker locker (GetInstrumentationRuntimeMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetInstrumentationRuntimeMutex()); InstrumentationRuntimeInstances &instances = GetInstrumentationRuntimeInstances (); InstrumentationRuntimeInstances::iterator pos, end = instances.end(); @@ -2399,7 +2399,7 @@ PluginManager::UnregisterPlugin (InstrumentationRuntimeCreateInstance create_cal InstrumentationRuntimeGetType PluginManager::GetInstrumentationRuntimeGetTypeCallbackAtIndex (uint32_t idx) { - Mutex::Locker locker (GetInstrumentationRuntimeMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetInstrumentationRuntimeMutex()); InstrumentationRuntimeInstances &instances = GetInstrumentationRuntimeInstances (); if (idx < instances.size()) return instances[idx].get_type_callback; @@ -2409,7 +2409,7 @@ PluginManager::GetInstrumentationRuntimeGetTypeCallbackAtIndex (uint32_t idx) InstrumentationRuntimeCreateInstance PluginManager::GetInstrumentationRuntimeCreateCallbackAtIndex (uint32_t idx) { - Mutex::Locker locker (GetInstrumentationRuntimeMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetInstrumentationRuntimeMutex()); InstrumentationRuntimeInstances &instances = GetInstrumentationRuntimeInstances (); if (idx < instances.size()) return instances[idx].create_callback; @@ -2421,7 +2421,7 @@ PluginManager::GetInstrumentationRuntimeCreateCallbackForPluginName (const Const { if (name) { - Mutex::Locker locker (GetInstrumentationRuntimeMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetInstrumentationRuntimeMutex()); InstrumentationRuntimeInstances &instances = GetInstrumentationRuntimeInstances (); InstrumentationRuntimeInstances::iterator pos, end = instances.end(); @@ -2453,10 +2453,10 @@ struct TypeSystemInstance typedef std::vector<TypeSystemInstance> TypeSystemInstances; -static Mutex & -GetTypeSystemMutex () +static std::recursive_mutex & +GetTypeSystemMutex() { - static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive); + static std::recursive_mutex g_instances_mutex; return g_instances_mutex; } @@ -2482,7 +2482,7 @@ PluginManager::RegisterPlugin (const ConstString &name, instance.description = description; instance.create_callback = create_callback; instance.enumerate_callback = enumerate_supported_languages_callback; - Mutex::Locker locker (GetTypeSystemMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetTypeSystemMutex()); GetTypeSystemInstances ().push_back (instance); } return false; @@ -2493,7 +2493,7 @@ PluginManager::UnregisterPlugin (TypeSystemCreateInstance create_callback) { if (create_callback) { - Mutex::Locker locker (GetTypeSystemMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetTypeSystemMutex()); TypeSystemInstances &instances = GetTypeSystemInstances (); TypeSystemInstances::iterator pos, end = instances.end(); @@ -2512,7 +2512,7 @@ PluginManager::UnregisterPlugin (TypeSystemCreateInstance create_callback) TypeSystemCreateInstance PluginManager::GetTypeSystemCreateCallbackAtIndex (uint32_t idx) { - Mutex::Locker locker (GetTypeSystemMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetTypeSystemMutex()); TypeSystemInstances &instances = GetTypeSystemInstances (); if (idx < instances.size()) return instances[idx].create_callback; @@ -2524,7 +2524,7 @@ PluginManager::GetTypeSystemCreateCallbackForPluginName (const ConstString &name { if (name) { - Mutex::Locker locker (GetTypeSystemMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetTypeSystemMutex()); TypeSystemInstances &instances = GetTypeSystemInstances (); TypeSystemInstances::iterator pos, end = instances.end(); @@ -2540,7 +2540,7 @@ PluginManager::GetTypeSystemCreateCallbackForPluginName (const ConstString &name TypeSystemEnumerateSupportedLanguages PluginManager::GetTypeSystemEnumerateSupportedLanguagesCallbackAtIndex (uint32_t idx) { - Mutex::Locker locker (GetTypeSystemMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetTypeSystemMutex()); TypeSystemInstances &instances = GetTypeSystemInstances (); if (idx < instances.size()) return instances[idx].enumerate_callback; @@ -2552,7 +2552,7 @@ PluginManager::GetTypeSystemEnumerateSupportedLanguagesCallbackForPluginName (co { if (name) { - Mutex::Locker locker (GetTypeSystemMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetTypeSystemMutex()); TypeSystemInstances &instances = GetTypeSystemInstances (); TypeSystemInstances::iterator pos, end = instances.end(); @@ -2584,10 +2584,10 @@ struct REPLInstance typedef std::vector<REPLInstance> REPLInstances; -static Mutex & -GetREPLMutex () +static std::recursive_mutex & +GetREPLMutex() { - static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive); + static std::recursive_mutex g_instances_mutex; return g_instances_mutex; } @@ -2613,7 +2613,7 @@ PluginManager::RegisterPlugin (const ConstString &name, instance.description = description; instance.create_callback = create_callback; instance.enumerate_languages_callback = enumerate_languages_callback; - Mutex::Locker locker (GetREPLMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetREPLMutex()); GetREPLInstances ().push_back (instance); } return false; @@ -2624,7 +2624,7 @@ PluginManager::UnregisterPlugin (REPLCreateInstance create_callback) { if (create_callback) { - Mutex::Locker locker (GetREPLMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetREPLMutex()); REPLInstances &instances = GetREPLInstances (); REPLInstances::iterator pos, end = instances.end(); @@ -2643,7 +2643,7 @@ PluginManager::UnregisterPlugin (REPLCreateInstance create_callback) REPLCreateInstance PluginManager::GetREPLCreateCallbackAtIndex (uint32_t idx) { - Mutex::Locker locker (GetREPLMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetREPLMutex()); REPLInstances &instances = GetREPLInstances (); if (idx < instances.size()) return instances[idx].create_callback; @@ -2655,7 +2655,7 @@ PluginManager::GetREPLCreateCallbackForPluginName (const ConstString &name) { if (name) { - Mutex::Locker locker (GetREPLMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetREPLMutex()); REPLInstances &instances = GetREPLInstances (); REPLInstances::iterator pos, end = instances.end(); @@ -2671,7 +2671,7 @@ PluginManager::GetREPLCreateCallbackForPluginName (const ConstString &name) REPLEnumerateSupportedLanguages PluginManager::GetREPLEnumerateSupportedLanguagesCallbackAtIndex (uint32_t idx) { - Mutex::Locker locker (GetREPLMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetREPLMutex()); REPLInstances &instances = GetREPLInstances (); if (idx < instances.size()) return instances[idx].enumerate_languages_callback; @@ -2683,7 +2683,7 @@ PluginManager::GetREPLSystemEnumerateSupportedLanguagesCallbackForPluginName (co { if (name) { - Mutex::Locker locker (GetREPLMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetREPLMutex()); REPLInstances &instances = GetREPLInstances (); REPLInstances::iterator pos, end = instances.end(); @@ -2703,7 +2703,7 @@ PluginManager::DebuggerInitialize (Debugger &debugger) { // Initialize the DynamicLoader plugins { - Mutex::Locker locker (GetDynamicLoaderMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetDynamicLoaderMutex()); DynamicLoaderInstances &instances = GetDynamicLoaderInstances (); DynamicLoaderInstances::iterator pos, end = instances.end(); @@ -2716,7 +2716,7 @@ PluginManager::DebuggerInitialize (Debugger &debugger) // Initialize the JITLoader plugins { - Mutex::Locker locker (GetJITLoaderMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetJITLoaderMutex()); JITLoaderInstances &instances = GetJITLoaderInstances (); JITLoaderInstances::iterator pos, end = instances.end(); @@ -2729,7 +2729,7 @@ PluginManager::DebuggerInitialize (Debugger &debugger) // Initialize the Platform plugins { - Mutex::Locker locker (GetPlatformInstancesMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetPlatformInstancesMutex()); PlatformInstances &instances = GetPlatformInstances (); PlatformInstances::iterator pos, end = instances.end(); @@ -2742,7 +2742,7 @@ PluginManager::DebuggerInitialize (Debugger &debugger) // Initialize the Process plugins { - Mutex::Locker locker (GetProcessMutex()); + std::lock_guard<std::recursive_mutex> guard(GetProcessMutex()); ProcessInstances &instances = GetProcessInstances(); ProcessInstances::iterator pos, end = instances.end(); @@ -2755,7 +2755,7 @@ PluginManager::DebuggerInitialize (Debugger &debugger) // Initialize the SymbolFile plugins { - Mutex::Locker locker (GetSymbolFileMutex()); + std::lock_guard<std::recursive_mutex> guard(GetSymbolFileMutex()); for (auto& sym_file: GetSymbolFileInstances()) { if (sym_file.debugger_init_callback) @@ -2765,7 +2765,7 @@ PluginManager::DebuggerInitialize (Debugger &debugger) // Initialize the OperatingSystem plugins { - Mutex::Locker locker(GetOperatingSystemMutex()); + std::lock_guard<std::recursive_mutex> guard(GetOperatingSystemMutex()); for (auto &os : GetOperatingSystemInstances()) { if (os.debugger_init_callback) diff --git a/lldb/source/Core/StreamCallback.cpp b/lldb/source/Core/StreamCallback.cpp index d144b16755e..9f0adee2a15 100644 --- a/lldb/source/Core/StreamCallback.cpp +++ b/lldb/source/Core/StreamCallback.cpp @@ -18,13 +18,8 @@ using namespace lldb; using namespace lldb_private; - -StreamCallback::StreamCallback (lldb::LogOutputCallback callback, void *baton) : - Stream (0, 4, eByteOrderBig), - m_callback (callback), - m_baton (baton), - m_accumulated_data (), - m_collection_mutex () +StreamCallback::StreamCallback(lldb::LogOutputCallback callback, void *baton) + : Stream(0, 4, eByteOrderBig), m_callback(callback), m_baton(baton), m_accumulated_data(), m_collection_mutex() { } @@ -35,7 +30,7 @@ StreamCallback::~StreamCallback () StreamString & StreamCallback::FindStreamForThread(lldb::tid_t cur_tid) { - Mutex::Locker locker(m_collection_mutex); + std::lock_guard<std::mutex> guard(m_collection_mutex); collection::iterator iter = m_accumulated_data.find (cur_tid); if (iter == m_accumulated_data.end()) { diff --git a/lldb/source/Core/Timer.cpp b/lldb/source/Core/Timer.cpp index 73175988753..f4cd33fc3cb 100644 --- a/lldb/source/Core/Timer.cpp +++ b/lldb/source/Core/Timer.cpp @@ -8,12 +8,12 @@ //===----------------------------------------------------------------------===// #include "lldb/Core/Timer.h" +#include <algorithm> #include <map> +#include <mutex> #include <vector> -#include <algorithm> #include "lldb/Core/Stream.h" -#include "lldb/Host/Mutex.h" #include "lldb/Host/Host.h" #include <stdio.h> @@ -52,11 +52,10 @@ GetFileMutex() return *g_file_mutex_ptr; } - -static Mutex & +static std::mutex & GetCategoryMutex() { - static Mutex g_category_mutex(Mutex::eMutexTypeNormal); + static std::mutex g_category_mutex; return g_category_mutex; } @@ -169,7 +168,7 @@ Timer::~Timer() } // Keep total results for each category so we can dump results. - Mutex::Locker locker (GetCategoryMutex()); + std::lock_guard<std::mutex> guard(GetCategoryMutex()); TimerCategoryMap &category_map = GetCategoryMap(); category_map[m_category] += timer_nsec_uint; } @@ -240,7 +239,7 @@ CategoryMapIteratorSortCriterion (const TimerCategoryMap::const_iterator& lhs, c void Timer::ResetCategoryTimes () { - Mutex::Locker locker (GetCategoryMutex()); + std::lock_guard<std::mutex> guard(GetCategoryMutex()); TimerCategoryMap &category_map = GetCategoryMap(); category_map.clear(); } @@ -248,7 +247,7 @@ Timer::ResetCategoryTimes () void Timer::DumpCategoryTimes (Stream *s) { - Mutex::Locker locker (GetCategoryMutex()); + std::lock_guard<std::mutex> guard(GetCategoryMutex()); TimerCategoryMap &category_map = GetCategoryMap(); std::vector<TimerCategoryMap::const_iterator> sorted_iterators; TimerCategoryMap::const_iterator pos, end = category_map.end(); diff --git a/lldb/source/DataFormatters/FormatCache.cpp b/lldb/source/DataFormatters/FormatCache.cpp index fa749405b60..fc5becbf200 100644 --- a/lldb/source/DataFormatters/FormatCache.cpp +++ b/lldb/source/DataFormatters/FormatCache.cpp @@ -158,11 +158,13 @@ FormatCache::Entry::SetValidator (lldb::TypeValidatorImplSP validator_sp) m_validator_sp = validator_sp; } -FormatCache::FormatCache () : -m_map(), -m_mutex (Mutex::eMutexTypeRecursive) +FormatCache::FormatCache() + : m_map(), + m_mutex() #ifdef LLDB_CONFIGURATION_DEBUG -,m_cache_hits(0),m_cache_misses(0) + , + m_cache_hits(0), + m_cache_misses(0) #endif { } @@ -181,7 +183,7 @@ FormatCache::GetEntry (const ConstString& type) bool FormatCache::GetFormat (const ConstString& type,lldb::TypeFormatImplSP& format_sp) { - Mutex::Locker lock(m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); auto entry = GetEntry(type); if (entry.IsFormatCached()) { @@ -201,7 +203,7 @@ FormatCache::GetFormat (const ConstString& type,lldb::TypeFormatImplSP& format_s bool FormatCache::GetSummary (const ConstString& type,lldb::TypeSummaryImplSP& summary_sp) { - Mutex::Locker lock(m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); auto entry = GetEntry(type); if (entry.IsSummaryCached()) { @@ -221,7 +223,7 @@ FormatCache::GetSummary (const ConstString& type,lldb::TypeSummaryImplSP& summar bool FormatCache::GetSynthetic (const ConstString& type,lldb::SyntheticChildrenSP& synthetic_sp) { - Mutex::Locker lock(m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); auto entry = GetEntry(type); if (entry.IsSyntheticCached()) { @@ -241,7 +243,7 @@ FormatCache::GetSynthetic (const ConstString& type,lldb::SyntheticChildrenSP& sy bool FormatCache::GetValidator (const ConstString& type,lldb::TypeValidatorImplSP& validator_sp) { - Mutex::Locker lock(m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); auto entry = GetEntry(type); if (entry.IsValidatorCached()) { @@ -261,35 +263,35 @@ FormatCache::GetValidator (const ConstString& type,lldb::TypeValidatorImplSP& va void FormatCache::SetFormat (const ConstString& type,lldb::TypeFormatImplSP& format_sp) { - Mutex::Locker lock(m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); GetEntry(type).SetFormat(format_sp); } void FormatCache::SetSummary (const ConstString& type,lldb::TypeSummaryImplSP& summary_sp) { - Mutex::Locker lock(m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); GetEntry(type).SetSummary(summary_sp); } void FormatCache::SetSynthetic (const ConstString& type,lldb::SyntheticChildrenSP& synthetic_sp) { - Mutex::Locker lock(m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); GetEntry(type).SetSynthetic(synthetic_sp); } void FormatCache::SetValidator (const ConstString& type,lldb::TypeValidatorImplSP& validator_sp) { - Mutex::Locker lock(m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); GetEntry(type).SetValidator(validator_sp); } void FormatCache::Clear () { - Mutex::Locker lock(m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); m_map.clear(); } diff --git a/lldb/source/DataFormatters/FormatManager.cpp b/lldb/source/DataFormatters/FormatManager.cpp index 35a0468306f..f51243f841e 100644 --- a/lldb/source/DataFormatters/FormatManager.cpp +++ b/lldb/source/DataFormatters/FormatManager.cpp @@ -128,7 +128,7 @@ FormatManager::Changed () { ++m_last_revision; m_format_cache.Clear (); - Mutex::Locker lang_locker(m_language_categories_mutex); + std::lock_guard<std::recursive_mutex> guard(m_language_categories_mutex); for (auto& iter : m_language_categories_map) { if (iter.second) @@ -181,7 +181,7 @@ void FormatManager::EnableAllCategories () { m_categories_map.EnableAllCategories (); - Mutex::Locker lang_locker(m_language_categories_mutex); + std::lock_guard<std::recursive_mutex> guard(m_language_categories_mutex); for (auto& iter : m_language_categories_map) { if (iter.second) @@ -193,7 +193,7 @@ void FormatManager::DisableAllCategories () { m_categories_map.DisableAllCategories (); - Mutex::Locker lang_locker(m_language_categories_mutex); + std::lock_guard<std::recursive_mutex> guard(m_language_categories_mutex); for (auto& iter : m_language_categories_map) { if (iter.second) @@ -502,7 +502,7 @@ void FormatManager::ForEachCategory(TypeCategoryMap::ForEachCallback callback) { m_categories_map.ForEach(callback); - Mutex::Locker locker(m_language_categories_mutex); + std::lock_guard<std::recursive_mutex> guard(m_language_categories_mutex); for (const auto& entry : m_language_categories_map) { if (auto category_sp = entry.second->GetCategory()) @@ -712,7 +712,7 @@ FormatManager::GetCandidateLanguages (lldb::LanguageType lang_type) LanguageCategory* FormatManager::GetCategoryForLanguage (lldb::LanguageType lang_type) { - Mutex::Locker locker(m_language_categories_mutex); + std::lock_guard<std::recursive_mutex> guard(m_language_categories_mutex); auto iter = m_language_categories_map.find(lang_type), end = m_language_categories_map.end(); if (iter != end) return iter->second.get(); @@ -1055,22 +1055,22 @@ FormatManager::GetHardcodedValidator (FormattersMatchData& match_data) return retval_sp; } -FormatManager::FormatManager() : - m_last_revision(0), - m_format_cache(), - m_language_categories_mutex(Mutex::eMutexTypeRecursive), - m_language_categories_map(), - m_named_summaries_map(this), - m_categories_map(this), - m_default_category_name(ConstString("default")), - m_system_category_name(ConstString("system")), - m_vectortypes_category_name(ConstString("VectorTypes")) +FormatManager::FormatManager() + : m_last_revision(0), + m_format_cache(), + m_language_categories_mutex(), + m_language_categories_map(), + m_named_summaries_map(this), + m_categories_map(this), + m_default_category_name(ConstString("default")), + m_system_category_name(ConstString("system")), + m_vectortypes_category_name(ConstString("VectorTypes")) { LoadSystemFormatters(); LoadVectorFormatters(); - - EnableCategory(m_vectortypes_category_name,TypeCategoryMap::Last, lldb::eLanguageTypeObjC_plus_plus); - EnableCategory(m_system_category_name,TypeCategoryMap::Last, lldb::eLanguageTypeObjC_plus_plus); + + EnableCategory(m_vectortypes_category_name, TypeCategoryMap::Last, lldb::eLanguageTypeObjC_plus_plus); + EnableCategory(m_system_category_name, TypeCategoryMap::Last, lldb::eLanguageTypeObjC_plus_plus); } void diff --git a/lldb/source/DataFormatters/TypeCategory.cpp b/lldb/source/DataFormatters/TypeCategory.cpp index 636d935b762..9df3ec6721f 100644 --- a/lldb/source/DataFormatters/TypeCategory.cpp +++ b/lldb/source/DataFormatters/TypeCategory.cpp @@ -18,21 +18,20 @@ using namespace lldb; using namespace lldb_private; -TypeCategoryImpl::TypeCategoryImpl(IFormatChangeListener* clist, - ConstString name, - std::initializer_list<lldb::LanguageType> langs) : -m_format_cont("format","regex-format",clist), -m_summary_cont("summary","regex-summary",clist), -m_filter_cont("filter","regex-filter",clist), +TypeCategoryImpl::TypeCategoryImpl(IFormatChangeListener *clist, ConstString name, + std::initializer_list<lldb::LanguageType> langs) + : m_format_cont("format", "regex-format", clist), + m_summary_cont("summary", "regex-summary", clist), + m_filter_cont("filter", "regex-filter", clist), #ifndef LLDB_DISABLE_PYTHON -m_synth_cont("synth","regex-synth",clist), + m_synth_cont("synth", "regex-synth", clist), #endif -m_validator_cont("validator","regex-validator",clist), -m_enabled(false), -m_change_listener(clist), -m_mutex(Mutex::eMutexTypeRecursive), -m_name(name), -m_languages() + m_validator_cont("validator", "regex-validator", clist), + m_enabled(false), + m_change_listener(clist), + m_mutex(), + m_name(name), + m_languages() { for (const lldb::LanguageType lang : langs) AddLanguage(lang); @@ -673,7 +672,7 @@ TypeCategoryImpl::GetTypeNameSpecifierForValidatorAtIndex (size_t index) void TypeCategoryImpl::Enable (bool value, uint32_t position) { - Mutex::Locker locker(m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); if ( (m_enabled = value) ) m_enabled_position = position; if (m_change_listener) diff --git a/lldb/source/DataFormatters/TypeCategoryMap.cpp b/lldb/source/DataFormatters/TypeCategoryMap.cpp index ba428417c7f..984c7f213de 100644 --- a/lldb/source/DataFormatters/TypeCategoryMap.cpp +++ b/lldb/source/DataFormatters/TypeCategoryMap.cpp @@ -20,22 +20,19 @@ using namespace lldb; using namespace lldb_private; -TypeCategoryMap::TypeCategoryMap (IFormatChangeListener* lst) : -m_map_mutex(Mutex::eMutexTypeRecursive), -listener(lst), -m_map(), -m_active_categories() +TypeCategoryMap::TypeCategoryMap(IFormatChangeListener *lst) + : m_map_mutex(), listener(lst), m_map(), m_active_categories() { ConstString default_cs("default"); lldb::TypeCategoryImplSP default_sp = lldb::TypeCategoryImplSP(new TypeCategoryImpl(listener, default_cs)); - Add(default_cs,default_sp); - Enable(default_cs,First); + Add(default_cs, default_sp); + Enable(default_cs, First); } void TypeCategoryMap::Add (KeyType name, const ValueSP& entry) { - Mutex::Locker locker(m_map_mutex); + std::lock_guard<std::recursive_mutex> guard(m_map_mutex); m_map[name] = entry; if (listener) listener->Changed(); @@ -44,7 +41,7 @@ TypeCategoryMap::Add (KeyType name, const ValueSP& entry) bool TypeCategoryMap::Delete (KeyType name) { - Mutex::Locker locker(m_map_mutex); + std::lock_guard<std::recursive_mutex> guard(m_map_mutex); MapIterator iter = m_map.find(name); if (iter == m_map.end()) return false; @@ -58,7 +55,7 @@ TypeCategoryMap::Delete (KeyType name) bool TypeCategoryMap::Enable (KeyType category_name, Position pos) { - Mutex::Locker locker(m_map_mutex); + std::lock_guard<std::recursive_mutex> guard(m_map_mutex); ValueSP category; if (!Get(category_name,category)) return false; @@ -68,7 +65,7 @@ TypeCategoryMap::Enable (KeyType category_name, Position pos) bool TypeCategoryMap::Disable (KeyType category_name) { - Mutex::Locker locker(m_map_mutex); + std::lock_guard<std::recursive_mutex> guard(m_map_mutex); ValueSP category; if (!Get(category_name,category)) return false; @@ -78,7 +75,7 @@ TypeCategoryMap::Disable (KeyType category_name) bool TypeCategoryMap::Enable (ValueSP category, Position pos) { - Mutex::Locker locker(m_map_mutex); + std::lock_guard<std::recursive_mutex> guard(m_map_mutex); if (category.get()) { Position pos_w = pos; @@ -107,7 +104,7 @@ TypeCategoryMap::Enable (ValueSP category, Position pos) bool TypeCategoryMap::Disable (ValueSP category) { - Mutex::Locker locker(m_map_mutex); + std::lock_guard<std::recursive_mutex> guard(m_map_mutex); if (category.get()) { m_active_categories.remove_if(delete_matching_categories(category)); @@ -120,7 +117,7 @@ TypeCategoryMap::Disable (ValueSP category) void TypeCategoryMap::EnableAllCategories () { - Mutex::Locker locker(m_map_mutex); + std::lock_guard<std::recursive_mutex> guard(m_map_mutex); std::vector<ValueSP> sorted_categories(m_map.size(), ValueSP()); MapType::iterator iter = m_map.begin(), end = m_map.end(); for (; iter != end; ++iter) @@ -148,7 +145,7 @@ TypeCategoryMap::EnableAllCategories () void TypeCategoryMap::DisableAllCategories () { - Mutex::Locker locker(m_map_mutex); + std::lock_guard<std::recursive_mutex> guard(m_map_mutex); Position p = First; for (; false == m_active_categories.empty(); p++) { @@ -160,7 +157,7 @@ TypeCategoryMap::DisableAllCategories () void TypeCategoryMap::Clear () { - Mutex::Locker locker(m_map_mutex); + std::lock_guard<std::recursive_mutex> guard(m_map_mutex); m_map.clear(); m_active_categories.clear(); if (listener) @@ -170,7 +167,7 @@ TypeCategoryMap::Clear () bool TypeCategoryMap::Get (KeyType name, ValueSP& entry) { - Mutex::Locker locker(m_map_mutex); + std::lock_guard<std::recursive_mutex> guard(m_map_mutex); MapIterator iter = m_map.find(name); if (iter == m_map.end()) return false; @@ -181,7 +178,7 @@ TypeCategoryMap::Get (KeyType name, ValueSP& entry) bool TypeCategoryMap::Get (uint32_t pos, ValueSP& entry) { - Mutex::Locker locker(m_map_mutex); + std::lock_guard<std::recursive_mutex> guard(m_map_mutex); MapIterator iter = m_map.begin(); MapIterator end = m_map.end(); while (pos > 0) @@ -202,8 +199,8 @@ TypeCategoryMap::AnyMatches (ConstString type_name, const char** matching_category, TypeCategoryImpl::FormatCategoryItems* matching_type) { - Mutex::Locker locker(m_map_mutex); - + std::lock_guard<std::recursive_mutex> guard(m_map_mutex); + MapIterator pos, end = m_map.end(); for (pos = m_map.begin(); pos != end; pos++) { @@ -220,8 +217,8 @@ TypeCategoryMap::AnyMatches (ConstString type_name, lldb::TypeFormatImplSP TypeCategoryMap::GetFormat (FormattersMatchData& match_data) { - Mutex::Locker locker(m_map_mutex); - + std::lock_guard<std::recursive_mutex> guard(m_map_mutex); + uint32_t reason_why; ActiveCategoriesIterator begin, end = m_active_categories.end(); @@ -258,8 +255,8 @@ TypeCategoryMap::GetFormat (FormattersMatchData& match_data) lldb::TypeSummaryImplSP TypeCategoryMap::GetSummaryFormat (FormattersMatchData& match_data) { - Mutex::Locker locker(m_map_mutex); - + std::lock_guard<std::recursive_mutex> guard(m_map_mutex); + uint32_t reason_why; ActiveCategoriesIterator begin, end = m_active_categories.end(); @@ -297,8 +294,8 @@ TypeCategoryMap::GetSummaryFormat (FormattersMatchData& match_data) lldb::SyntheticChildrenSP TypeCategoryMap::GetSyntheticChildren (FormattersMatchData& match_data) { - Mutex::Locker locker(m_map_mutex); - + std::lock_guard<std::recursive_mutex> guard(m_map_mutex); + uint32_t reason_why; ActiveCategoriesIterator begin, end = m_active_categories.end(); @@ -337,8 +334,8 @@ TypeCategoryMap::GetSyntheticChildren (FormattersMatchData& match_data) lldb::TypeValidatorImplSP TypeCategoryMap::GetValidator (FormattersMatchData& match_data) { - Mutex::Locker locker(m_map_mutex); - + std::lock_guard<std::recursive_mutex> guard(m_map_mutex); + uint32_t reason_why; ActiveCategoriesIterator begin, end = m_active_categories.end(); @@ -377,8 +374,8 @@ TypeCategoryMap::ForEach(ForEachCallback callback) { if (callback) { - Mutex::Locker locker(m_map_mutex); - + std::lock_guard<std::recursive_mutex> guard(m_map_mutex); + // loop through enabled categories in respective order { ActiveCategoriesIterator begin, end = m_active_categories.end(); @@ -408,8 +405,8 @@ TypeCategoryMap::ForEach(ForEachCallback callback) TypeCategoryImplSP TypeCategoryMap::GetAtIndex (uint32_t index) { - Mutex::Locker locker(m_map_mutex); - + std::lock_guard<std::recursive_mutex> guard(m_map_mutex); + if (index < m_map.size()) { MapIterator pos, end = m_map.end(); diff --git a/lldb/source/Expression/IRExecutionUnit.cpp b/lldb/source/Expression/IRExecutionUnit.cpp index 1fc7b75e18d..69f4ee3d174 100644 --- a/lldb/source/Expression/IRExecutionUnit.cpp +++ b/lldb/source/Expression/IRExecutionUnit.cpp @@ -247,7 +247,7 @@ IRExecutionUnit::GetRunnableInfo(Error &error, { lldb::ProcessSP process_sp(GetProcessWP().lock()); - static Mutex s_runnable_info_mutex(Mutex::Type::eMutexTypeRecursive); + static std::recursive_mutex s_runnable_info_mutex; func_addr = LLDB_INVALID_ADDRESS; func_end = LLDB_INVALID_ADDRESS; @@ -267,7 +267,7 @@ IRExecutionUnit::GetRunnableInfo(Error &error, return; }; - Mutex::Locker runnable_info_mutex_locker(s_runnable_info_mutex); + std::lock_guard<std::recursive_mutex> guard(s_runnable_info_mutex); m_did_jit = true; diff --git a/lldb/source/Host/common/Editline.cpp b/lldb/source/Host/common/Editline.cpp index 4640154c6cb..86960f83d65 100644 --- a/lldb/source/Host/common/Editline.cpp +++ b/lldb/source/Host/common/Editline.cpp @@ -19,7 +19,6 @@ #include "lldb/Host/FileSpec.h" #include "lldb/Host/FileSystem.h" #include "lldb/Host/Host.h" -#include "lldb/Host/Mutex.h" #include "lldb/Utility/LLDBAssert.h" using namespace lldb_private; @@ -227,9 +226,9 @@ namespace lldb_private GetHistory (const std::string &prefix) { typedef std::map<std::string, EditlineHistoryWP> WeakHistoryMap; - static Mutex g_mutex (Mutex::eMutexTypeRecursive); + static std::recursive_mutex g_mutex; static WeakHistoryMap g_weak_map; - Mutex::Locker locker (g_mutex); + std::lock_guard<std::recursive_mutex> guard(g_mutex); WeakHistoryMap::const_iterator pos = g_weak_map.find (prefix); EditlineHistorySP history_sp; if (pos != g_weak_map.end()) @@ -587,9 +586,9 @@ Editline::GetCharacter (EditLineCharType * c) // (blocking operation), so we do not hold the mutex indefinitely. This gives a chance // for someone to interrupt us. After Read returns, immediately lock the mutex again and // check if we were interrupted. - m_output_mutex.Unlock(); + m_output_mutex.unlock(); int read_count = m_input_connection.Read(&ch, 1, UINT32_MAX, status, NULL); - m_output_mutex.Lock(); + m_output_mutex.lock(); if (m_editor_status == EditorStatus::Interrupted) { while (read_count > 0 && status == lldb::eConnectionStatusSuccess) @@ -1284,7 +1283,7 @@ bool Editline::Interrupt() { bool result = true; - Mutex::Locker locker(m_output_mutex); + std::lock_guard<std::mutex> guard(m_output_mutex); if (m_editor_status == EditorStatus::Editing) { fprintf(m_output_file, "^C\n"); result = m_input_connection.InterruptRead(); @@ -1297,7 +1296,7 @@ bool Editline::Cancel() { bool result = true; - Mutex::Locker locker(m_output_mutex); + std::lock_guard<std::mutex> guard(m_output_mutex); if (m_editor_status == EditorStatus::Editing) { MoveCursor(CursorLocation::EditingCursor, CursorLocation::BlockStart); fprintf(m_output_file, ANSI_CLEAR_BELOW); @@ -1338,8 +1337,8 @@ Editline::GetLine (std::string &line, bool &interrupted) ConfigureEditor (false); m_input_lines = std::vector<EditLineStringType>(); m_input_lines.insert (m_input_lines.begin(), EditLineConstString("")); - - Mutex::Locker locker(m_output_mutex); + + std::lock_guard<std::mutex> guard(m_output_mutex); lldbassert(m_editor_status != EditorStatus::Editing); if (m_editor_status == EditorStatus::Interrupted) @@ -1392,8 +1391,8 @@ Editline::GetLines (int first_line_number, StringList &lines, bool &interrupted) SetBaseLineNumber (first_line_number); m_input_lines = std::vector<EditLineStringType>(); m_input_lines.insert (m_input_lines.begin(), EditLineConstString("")); - - Mutex::Locker locker(m_output_mutex); + + std::lock_guard<std::mutex> guard(m_output_mutex); // Begin the line editing loop DisplayInput(); SetCurrentLine (0); @@ -1427,7 +1426,7 @@ Editline::GetLines (int first_line_number, StringList &lines, bool &interrupted) void Editline::PrintAsync (Stream *stream, const char *s, size_t len) { - Mutex::Locker locker(m_output_mutex); + std::lock_guard<std::mutex> guard(m_output_mutex); if (m_editor_status == EditorStatus::Editing) { MoveCursor(CursorLocation::EditingCursor, CursorLocation::BlockStart); diff --git a/lldb/source/Host/common/NativeBreakpointList.cpp b/lldb/source/Host/common/NativeBreakpointList.cpp index 52b9baf5f53..67873a06dd2 100644 --- a/lldb/source/Host/common/NativeBreakpointList.cpp +++ b/lldb/source/Host/common/NativeBreakpointList.cpp @@ -17,8 +17,7 @@ using namespace lldb; using namespace lldb_private; -NativeBreakpointList::NativeBreakpointList () : - m_mutex (Mutex::eMutexTypeRecursive) +NativeBreakpointList::NativeBreakpointList() : m_mutex() { } @@ -29,7 +28,7 @@ NativeBreakpointList::AddRef (lldb::addr_t addr, size_t size_hint, bool hardware if (log) log->Printf ("NativeBreakpointList::%s addr = 0x%" PRIx64 ", size_hint = %lu, hardware = %s", __FUNCTION__, addr, size_hint, hardware ? "true" : "false"); - Mutex::Locker locker (m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); // Check if the breakpoint is already set. auto iter = m_breakpoints.find (addr); @@ -72,7 +71,7 @@ NativeBreakpointList::DecRef (lldb::addr_t addr) if (log) log->Printf ("NativeBreakpointList::%s addr = 0x%" PRIx64, __FUNCTION__, addr); - Mutex::Locker locker (m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); // Check if the breakpoint is already set. auto iter = m_breakpoints.find (addr); @@ -136,7 +135,7 @@ NativeBreakpointList::EnableBreakpoint (lldb::addr_t addr) if (log) log->Printf ("NativeBreakpointList::%s addr = 0x%" PRIx64, __FUNCTION__, addr); - Mutex::Locker locker (m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); // Ensure we have said breakpoint. auto iter = m_breakpoints.find (addr); @@ -159,7 +158,7 @@ NativeBreakpointList::DisableBreakpoint (lldb::addr_t addr) if (log) log->Printf ("NativeBreakpointList::%s addr = 0x%" PRIx64, __FUNCTION__, addr); - Mutex::Locker locker (m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); // Ensure we have said breakpoint. auto iter = m_breakpoints.find (addr); @@ -182,7 +181,7 @@ NativeBreakpointList::GetBreakpoint (lldb::addr_t addr, NativeBreakpointSP &brea if (log) log->Printf ("NativeBreakpointList::%s addr = 0x%" PRIx64, __FUNCTION__, addr); - Mutex::Locker locker (m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); // Ensure we have said breakpoint. auto iter = m_breakpoints.find (addr); diff --git a/lldb/source/Host/common/NativeProcessProtocol.cpp b/lldb/source/Host/common/NativeProcessProtocol.cpp index 7d2f4012bf8..dfac0cb5645 100644 --- a/lldb/source/Host/common/NativeProcessProtocol.cpp +++ b/lldb/source/Host/common/NativeProcessProtocol.cpp @@ -26,22 +26,22 @@ using namespace lldb_private; // NativeProcessProtocol Members // ----------------------------------------------------------------------------- -NativeProcessProtocol::NativeProcessProtocol (lldb::pid_t pid) : - m_pid (pid), - m_threads (), - m_current_thread_id (LLDB_INVALID_THREAD_ID), - m_threads_mutex (Mutex::eMutexTypeRecursive), - m_state (lldb::eStateInvalid), - m_state_mutex (Mutex::eMutexTypeRecursive), - m_exit_type (eExitTypeInvalid), - m_exit_status (0), - m_exit_description (), - m_delegates_mutex (Mutex::eMutexTypeRecursive), - m_delegates (), - m_breakpoint_list (), - m_watchpoint_list (), - m_terminal_fd (-1), - m_stop_id (0) +NativeProcessProtocol::NativeProcessProtocol(lldb::pid_t pid) + : m_pid(pid), + m_threads(), + m_current_thread_id(LLDB_INVALID_THREAD_ID), + m_threads_mutex(), + m_state(lldb::eStateInvalid), + m_state_mutex(), + m_exit_type(eExitTypeInvalid), + m_exit_status(0), + m_exit_description(), + m_delegates_mutex(), + m_delegates(), + m_breakpoint_list(), + m_watchpoint_list(), + m_terminal_fd(-1), + m_stop_id(0) { } @@ -117,7 +117,7 @@ NativeProcessProtocol::SetExitStatus (ExitType exit_type, int status, const char NativeThreadProtocolSP NativeProcessProtocol::GetThreadAtIndex (uint32_t idx) { - Mutex::Locker locker (m_threads_mutex); + std::lock_guard<std::recursive_mutex> guard(m_threads_mutex); if (idx < m_threads.size ()) return m_threads[idx]; return NativeThreadProtocolSP (); @@ -137,7 +137,7 @@ NativeProcessProtocol::GetThreadByIDUnlocked (lldb::tid_t tid) NativeThreadProtocolSP NativeProcessProtocol::GetThreadByID (lldb::tid_t tid) { - Mutex::Locker locker (m_threads_mutex); + std::lock_guard<std::recursive_mutex> guard(m_threads_mutex); return GetThreadByIDUnlocked (tid); } @@ -221,7 +221,7 @@ NativeProcessProtocol::SetWatchpoint (lldb::addr_t addr, size_t size, uint32_t w // conceivable that if there are more threads than hardware // watchpoints available, some of the threads will fail to set // hardware watchpoints while software ones may be available. - Mutex::Locker locker (m_threads_mutex); + std::lock_guard<std::recursive_mutex> guard(m_threads_mutex); for (auto thread_sp : m_threads) { assert (thread_sp && "thread list should not have a NULL thread!"); @@ -276,7 +276,7 @@ NativeProcessProtocol::RemoveWatchpoint (lldb::addr_t addr) Error overall_error; - Mutex::Locker locker (m_threads_mutex); + std::lock_guard<std::recursive_mutex> guard(m_threads_mutex); for (auto thread_sp : m_threads) { assert (thread_sp && "thread list should not have a NULL thread!"); @@ -300,7 +300,7 @@ NativeProcessProtocol::RemoveWatchpoint (lldb::addr_t addr) bool NativeProcessProtocol::RegisterNativeDelegate (NativeDelegate &native_delegate) { - Mutex::Locker locker (m_delegates_mutex); + std::lock_guard<std::recursive_mutex> guard(m_delegates_mutex); if (std::find (m_delegates.begin (), m_delegates.end (), &native_delegate) != m_delegates.end ()) return false; @@ -312,7 +312,7 @@ NativeProcessProtocol::RegisterNativeDelegate (NativeDelegate &native_delegate) bool NativeProcessProtocol::UnregisterNativeDelegate (NativeDelegate &native_delegate) { - Mutex::Locker locker (m_delegates_mutex); + std::lock_guard<std::recursive_mutex> guard(m_delegates_mutex); const auto initial_size = m_delegates.size (); m_delegates.erase (remove (m_delegates.begin (), m_delegates.end (), &native_delegate), m_delegates.end ()); @@ -327,7 +327,7 @@ NativeProcessProtocol::SynchronouslyNotifyProcessStateChanged (lldb::StateType s { Log *log (GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS)); - Mutex::Locker locker (m_delegates_mutex); + std::lock_guard<std::recursive_mutex> guard(m_delegates_mutex); for (auto native_delegate: m_delegates) native_delegate->ProcessStateChanged (this, state); @@ -354,7 +354,7 @@ NativeProcessProtocol::NotifyDidExec () log->Printf ("NativeProcessProtocol::%s - preparing to call delegates", __FUNCTION__); { - Mutex::Locker locker (m_delegates_mutex); + std::lock_guard<std::recursive_mutex> guard(m_delegates_mutex); for (auto native_delegate: m_delegates) native_delegate->DidExec (this); } @@ -394,14 +394,14 @@ NativeProcessProtocol::DisableBreakpoint (lldb::addr_t addr) lldb::StateType NativeProcessProtocol::GetState () const { - Mutex::Locker locker (m_state_mutex); + std::lock_guard<std::recursive_mutex> guard(m_state_mutex); return m_state; } void NativeProcessProtocol::SetState (lldb::StateType state, bool notify_delegates) { - Mutex::Locker locker (m_state_mutex); + std::lock_guard<std::recursive_mutex> guard(m_state_mutex); if (state == m_state) return; @@ -426,8 +426,8 @@ NativeProcessProtocol::SetState (lldb::StateType state, bool notify_delegates) uint32_t NativeProcessProtocol::GetStopID () const { - Mutex::Locker locker (m_state_mutex); - return m_stop_id; + std::lock_guard<std::recursive_mutex> guard(m_state_mutex); + return m_stop_id; } void diff --git a/lldb/source/Host/common/SoftwareBreakpoint.cpp b/lldb/source/Host/common/SoftwareBreakpoint.cpp index 5a6f78372b3..51cb34ffe6d 100644 --- a/lldb/source/Host/common/SoftwareBreakpoint.cpp +++ b/lldb/source/Host/common/SoftwareBreakpoint.cpp @@ -12,7 +12,6 @@ #include "lldb/Core/Error.h" #include "lldb/Core/Log.h" #include "lldb/Host/Debug.h" -#include "lldb/Host/Mutex.h" #include "lldb/Host/common/NativeProcessProtocol.h" diff --git a/lldb/source/Host/macosx/Host.mm b/lldb/source/Host/macosx/Host.mm index a8b28d72cb5..8bd2e2f2b25 100644 --- a/lldb/source/Host/macosx/Host.mm +++ b/lldb/source/Host/macosx/Host.mm @@ -556,10 +556,10 @@ LaunchInNewTerminalWithAppleScript (const char *exe_path, ProcessLaunchInfo &lau // On MacOSX CrashReporter will display a string for each shared library if // the shared library has an exported symbol named "__crashreporter_info__". -static Mutex& -GetCrashReporterMutex () +static std::mutex & +GetCrashReporterMutex() { - static Mutex g_mutex; + static std::mutex g_mutex; return g_mutex; } @@ -573,8 +573,8 @@ void Host::SetCrashDescriptionWithFormat (const char *format, ...) { static StreamString g_crash_description; - Mutex::Locker locker (GetCrashReporterMutex ()); - + std::lock_guard<std::mutex> guard(GetCrashReporterMutex()); + if (format) { va_list args; @@ -593,7 +593,7 @@ Host::SetCrashDescriptionWithFormat (const char *format, ...) void Host::SetCrashDescription (const char *cstr) { - Mutex::Locker locker (GetCrashReporterMutex ()); + std::lock_guard<std::mutex> guard(GetCrashReporterMutex()); static std::string g_crash_description; if (cstr) { diff --git a/lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp b/lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp index dbbd5a1dcc3..52d65b1e9a9 100644 --- a/lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp +++ b/lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp @@ -79,12 +79,12 @@ GetURLAddress(const char *url, const char *scheme) } ConnectionFileDescriptor::ConnectionFileDescriptor(bool child_processes_inherit) - : Connection() - , m_pipe() - , m_mutex(Mutex::eMutexTypeRecursive) - , m_shutting_down(false) - , m_waiting_for_accept(false) - , m_child_processes_inherit(child_processes_inherit) + : Connection(), + m_pipe(), + m_mutex(), + m_shutting_down(false), + m_waiting_for_accept(false), + m_child_processes_inherit(child_processes_inherit) { Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_CONNECTION | LIBLLDB_LOG_OBJECT)); if (log) @@ -92,30 +92,30 @@ ConnectionFileDescriptor::ConnectionFileDescriptor(bool child_processes_inherit) } ConnectionFileDescriptor::ConnectionFileDescriptor(int fd, bool owns_fd) - : Connection() - , m_pipe() - , m_mutex(Mutex::eMutexTypeRecursive) - , m_shutting_down(false) - , m_waiting_for_accept(false) - , m_child_processes_inherit(false) + : Connection(), + m_pipe(), + m_mutex(), + m_shutting_down(false), + m_waiting_for_accept(false), + m_child_processes_inherit(false) { m_write_sp.reset(new File(fd, owns_fd)); m_read_sp.reset(new File(fd, false)); Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_CONNECTION | LIBLLDB_LOG_OBJECT)); if (log) - log->Printf("%p ConnectionFileDescriptor::ConnectionFileDescriptor (fd = %i, owns_fd = %i)", static_cast<void *>(this), fd, - owns_fd); + log->Printf("%p ConnectionFileDescriptor::ConnectionFileDescriptor (fd = %i, owns_fd = %i)", + static_cast<void *>(this), fd, owns_fd); OpenCommandPipe(); } -ConnectionFileDescriptor::ConnectionFileDescriptor(Socket* socket) - : Connection() - , m_pipe() - , m_mutex(Mutex::eMutexTypeRecursive) - , m_shutting_down(false) - , m_waiting_for_accept(false) - , m_child_processes_inherit(false) +ConnectionFileDescriptor::ConnectionFileDescriptor(Socket *socket) + : Connection(), + m_pipe(), + m_mutex(), + m_shutting_down(false), + m_waiting_for_accept(false), + m_child_processes_inherit(false) { InitializeSocket(socket); } @@ -170,7 +170,7 @@ ConnectionFileDescriptor::IsConnected() const ConnectionStatus ConnectionFileDescriptor::Connect(const char *s, Error *error_ptr) { - Mutex::Locker locker(m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_CONNECTION)); if (log) log->Printf("%p ConnectionFileDescriptor::Connect (url = '%s')", static_cast<void *>(this), s); @@ -374,10 +374,8 @@ ConnectionFileDescriptor::Disconnect(Error *error_ptr) m_shutting_down = true; - Mutex::Locker locker; - bool got_lock = locker.TryLock(m_mutex); - - if (!got_lock) + std::unique_lock<std::recursive_mutex> locker(m_mutex, std::defer_lock); + if (!locker.try_lock()) { if (m_pipe.CanWrite()) { @@ -392,7 +390,7 @@ ConnectionFileDescriptor::Disconnect(Error *error_ptr) log->Printf("%p ConnectionFileDescriptor::Disconnect(): Couldn't get the lock, but no command pipe is available.", static_cast<void *>(this)); } - locker.Lock(m_mutex); + locker.lock(); } Error error = m_read_sp->Close(); @@ -415,9 +413,8 @@ ConnectionFileDescriptor::Read(void *dst, size_t dst_len, uint32_t timeout_usec, { Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_CONNECTION)); - Mutex::Locker locker; - bool got_lock = locker.TryLock(m_mutex); - if (!got_lock) + std::unique_lock<std::recursive_mutex> locker(m_mutex, std::defer_lock); + if (!locker.try_lock()) { if (log) log->Printf("%p ConnectionFileDescriptor::Read () failed to get the connection lock.", static_cast<void *>(this)); diff --git a/lldb/source/Initialization/SystemLifetimeManager.cpp b/lldb/source/Initialization/SystemLifetimeManager.cpp index eafbe68c998..0f61622b31b 100644 --- a/lldb/source/Initialization/SystemLifetimeManager.cpp +++ b/lldb/source/Initialization/SystemLifetimeManager.cpp @@ -10,16 +10,13 @@ #include "lldb/Initialization/SystemLifetimeManager.h" #include "lldb/Core/Debugger.h" -#include "lldb/Host/Mutex.h" #include "lldb/Initialization/SystemInitializer.h" #include <utility> using namespace lldb_private; -SystemLifetimeManager::SystemLifetimeManager() - : m_mutex(Mutex::eMutexTypeRecursive) - , m_initialized(false) +SystemLifetimeManager::SystemLifetimeManager() : m_mutex(), m_initialized(false) { } @@ -32,7 +29,7 @@ void SystemLifetimeManager::Initialize(std::unique_ptr<SystemInitializer> initializer, LoadPluginCallbackType plugin_callback) { - Mutex::Locker locker(m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); if (!m_initialized) { assert(!m_initializer && @@ -48,7 +45,7 @@ SystemLifetimeManager::Initialize(std::unique_ptr<SystemInitializer> initializer void SystemLifetimeManager::Terminate() { - Mutex::Locker locker(m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); if (m_initialized) { diff --git a/lldb/source/Interpreter/CommandHistory.cpp b/lldb/source/Interpreter/CommandHistory.cpp index 9d3c814697b..ff87e528d36 100644 --- a/lldb/source/Interpreter/CommandHistory.cpp +++ b/lldb/source/Interpreter/CommandHistory.cpp @@ -15,10 +15,7 @@ using namespace lldb; using namespace lldb_private; - -CommandHistory::CommandHistory () : - m_mutex(Mutex::eMutexTypeRecursive), - m_history() +CommandHistory::CommandHistory() : m_mutex(), m_history() {} CommandHistory::~CommandHistory () @@ -27,21 +24,21 @@ CommandHistory::~CommandHistory () size_t CommandHistory::GetSize () const { - Mutex::Locker locker(m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); return m_history.size(); } bool CommandHistory::IsEmpty () const { - Mutex::Locker locker(m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); return m_history.empty(); } const char* CommandHistory::FindString (const char* input_str) const { - Mutex::Locker locker(m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); if (!input_str) return nullptr; if (input_str[0] != g_repeat_char) @@ -80,7 +77,7 @@ CommandHistory::FindString (const char* input_str) const const char* CommandHistory::GetStringAtIndex (size_t idx) const { - Mutex::Locker locker(m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); if (idx < m_history.size()) return m_history[idx].c_str(); return nullptr; @@ -95,7 +92,7 @@ CommandHistory::operator [] (size_t idx) const const char* CommandHistory::GetRecentmostString () const { - Mutex::Locker locker(m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); if (m_history.empty()) return nullptr; return m_history.back().c_str(); @@ -105,7 +102,7 @@ void CommandHistory::AppendString (const std::string& str, bool reject_if_dupe) { - Mutex::Locker locker(m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); if (reject_if_dupe) { if (!m_history.empty()) @@ -120,7 +117,7 @@ CommandHistory::AppendString (const std::string& str, void CommandHistory::Clear () { - Mutex::Locker locker(m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); m_history.clear(); } @@ -129,7 +126,7 @@ CommandHistory::Dump (Stream& stream, size_t start_idx, size_t stop_idx) const { - Mutex::Locker locker(m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); stop_idx = std::min(stop_idx + 1, m_history.size()); for (size_t counter = start_idx; counter < stop_idx; diff --git a/lldb/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.h b/lldb/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.h index 6359146d81d..e8f09a4d3ab 100644 --- a/lldb/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.h +++ b/lldb/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.h @@ -13,6 +13,7 @@ // C Includes // C++ Includes #include <memory> +#include <mutex> #include <string> // Other libraries and framework includes @@ -22,7 +23,6 @@ #include "lldb/Core/Address.h" #include "lldb/Core/Disassembler.h" #include "lldb/Core/PluginManager.h" -#include "lldb/Host/Mutex.h" // Opaque references to C++ Objects in LLVM's MC. namespace llvm @@ -147,7 +147,7 @@ protected: void Lock(InstructionLLVMC *inst, const lldb_private::ExecutionContext *exe_ctx) { - m_mutex.Lock(); + m_mutex.lock(); m_inst = inst; m_exe_ctx = exe_ctx; } @@ -156,12 +156,12 @@ protected: { m_inst = NULL; m_exe_ctx = NULL; - m_mutex.Unlock(); + m_mutex.unlock(); } const lldb_private::ExecutionContext *m_exe_ctx; InstructionLLVMC *m_inst; - lldb_private::Mutex m_mutex; + std::mutex m_mutex; bool m_data_from_file; std::unique_ptr<LLVMCDisassembler> m_disasm_ap; diff --git a/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp b/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp index 1360edd9fd4..4021b44c96a 100644 --- a/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp +++ b/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp @@ -452,16 +452,16 @@ DynamicLoaderDarwinKernel::CheckForKernelImageAtAddress (lldb::addr_t addr, Proc //---------------------------------------------------------------------- // Constructor //---------------------------------------------------------------------- -DynamicLoaderDarwinKernel::DynamicLoaderDarwinKernel (Process* process, lldb::addr_t kernel_addr) : - DynamicLoader(process), - m_kernel_load_address (kernel_addr), - m_kernel(), - m_kext_summary_header_ptr_addr (), - m_kext_summary_header_addr (), - m_kext_summary_header (), - m_known_kexts (), - m_mutex(Mutex::eMutexTypeRecursive), - m_break_id (LLDB_INVALID_BREAK_ID) +DynamicLoaderDarwinKernel::DynamicLoaderDarwinKernel(Process *process, lldb::addr_t kernel_addr) + : DynamicLoader(process), + m_kernel_load_address(kernel_addr), + m_kernel(), + m_kext_summary_header_ptr_addr(), + m_kext_summary_header_addr(), + m_kext_summary_header(), + m_known_kexts(), + m_mutex(), + m_break_id(LLDB_INVALID_BREAK_ID) { Error error; PlatformSP platform_sp(Platform::Create(PlatformDarwinKernel::GetPluginNameStatic(), error)); @@ -470,7 +470,7 @@ DynamicLoaderDarwinKernel::DynamicLoaderDarwinKernel (Process* process, lldb::ad // shouldn't be done if kext loading is explicitly disabled. if (platform_sp.get() && GetGlobalProperties()->GetLoadKexts()) { - process->GetTarget().SetPlatform (platform_sp); + process->GetTarget().SetPlatform(platform_sp); } } @@ -521,7 +521,7 @@ DynamicLoaderDarwinKernel::DidLaunch () void DynamicLoaderDarwinKernel::Clear (bool clear_process) { - Mutex::Locker locker(m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); if (m_process->IsAlive() && LLDB_BREAK_ID_IS_VALID(m_break_id)) m_process->ClearBreakpointSiteByID(m_break_id); @@ -1131,7 +1131,7 @@ DynamicLoaderDarwinKernel::BreakpointHit (StoppointCallbackContext *context, bool DynamicLoaderDarwinKernel::ReadKextSummaryHeader () { - Mutex::Locker locker(m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); // the all image infos is already valid for this process stop ID @@ -1216,8 +1216,8 @@ DynamicLoaderDarwinKernel::ParseKextSummaries (const Address &kext_summary_addr, Log *log(GetLogIfAnyCategoriesSet (LIBLLDB_LOG_DYNAMIC_LOADER)); if (log) log->Printf ("Kexts-changed breakpoint hit, there are %d kexts currently.\n", count); - - Mutex::Locker locker(m_mutex); + + std::lock_guard<std::recursive_mutex> guard(m_mutex); if (!ReadKextSummaries (kext_summary_addr, count, kext_summaries)) return false; @@ -1438,8 +1438,8 @@ DynamicLoaderDarwinKernel::ReadKextSummaries (const Address &kext_summary_addr, bool DynamicLoaderDarwinKernel::ReadAllKextSummaries () { - Mutex::Locker locker(m_mutex); - + std::lock_guard<std::recursive_mutex> guard(m_mutex); + if (ReadKextSummaryHeader ()) { if (m_kext_summary_header.entry_count > 0 && m_kext_summary_header_addr.IsValid()) @@ -1508,7 +1508,7 @@ DynamicLoaderDarwinKernel::PutToLog(Log *log) const if (log == NULL) return; - Mutex::Locker locker(m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); log->Printf("gLoadedKextSummaries = 0x%16.16" PRIx64 " { version=%u, entry_size=%u, entry_count=%u }", m_kext_summary_header_addr.GetFileAddress(), m_kext_summary_header.version, diff --git a/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.h b/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.h index 5b313bfc910..47fba086a4a 100644 --- a/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.h +++ b/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.h @@ -12,8 +12,9 @@ // C Includes // C++ Includes -#include <vector> +#include <mutex> #include <string> +#include <vector> // Other libraries and framework includes // Project includes @@ -21,7 +22,6 @@ #include "lldb/Host/FileSpec.h" #include "lldb/Host/TimeValue.h" #include "lldb/Core/UUID.h" -#include "lldb/Host/Mutex.h" #include "lldb/Target/Process.h" class DynamicLoaderDarwinKernel : public lldb_private::DynamicLoader @@ -361,7 +361,7 @@ protected: lldb_private::Address m_kext_summary_header_addr; OSKextLoadedKextSummaryHeader m_kext_summary_header; KextImageInfo::collection m_known_kexts; - mutable lldb_private::Mutex m_mutex; + mutable std::recursive_mutex m_mutex; lldb::user_id_t m_break_id; private: diff --git a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp index fba11f6aea8..d12f0ab05d9 100644 --- a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp +++ b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp @@ -138,18 +138,18 @@ DynamicLoaderMacOSXDYLD::CreateInstance (Process* process, bool force) //---------------------------------------------------------------------- // Constructor //---------------------------------------------------------------------- -DynamicLoaderMacOSXDYLD::DynamicLoaderMacOSXDYLD (Process* process) : - DynamicLoader(process), - m_dyld(), - m_dyld_module_wp(), - m_dyld_all_image_infos_addr(LLDB_INVALID_ADDRESS), - m_dyld_all_image_infos(), - m_dyld_all_image_infos_stop_id (UINT32_MAX), - m_break_id(LLDB_INVALID_BREAK_ID), - m_dyld_image_infos(), - m_dyld_image_infos_stop_id (UINT32_MAX), - m_mutex(Mutex::eMutexTypeRecursive), - m_process_image_addr_is_all_images_infos (false) +DynamicLoaderMacOSXDYLD::DynamicLoaderMacOSXDYLD(Process *process) + : DynamicLoader(process), + m_dyld(), + m_dyld_module_wp(), + m_dyld_all_image_infos_addr(LLDB_INVALID_ADDRESS), + m_dyld_all_image_infos(), + m_dyld_all_image_infos_stop_id(UINT32_MAX), + m_break_id(LLDB_INVALID_BREAK_ID), + m_dyld_image_infos(), + m_dyld_image_infos_stop_id(UINT32_MAX), + m_mutex(), + m_process_image_addr_is_all_images_infos(false) { } @@ -244,7 +244,7 @@ DynamicLoaderMacOSXDYLD::ProcessDidExec () void DynamicLoaderMacOSXDYLD::Clear (bool clear_process) { - Mutex::Locker locker(m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); if (LLDB_BREAK_ID_IS_VALID(m_break_id)) m_process->GetTarget().RemoveBreakpointByID (m_break_id); @@ -683,7 +683,7 @@ DynamicLoaderMacOSXDYLD::NotifyBreakpointHit (void *baton, bool DynamicLoaderMacOSXDYLD::ReadAllImageInfosStructure () { - Mutex::Locker locker(m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); // the all image infos is already valid for this process stop ID if (m_process->GetStopID() == m_dyld_all_image_infos_stop_id) @@ -974,8 +974,8 @@ DynamicLoaderMacOSXDYLD::AddModulesUsingImageInfosAddress (lldb::addr_t image_in Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_DYNAMIC_LOADER)); if (log) log->Printf ("Adding %d modules.\n", image_infos_count); - - Mutex::Locker locker(m_mutex); + + std::lock_guard<std::recursive_mutex> guard(m_mutex); if (m_process->GetStopID() == m_dyld_image_infos_stop_id) return true; @@ -1097,8 +1097,8 @@ DynamicLoaderMacOSXDYLD::RemoveModulesUsingImageInfosAddress (lldb::addr_t image { DYLDImageInfo::collection image_infos; Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_DYNAMIC_LOADER)); - - Mutex::Locker locker(m_mutex); + + std::lock_guard<std::recursive_mutex> guard(m_mutex); if (m_process->GetStopID() == m_dyld_image_infos_stop_id) return true; @@ -1239,8 +1239,8 @@ bool DynamicLoaderMacOSXDYLD::InitializeFromAllImageInfos () { Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_DYNAMIC_LOADER)); - - Mutex::Locker locker(m_mutex); + + std::lock_guard<std::recursive_mutex> guard(m_mutex); if (m_process->GetStopID() == m_dyld_image_infos_stop_id || m_dyld_image_infos.size() != 0) return false; @@ -1678,7 +1678,7 @@ DynamicLoaderMacOSXDYLD::PutToLog(Log *log) const if (log == NULL) return; - Mutex::Locker locker(m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); log->Printf("dyld_all_image_infos = { version=%d, count=%d, addr=0x%8.8" PRIx64 ", notify=0x%8.8" PRIx64 " }", m_dyld_all_image_infos.version, m_dyld_all_image_infos.dylib_info_count, diff --git a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.h b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.h index 8fd60d0b6ac..a5bb85fbf66 100644 --- a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.h +++ b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.h @@ -12,6 +12,7 @@ // C Includes // C++ Includes +#include <mutex> #include <vector> // Other libraries and framework includes @@ -20,7 +21,6 @@ #include "lldb/Host/FileSpec.h" #include "lldb/Core/StructuredData.h" #include "lldb/Core/UUID.h" -#include "lldb/Host/Mutex.h" #include "lldb/Target/Process.h" #include "lldb/Utility/SafeMachO.h" @@ -374,7 +374,7 @@ protected: lldb::user_id_t m_break_id; DYLDImageInfo::collection m_dyld_image_infos; // Current shared libraries information uint32_t m_dyld_image_infos_stop_id; // The process stop ID that "m_dyld_image_infos" is valid for - mutable lldb_private::Mutex m_mutex; + mutable std::recursive_mutex m_mutex; lldb_private::Process::Notifications m_notification_callbacks; bool m_process_image_addr_is_all_images_infos; diff --git a/lldb/source/Plugins/DynamicLoader/Static/DynamicLoaderStatic.h b/lldb/source/Plugins/DynamicLoader/Static/DynamicLoaderStatic.h index a7fdf4d2216..67694c96025 100644 --- a/lldb/source/Plugins/DynamicLoader/Static/DynamicLoaderStatic.h +++ b/lldb/source/Plugins/DynamicLoader/Static/DynamicLoaderStatic.h @@ -17,7 +17,6 @@ #include "lldb/Target/DynamicLoader.h" #include "lldb/Host/FileSpec.h" #include "lldb/Core/UUID.h" -#include "lldb/Host/Mutex.h" #include "lldb/Target/Process.h" class DynamicLoaderStatic : public lldb_private::DynamicLoader diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.cpp b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.cpp index 711d324d8aa..5cf99a573d8 100644 --- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.cpp +++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.cpp @@ -499,11 +499,9 @@ ClassDescriptorV2::GetInstanceSize () return 0; } -ClassDescriptorV2::iVarsStorage::iVarsStorage (): -m_filled(false), -m_ivars(), -m_mutex(Mutex::eMutexTypeRecursive) -{} +ClassDescriptorV2::iVarsStorage::iVarsStorage() : m_filled(false), m_ivars(), m_mutex() +{ +} size_t ClassDescriptorV2::iVarsStorage::size () @@ -522,7 +520,7 @@ ClassDescriptorV2::iVarsStorage::fill (AppleObjCRuntimeV2& runtime, ClassDescrip { if (m_filled) return; - Mutex::Locker lock(m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_TYPES | LIBLLDB_LOG_VERBOSE)); if (log) log->Printf("[ClassDescriptorV2::iVarsStorage::fill] class_name = %s", descriptor.GetClassName().AsCString("<unknown")); diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.h b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.h index 18591ecd6e9..f5fc8bc0644 100644 --- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.h +++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.h @@ -12,10 +12,11 @@ // C Includes // C++ Includes +#include <mutex> + // Other libraries and framework includes // Project includes #include "lldb/lldb-private.h" -#include "lldb/Host/Mutex.h" #include "lldb/Target/ObjCLanguageRuntime.h" #include "AppleObjCRuntimeV2.h" @@ -247,7 +248,7 @@ private: private: bool m_filled; std::vector<iVarDescriptor> m_ivars; - Mutex m_mutex; + std::recursive_mutex m_mutex; }; // The constructor should only be invoked by the runtime as it builds its caches diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp index 0f79427559b..55516341889 100644 --- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp +++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp @@ -379,27 +379,27 @@ ExtractRuntimeGlobalSymbol (Process* process, } } -AppleObjCRuntimeV2::AppleObjCRuntimeV2 (Process *process, - const ModuleSP &objc_module_sp) : - AppleObjCRuntime (process), - m_get_class_info_code(), - m_get_class_info_args (LLDB_INVALID_ADDRESS), - m_get_class_info_args_mutex (Mutex::eMutexTypeNormal), - m_get_shared_cache_class_info_code(), - m_get_shared_cache_class_info_args (LLDB_INVALID_ADDRESS), - m_get_shared_cache_class_info_args_mutex (Mutex::eMutexTypeNormal), - m_decl_vendor_ap (), - m_isa_hash_table_ptr (LLDB_INVALID_ADDRESS), - m_hash_signature (), - m_has_object_getClass (false), - m_loaded_objc_opt (false), - m_non_pointer_isa_cache_ap(NonPointerISACache::CreateInstance(*this,objc_module_sp)), - m_tagged_pointer_vendor_ap(TaggedPointerVendorV2::CreateInstance(*this,objc_module_sp)), - m_encoding_to_type_sp(), - m_noclasses_warning_emitted(false) +AppleObjCRuntimeV2::AppleObjCRuntimeV2(Process *process, const ModuleSP &objc_module_sp) + : AppleObjCRuntime(process), + m_get_class_info_code(), + m_get_class_info_args(LLDB_INVALID_ADDRESS), + m_get_class_info_args_mutex(), + m_get_shared_cache_class_info_code(), + m_get_shared_cache_class_info_args(LLDB_INVALID_ADDRESS), + m_get_shared_cache_class_info_args_mutex(), + m_decl_vendor_ap(), + m_isa_hash_table_ptr(LLDB_INVALID_ADDRESS), + m_hash_signature(), + m_has_object_getClass(false), + m_loaded_objc_opt(false), + m_non_pointer_isa_cache_ap(NonPointerISACache::CreateInstance(*this, objc_module_sp)), + m_tagged_pointer_vendor_ap(TaggedPointerVendorV2::CreateInstance(*this, objc_module_sp)), + m_encoding_to_type_sp(), + m_noclasses_warning_emitted(false) { static const ConstString g_gdb_object_getClass("gdb_object_getClass"); - m_has_object_getClass = (objc_module_sp->FindFirstSymbolWithNameAndType(g_gdb_object_getClass, eSymbolTypeCode) != NULL); + m_has_object_getClass = + (objc_module_sp->FindFirstSymbolWithNameAndType(g_gdb_object_getClass, eSymbolTypeCode) != NULL); } bool @@ -1483,8 +1483,8 @@ AppleObjCRuntimeV2::UpdateISAToDescriptorMapDynamic(RemoteNXMapTable &hash_table if (class_infos_addr == LLDB_INVALID_ADDRESS) return false; - - Mutex::Locker locker(m_get_class_info_args_mutex); + + std::lock_guard<std::mutex> guard(m_get_class_info_args_mutex); // Fill in our function argument values arguments.GetValueAtIndex(0)->GetScalar() = hash_table.GetTableLoadAddress(); @@ -1735,9 +1735,9 @@ AppleObjCRuntimeV2::UpdateISAToDescriptorMapSharedCache() if (class_infos_addr == LLDB_INVALID_ADDRESS) return DescriptorMapUpdateResult::Fail(); - - Mutex::Locker locker(m_get_shared_cache_class_info_args_mutex); - + + std::lock_guard<std::mutex> guard(m_get_shared_cache_class_info_args_mutex); + // Fill in our function argument values arguments.GetValueAtIndex(0)->GetScalar() = objc_opt_ptr; arguments.GetValueAtIndex(1)->GetScalar() = class_infos_addr; diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h index 8b4ca8f4e9b..4b27c740048 100644 --- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h +++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h @@ -14,6 +14,7 @@ // C++ Includes #include <map> #include <memory> +#include <mutex> // Other libraries and framework includes // Project includes @@ -353,11 +354,11 @@ private: std::unique_ptr<UtilityFunction> m_get_class_info_code; lldb::addr_t m_get_class_info_args; - Mutex m_get_class_info_args_mutex; + std::mutex m_get_class_info_args_mutex; std::unique_ptr<UtilityFunction> m_get_shared_cache_class_info_code; lldb::addr_t m_get_shared_cache_class_info_args; - Mutex m_get_shared_cache_class_info_args_mutex; + std::mutex m_get_shared_cache_class_info_args_mutex; std::unique_ptr<DeclVendor> m_decl_vendor_ap; lldb::addr_t m_isa_hash_table_ptr; diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp index 614c267d0be..56aa36ecb0d 100644 --- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp +++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp @@ -751,8 +751,8 @@ AppleObjCTrampolineHandler::SetupDispatchFunction(Thread &thread, ValueList &dis // Scope for mutex locker: { - Mutex::Locker locker(m_impl_function_mutex); - + std::lock_guard<std::mutex> guard(m_impl_function_mutex); + // First stage is to make the ClangUtility to hold our injected function: if (!m_impl_code.get()) diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.h b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.h index 42d3461ddfa..b11beea9197 100644 --- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.h +++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.h @@ -13,12 +13,12 @@ // C Includes // C++ Includes #include <map> +#include <mutex> #include <vector> // Other libraries and framework includes // Project includes #include "lldb/lldb-public.h" -#include "lldb/Host/Mutex.h" #include "lldb/Expression/UtilityFunction.h" namespace lldb_private @@ -196,7 +196,7 @@ private: lldb::ProcessWP m_process_wp; lldb::ModuleSP m_objc_module_sp; std::unique_ptr<UtilityFunction> m_impl_code; - Mutex m_impl_function_mutex; + std::mutex m_impl_function_mutex; lldb::addr_t m_impl_fn_addr; lldb::addr_t m_impl_stret_fn_addr; lldb::addr_t m_msg_forward_addr; diff --git a/lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp b/lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp index f2a74b05fe2..984a9ece12e 100644 --- a/lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp +++ b/lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp @@ -35,7 +35,6 @@ typedef struct ar_hdr #include "lldb/Core/PluginManager.h" #include "lldb/Core/Stream.h" #include "lldb/Core/Timer.h" -#include "lldb/Host/Mutex.h" #include "lldb/Symbol/ObjectFile.h" using namespace lldb; @@ -226,7 +225,7 @@ ObjectContainerBSDArchive::Archive::FindObject (const ConstString &object_name, ObjectContainerBSDArchive::Archive::shared_ptr ObjectContainerBSDArchive::Archive::FindCachedArchive (const FileSpec &file, const ArchSpec &arch, const TimeValue &time, lldb::offset_t file_offset) { - Mutex::Locker locker(Archive::GetArchiveCacheMutex ()); + std::lock_guard<std::recursive_mutex> guard(Archive::GetArchiveCacheMutex()); shared_ptr archive_sp; Archive::Map &archive_map = Archive::GetArchiveCache (); Archive::Map::iterator pos = archive_map.find (file); @@ -281,7 +280,7 @@ ObjectContainerBSDArchive::Archive::ParseAndCacheArchiveForFile const size_t num_objects = archive_sp->ParseObjects (); if (num_objects > 0) { - Mutex::Locker locker(Archive::GetArchiveCacheMutex ()); + std::lock_guard<std::recursive_mutex> guard(Archive::GetArchiveCacheMutex()); Archive::GetArchiveCache().insert(std::make_pair(file, archive_sp)); } else @@ -299,14 +298,13 @@ ObjectContainerBSDArchive::Archive::GetArchiveCache () return g_archive_map; } -Mutex & -ObjectContainerBSDArchive::Archive::GetArchiveCacheMutex () +std::recursive_mutex & +ObjectContainerBSDArchive::Archive::GetArchiveCacheMutex() { - static Mutex g_archive_map_mutex (Mutex::eMutexTypeRecursive); + static std::recursive_mutex g_archive_map_mutex; return g_archive_map_mutex; } - void ObjectContainerBSDArchive::Initialize() { diff --git a/lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.h b/lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.h index cbb3848dc7c..03b0bf3e2f0 100644 --- a/lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.h +++ b/lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.h @@ -12,6 +12,8 @@ // C Includes // C++ Includes +#include <mutex> + // Other libraries and framework includes // Project includes #include "lldb/Symbol/ObjectContainer.h" @@ -138,8 +140,8 @@ protected: static Map & GetArchiveCache (); - static lldb_private::Mutex & - GetArchiveCacheMutex (); + static std::recursive_mutex & + GetArchiveCacheMutex(); static Archive::shared_ptr FindCachedArchive (const lldb_private::FileSpec &file, diff --git a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp index fe299b17f59..7f963c9f3f9 100644 --- a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp +++ b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp @@ -2938,7 +2938,7 @@ ObjectFileELF::GetSymtab() return NULL; uint64_t symbol_id = 0; - lldb_private::Mutex::Locker locker(module_sp->GetMutex()); + std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); // Sharable objects and dynamic executables usually have 2 distinct symbol // tables, one named ".symtab", and the other ".dynsym". The dynsym is a smaller @@ -3102,7 +3102,7 @@ ObjectFileELF::Dump(Stream *s) return; } - lldb_private::Mutex::Locker locker(module_sp->GetMutex()); + std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); s->Printf("%p: ", static_cast<void *>(this)); s->Indent(); s->PutCString("ObjectFileELF"); diff --git a/lldb/source/Plugins/ObjectFile/JIT/ObjectFileJIT.cpp b/lldb/source/Plugins/ObjectFile/JIT/ObjectFileJIT.cpp index 3103ed8fb8f..7b1627ddd73 100644 --- a/lldb/source/Plugins/ObjectFile/JIT/ObjectFileJIT.cpp +++ b/lldb/source/Plugins/ObjectFile/JIT/ObjectFileJIT.cpp @@ -158,7 +158,7 @@ ObjectFileJIT::GetSymtab() ModuleSP module_sp(GetModule()); if (module_sp) { - lldb_private::Mutex::Locker locker(module_sp->GetMutex()); + std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); if (m_symtab_ap.get() == NULL) { m_symtab_ap.reset(new Symtab(this)); @@ -200,7 +200,7 @@ ObjectFileJIT::Dump (Stream *s) ModuleSP module_sp(GetModule()); if (module_sp) { - lldb_private::Mutex::Locker locker(module_sp->GetMutex()); + std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); s->Printf("%p: ", static_cast<void*>(this)); s->Indent(); s->PutCString("ObjectFileJIT"); diff --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp index 09fc922fc72..6a105195c5a 100644 --- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp +++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp @@ -1217,7 +1217,7 @@ ObjectFileMachO::ParseHeader () ModuleSP module_sp(GetModule()); if (module_sp) { - lldb_private::Mutex::Locker locker(module_sp->GetMutex()); + std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); bool can_parse = false; lldb::offset_t offset = 0; m_data.SetByteOrder (endian::InlHostByteOrder()); @@ -1457,7 +1457,7 @@ ObjectFileMachO::GetSymtab() ModuleSP module_sp(GetModule()); if (module_sp) { - lldb_private::Mutex::Locker locker(module_sp->GetMutex()); + std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); if (m_symtab_ap.get() == NULL) { m_symtab_ap.reset(new Symtab(this)); @@ -4755,7 +4755,7 @@ ObjectFileMachO::Dump (Stream *s) ModuleSP module_sp(GetModule()); if (module_sp) { - lldb_private::Mutex::Locker locker(module_sp->GetMutex()); + std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); s->Printf("%p: ", static_cast<void*>(this)); s->Indent(); if (m_header.magic == MH_MAGIC_64 || m_header.magic == MH_CIGAM_64) @@ -4911,7 +4911,7 @@ ObjectFileMachO::GetUUID (lldb_private::UUID* uuid) ModuleSP module_sp(GetModule()); if (module_sp) { - lldb_private::Mutex::Locker locker(module_sp->GetMutex()); + std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); lldb::offset_t offset = MachHeaderSizeFromMagic(m_header.magic); return GetUUID (m_header, m_data, offset, *uuid); } @@ -4925,7 +4925,7 @@ ObjectFileMachO::GetDependentModules (FileSpecList& files) ModuleSP module_sp(GetModule()); if (module_sp) { - lldb_private::Mutex::Locker locker(module_sp->GetMutex()); + std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); struct load_command load_cmd; lldb::offset_t offset = MachHeaderSizeFromMagic(m_header.magic); std::vector<std::string> rpath_paths; @@ -5053,7 +5053,7 @@ ObjectFileMachO::GetEntryPointAddress () ModuleSP module_sp(GetModule()); if (module_sp) { - lldb_private::Mutex::Locker locker(module_sp->GetMutex()); + std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); struct load_command load_cmd; lldb::offset_t offset = MachHeaderSizeFromMagic(m_header.magic); uint32_t i; @@ -5203,7 +5203,7 @@ ObjectFileMachO::GetNumThreadContexts () ModuleSP module_sp(GetModule()); if (module_sp) { - lldb_private::Mutex::Locker locker(module_sp->GetMutex()); + std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); if (!m_thread_context_offsets_valid) { m_thread_context_offsets_valid = true; @@ -5237,7 +5237,7 @@ ObjectFileMachO::GetThreadContextAtIndex (uint32_t idx, lldb_private::Thread &th ModuleSP module_sp(GetModule()); if (module_sp) { - lldb_private::Mutex::Locker locker(module_sp->GetMutex()); + std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); if (!m_thread_context_offsets_valid) GetNumThreadContexts (); @@ -5373,7 +5373,7 @@ ObjectFileMachO::GetVersion (uint32_t *versions, uint32_t num_versions) ModuleSP module_sp(GetModule()); if (module_sp) { - lldb_private::Mutex::Locker locker(module_sp->GetMutex()); + std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); struct dylib_command load_cmd; lldb::offset_t offset = MachHeaderSizeFromMagic(m_header.magic); uint32_t version_cmd = 0; @@ -5428,7 +5428,7 @@ ObjectFileMachO::GetArchitecture (ArchSpec &arch) ModuleSP module_sp(GetModule()); if (module_sp) { - lldb_private::Mutex::Locker locker(module_sp->GetMutex()); + std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); return GetArchitecture (m_header, m_data, MachHeaderSizeFromMagic(m_header.magic), arch); } return false; diff --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h index 9f7cb3e40dd..251a0865e78 100644 --- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h +++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h @@ -19,7 +19,6 @@ #include "lldb/Core/FileSpecList.h" #include "lldb/Core/RangeMap.h" #include "lldb/Host/FileSpec.h" -#include "lldb/Host/Mutex.h" #include "lldb/Symbol/ObjectFile.h" //---------------------------------------------------------------------- diff --git a/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp b/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp index 48b9f8816a3..8e942f5bdb9 100644 --- a/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp +++ b/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp @@ -212,7 +212,7 @@ ObjectFilePECOFF::ParseHeader () ModuleSP module_sp(GetModule()); if (module_sp) { - lldb_private::Mutex::Locker locker(module_sp->GetMutex()); + std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); m_sect_headers.clear(); m_data.SetByteOrder (eByteOrderLittle); lldb::offset_t offset = 0; @@ -534,7 +534,7 @@ ObjectFilePECOFF::GetSymtab() ModuleSP module_sp(GetModule()); if (module_sp) { - lldb_private::Mutex::Locker locker(module_sp->GetMutex()); + std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); if (m_symtab_ap.get() == NULL) { SectionList *sect_list = GetSectionList(); @@ -689,7 +689,7 @@ ObjectFilePECOFF::CreateSections (SectionList &unified_section_list) ModuleSP module_sp(GetModule()); if (module_sp) { - lldb_private::Mutex::Locker locker(module_sp->GetMutex()); + std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); const uint32_t nsects = m_sect_headers.size(); ModuleSP module_sp (GetModule()); for (uint32_t idx = 0; idx<nsects; ++idx) @@ -847,7 +847,7 @@ ObjectFilePECOFF::Dump(Stream *s) ModuleSP module_sp(GetModule()); if (module_sp) { - lldb_private::Mutex::Locker locker(module_sp->GetMutex()); + std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); s->Printf("%p: ", static_cast<void*>(this)); s->Indent(); s->PutCString("ObjectFilePECOFF"); diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.cpp index eea2844d564..a5f165e1f92 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.cpp +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.cpp @@ -252,7 +252,7 @@ FileSpec PlatformAppleSimulator::GetCoreSimulatorPath() { #if defined(__APPLE__) - Mutex::Locker locker (m_mutex); + std::lock_guard<std::mutex> guard(m_mutex); if (!m_core_simulator_framework_path.hasValue()) { const char *developer_dir = GetDeveloperDirectory(); diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformAppleTVSimulator.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformAppleTVSimulator.cpp index f537934a917..097d58dcfbc 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformAppleTVSimulator.cpp +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformAppleTVSimulator.cpp @@ -304,7 +304,7 @@ EnumerateDirectoryCallback (void *baton, FileSpec::FileType file_type, const Fil const char * PlatformAppleTVSimulator::GetSDKDirectoryAsCString() { - Mutex::Locker locker (m_mutex); + std::lock_guard<std::mutex> guard(m_mutex); if (m_sdk_directory.empty()) { const char *developer_dir = GetDeveloperDirectory(); diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformAppleWatchSimulator.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformAppleWatchSimulator.cpp index ea8e789b292..46e5970bc08 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformAppleWatchSimulator.cpp +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformAppleWatchSimulator.cpp @@ -304,7 +304,7 @@ EnumerateDirectoryCallback (void *baton, FileSpec::FileType file_type, const Fil const char * PlatformAppleWatchSimulator::GetSDKDirectoryAsCString() { - Mutex::Locker locker (m_mutex); + std::lock_guard<std::mutex> guard(m_mutex); if (m_sdk_directory.empty()) { const char *developer_dir = GetDeveloperDirectory(); diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp index 905cd6229bf..62ada5a70a5 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp @@ -1015,7 +1015,7 @@ PlatformDarwin::ARMGetSupportedArchitectureAtIndex (uint32_t idx, ArchSpec &arch const char * PlatformDarwin::GetDeveloperDirectory() { - Mutex::Locker locker (m_mutex); + std::lock_guard<std::mutex> guard(m_mutex); if (m_developer_directory.empty()) { bool developer_dir_path_valid = false; @@ -1572,10 +1572,10 @@ PlatformDarwin::AddClangModuleCompilationOptionsForSDKType (Target *target, std: FileSpec sysroot_spec; // Scope for mutex locker below { - Mutex::Locker locker (m_mutex); + std::lock_guard<std::mutex> guard(m_mutex); sysroot_spec = GetSDKDirectoryForModules(sdk_type); } - + if (sysroot_spec.IsDirectory()) { options.push_back("-isysroot"); diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.cpp index cbe9c7949a4..99b9324417b 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.cpp +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.cpp @@ -308,7 +308,7 @@ EnumerateDirectoryCallback (void *baton, FileSpec::FileType file_type, const Fil const char * PlatformiOSSimulator::GetSDKDirectoryAsCString() { - Mutex::Locker locker (m_mutex); + std::lock_guard<std::mutex> guard(m_mutex); if (m_sdk_directory.empty()) { const char *developer_dir = GetDeveloperDirectory(); diff --git a/lldb/source/Plugins/Process/FreeBSD/ProcessFreeBSD.cpp b/lldb/source/Plugins/Process/FreeBSD/ProcessFreeBSD.cpp index 69b527a513f..debad980a31 100644 --- a/lldb/source/Plugins/Process/FreeBSD/ProcessFreeBSD.cpp +++ b/lldb/source/Plugins/Process/FreeBSD/ProcessFreeBSD.cpp @@ -229,7 +229,7 @@ ProcessFreeBSD::WillResume() void ProcessFreeBSD::SendMessage(const ProcessMessage &message) { - Mutex::Locker lock(m_message_mutex); + std::lock_guard<std::recursive_mutex> guard(m_message_mutex); switch (message.GetKind()) { @@ -274,7 +274,7 @@ ProcessFreeBSD::ProcessFreeBSD(lldb::TargetSP target_sp, lldb::ListenerSP listen m_byte_order(endian::InlHostByteOrder()), m_monitor(NULL), m_module(NULL), - m_message_mutex (Mutex::eMutexTypeRecursive), + m_message_mutex(), m_exit_now(false), m_seen_initial_stop(), m_resume_signo(0) @@ -603,7 +603,7 @@ ProcessFreeBSD::RefreshStateAfterStop() if (log && log->GetMask().Test(POSIX_LOG_VERBOSE)) log->Printf ("ProcessFreeBSD::%s(), message_queue size = %d", __FUNCTION__, (int)m_message_queue.size()); - Mutex::Locker lock(m_message_mutex); + std::lock_guard<std::recursive_mutex> guard(m_message_mutex); // This method used to only handle one message. Changing it to loop allows // it to handle the case where we hit a breakpoint while handling a different diff --git a/lldb/source/Plugins/Process/FreeBSD/ProcessFreeBSD.h b/lldb/source/Plugins/Process/FreeBSD/ProcessFreeBSD.h index a1d255c34cb..888e2a90ad7 100644 --- a/lldb/source/Plugins/Process/FreeBSD/ProcessFreeBSD.h +++ b/lldb/source/Plugins/Process/FreeBSD/ProcessFreeBSD.h @@ -13,8 +13,9 @@ // C Includes // C++ Includes -#include <set> +#include <mutex> #include <queue> +#include <set> // Other libraries and framework includes #include "lldb/Target/Process.h" @@ -212,7 +213,7 @@ protected: lldb_private::Module *m_module; /// Message queue notifying this instance of inferior process state changes. - lldb_private::Mutex m_message_mutex; + std::recursive_mutex m_message_mutex; std::queue<ProcessMessage> m_message_queue; /// Drive any exit events to completion. diff --git a/lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp b/lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp index 2318a657578..16707a5c8b9 100644 --- a/lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp +++ b/lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp @@ -1348,7 +1348,7 @@ ProcessMonitor::ServeOperation(OperationArgs *args) void ProcessMonitor::DoOperation(Operation *op) { - Mutex::Locker lock(m_operation_mutex); + std::lock_guard<std::mutex> guard(m_operation_mutex); m_operation = op; diff --git a/lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.h b/lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.h index 27cdd3e7000..93f6be11136 100644 --- a/lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.h +++ b/lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.h @@ -15,11 +15,12 @@ #include <signal.h> // C++ Includes +#include <mutex> + // Other libraries and framework includes #include "lldb/lldb-types.h" #include "lldb/Host/FileSpec.h" #include "lldb/Host/HostThread.h" -#include "lldb/Host/Mutex.h" namespace lldb_private { @@ -223,7 +224,7 @@ private: // current operation which must be executed on the privileged thread Operation *m_operation; - lldb_private::Mutex m_operation_mutex; + std::mutex m_operation_mutex; // semaphores notified when Operation is ready to be processed and when // the operation is complete. diff --git a/lldb/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.cpp b/lldb/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.cpp index 2cbd94a2f96..813c810bff9 100644 --- a/lldb/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.cpp +++ b/lldb/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.cpp @@ -284,8 +284,8 @@ bool CommunicationKDP::CheckForPacket (const uint8_t *src, size_t src_len, DataExtractor &packet) { // Put the packet data into the buffer in a thread safe fashion - Mutex::Locker locker(m_bytes_mutex); - + std::lock_guard<std::recursive_mutex> guard(m_bytes_mutex); + Log *log (ProcessKDPLog::GetLogIfAllCategoriesSet (KDP_LOG_PACKETS)); if (src && src_len > 0) diff --git a/lldb/source/Plugins/Process/Utility/HistoryThread.cpp b/lldb/source/Plugins/Process/Utility/HistoryThread.cpp index 206b8290c5f..20a10106c2a 100644 --- a/lldb/source/Plugins/Process/Utility/HistoryThread.cpp +++ b/lldb/source/Plugins/Process/Utility/HistoryThread.cpp @@ -22,28 +22,24 @@ using namespace lldb_private; // Constructor -HistoryThread::HistoryThread (lldb_private::Process &process, - lldb::tid_t tid, - std::vector<lldb::addr_t> pcs, - uint32_t stop_id, - bool stop_id_is_valid) : - Thread (process, tid, true), - m_framelist_mutex(), - m_framelist(), - m_pcs (pcs), - m_stop_id (stop_id), - m_stop_id_is_valid (stop_id_is_valid), - m_extended_unwind_token (LLDB_INVALID_ADDRESS), - m_queue_name (), - m_thread_name (), - m_originating_unique_thread_id (tid), - m_queue_id (LLDB_INVALID_QUEUE_ID) +HistoryThread::HistoryThread(lldb_private::Process &process, lldb::tid_t tid, std::vector<lldb::addr_t> pcs, + uint32_t stop_id, bool stop_id_is_valid) + : Thread(process, tid, true), + m_framelist_mutex(), + m_framelist(), + m_pcs(pcs), + m_stop_id(stop_id), + m_stop_id_is_valid(stop_id_is_valid), + m_extended_unwind_token(LLDB_INVALID_ADDRESS), + m_queue_name(), + m_thread_name(), + m_originating_unique_thread_id(tid), + m_queue_id(LLDB_INVALID_QUEUE_ID) { - m_unwinder_ap.reset (new HistoryUnwind (*this, pcs, stop_id_is_valid)); - Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT)); + m_unwinder_ap.reset(new HistoryUnwind(*this, pcs, stop_id_is_valid)); + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_OBJECT)); if (log) - log->Printf ("%p HistoryThread::HistoryThread", - static_cast<void*>(this)); + log->Printf("%p HistoryThread::HistoryThread", static_cast<void *>(this)); } // Destructor @@ -78,7 +74,9 @@ HistoryThread::CreateRegisterContextForFrame (StackFrame *frame) lldb::StackFrameListSP HistoryThread::GetStackFrameList () { - Mutex::Locker (m_framelist_mutex); // FIXME do not throw away the lock after we acquire it.. + // FIXME do not throw away the lock after we acquire it.. + std::unique_lock<std::mutex> lock(m_framelist_mutex); + lock.release(); if (m_framelist.get() == NULL) { m_framelist.reset (new StackFrameList (*this, StackFrameListSP(), true)); diff --git a/lldb/source/Plugins/Process/Utility/HistoryThread.h b/lldb/source/Plugins/Process/Utility/HistoryThread.h index e87f6496134..43ac13c2d8b 100644 --- a/lldb/source/Plugins/Process/Utility/HistoryThread.h +++ b/lldb/source/Plugins/Process/Utility/HistoryThread.h @@ -12,10 +12,11 @@ // C Includes // C++ Includes +#include <mutex> + // Other libraries and framework includes // Project includes #include "lldb/lldb-private.h" -#include "lldb/Host/Mutex.h" #include "lldb/Core/Broadcaster.h" #include "lldb/Core/Event.h" #include "lldb/Core/UserID.h" @@ -125,7 +126,7 @@ protected: virtual lldb::StackFrameListSP GetStackFrameList (); - mutable Mutex m_framelist_mutex; + mutable std::mutex m_framelist_mutex; lldb::StackFrameListSP m_framelist; std::vector<lldb::addr_t> m_pcs; uint32_t m_stop_id; diff --git a/lldb/source/Plugins/Process/Utility/HistoryUnwind.cpp b/lldb/source/Plugins/Process/Utility/HistoryUnwind.cpp index 14afcbee0b4..62e4bc0a347 100644 --- a/lldb/source/Plugins/Process/Utility/HistoryUnwind.cpp +++ b/lldb/source/Plugins/Process/Utility/HistoryUnwind.cpp @@ -40,7 +40,7 @@ HistoryUnwind::~HistoryUnwind () void HistoryUnwind::DoClear () { - Mutex::Locker locker(m_unwind_mutex); + std::lock_guard<std::recursive_mutex> guard(m_unwind_mutex); m_pcs.clear(); m_stop_id_is_valid = false; } @@ -64,7 +64,9 @@ HistoryUnwind::DoCreateRegisterContextForFrame (StackFrame *frame) bool HistoryUnwind::DoGetFrameInfoAtIndex (uint32_t frame_idx, lldb::addr_t& cfa, lldb::addr_t& pc) { - Mutex::Locker (m_unwind_mutex); // FIXME do not throw away the lock after we acquire it.. + // FIXME do not throw away the lock after we acquire it.. + std::unique_lock<std::recursive_mutex> guard(m_unwind_mutex); + guard.release(); if (frame_idx < m_pcs.size()) { cfa = frame_idx; diff --git a/lldb/source/Plugins/Process/Utility/HistoryUnwind.h b/lldb/source/Plugins/Process/Utility/HistoryUnwind.h index 2cb78bc1dc6..890604fcb68 100644 --- a/lldb/source/Plugins/Process/Utility/HistoryUnwind.h +++ b/lldb/source/Plugins/Process/Utility/HistoryUnwind.h @@ -17,7 +17,6 @@ // Other libraries and framework includes // Project includes #include "lldb/lldb-private.h" -#include "lldb/Host/Mutex.h" #include "lldb/Target/Unwind.h" namespace lldb_private { diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp index 891cc22fec7..4689e0bc299 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp @@ -793,8 +793,8 @@ GDBRemoteCommunication::PacketType GDBRemoteCommunication::CheckForPacket (const uint8_t *src, size_t src_len, StringExtractorGDBRemote &packet) { // Put the packet data into the buffer in a thread safe fashion - Mutex::Locker locker(m_bytes_mutex); - + std::lock_guard<std::recursive_mutex> guard(m_bytes_mutex); + Log *log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PACKETS)); if (src && src_len > 0) diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp index 1a109307b88..5f2678d24cf 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp @@ -55,79 +55,79 @@ using namespace lldb_private::process_gdb_remote; //---------------------------------------------------------------------- // GDBRemoteCommunicationClient constructor //---------------------------------------------------------------------- -GDBRemoteCommunicationClient::GDBRemoteCommunicationClient() : - GDBRemoteCommunication("gdb-remote.client", "gdb-remote.client.rx_packet"), - m_supports_not_sending_acks (eLazyBoolCalculate), - m_supports_thread_suffix (eLazyBoolCalculate), - m_supports_threads_in_stop_reply (eLazyBoolCalculate), - m_supports_vCont_all (eLazyBoolCalculate), - m_supports_vCont_any (eLazyBoolCalculate), - m_supports_vCont_c (eLazyBoolCalculate), - m_supports_vCont_C (eLazyBoolCalculate), - m_supports_vCont_s (eLazyBoolCalculate), - m_supports_vCont_S (eLazyBoolCalculate), - m_qHostInfo_is_valid (eLazyBoolCalculate), - m_curr_pid_is_valid (eLazyBoolCalculate), - m_qProcessInfo_is_valid (eLazyBoolCalculate), - m_qGDBServerVersion_is_valid (eLazyBoolCalculate), - m_supports_alloc_dealloc_memory (eLazyBoolCalculate), - m_supports_memory_region_info (eLazyBoolCalculate), - m_supports_watchpoint_support_info (eLazyBoolCalculate), - m_supports_detach_stay_stopped (eLazyBoolCalculate), - m_watchpoints_trigger_after_instruction(eLazyBoolCalculate), - m_attach_or_wait_reply(eLazyBoolCalculate), - m_prepare_for_reg_writing_reply (eLazyBoolCalculate), - m_supports_p (eLazyBoolCalculate), - m_supports_x (eLazyBoolCalculate), - m_avoid_g_packets (eLazyBoolCalculate), - m_supports_QSaveRegisterState (eLazyBoolCalculate), - m_supports_qXfer_auxv_read (eLazyBoolCalculate), - m_supports_qXfer_libraries_read (eLazyBoolCalculate), - m_supports_qXfer_libraries_svr4_read (eLazyBoolCalculate), - m_supports_qXfer_features_read (eLazyBoolCalculate), - m_supports_augmented_libraries_svr4_read (eLazyBoolCalculate), - m_supports_jThreadExtendedInfo (eLazyBoolCalculate), - m_supports_jLoadedDynamicLibrariesInfos (eLazyBoolCalculate), - m_supports_qProcessInfoPID (true), - m_supports_qfProcessInfo (true), - m_supports_qUserName (true), - m_supports_qGroupName (true), - m_supports_qThreadStopInfo (true), - m_supports_z0 (true), - m_supports_z1 (true), - m_supports_z2 (true), - m_supports_z3 (true), - m_supports_z4 (true), - m_supports_QEnvironment (true), - m_supports_QEnvironmentHexEncoded (true), - m_supports_qSymbol (true), - m_qSymbol_requests_done (false), - m_supports_qModuleInfo (true), - m_supports_jThreadsInfo (true), - m_curr_pid (LLDB_INVALID_PROCESS_ID), - m_curr_tid (LLDB_INVALID_THREAD_ID), - m_curr_tid_run (LLDB_INVALID_THREAD_ID), - m_num_supported_hardware_watchpoints (0), - m_async_mutex (Mutex::eMutexTypeRecursive), - m_async_packet_predicate (false), - m_async_packet (), - m_async_result (PacketResult::Success), - m_async_response (), - m_async_signal (-1), - m_interrupt_sent (false), - m_thread_id_to_used_usec_map (), - m_host_arch(), - m_process_arch(), - m_os_version_major (UINT32_MAX), - m_os_version_minor (UINT32_MAX), - m_os_version_update (UINT32_MAX), - m_os_build (), - m_os_kernel (), - m_hostname (), - m_gdb_server_name(), - m_gdb_server_version(UINT32_MAX), - m_default_packet_timeout (0), - m_max_packet_size (0) +GDBRemoteCommunicationClient::GDBRemoteCommunicationClient() + : GDBRemoteCommunication("gdb-remote.client", "gdb-remote.client.rx_packet"), + m_supports_not_sending_acks(eLazyBoolCalculate), + m_supports_thread_suffix(eLazyBoolCalculate), + m_supports_threads_in_stop_reply(eLazyBoolCalculate), + m_supports_vCont_all(eLazyBoolCalculate), + m_supports_vCont_any(eLazyBoolCalculate), + m_supports_vCont_c(eLazyBoolCalculate), + m_supports_vCont_C(eLazyBoolCalculate), + m_supports_vCont_s(eLazyBoolCalculate), + m_supports_vCont_S(eLazyBoolCalculate), + m_qHostInfo_is_valid(eLazyBoolCalculate), + m_curr_pid_is_valid(eLazyBoolCalculate), + m_qProcessInfo_is_valid(eLazyBoolCalculate), + m_qGDBServerVersion_is_valid(eLazyBoolCalculate), + m_supports_alloc_dealloc_memory(eLazyBoolCalculate), + m_supports_memory_region_info(eLazyBoolCalculate), + m_supports_watchpoint_support_info(eLazyBoolCalculate), + m_supports_detach_stay_stopped(eLazyBoolCalculate), + m_watchpoints_trigger_after_instruction(eLazyBoolCalculate), + m_attach_or_wait_reply(eLazyBoolCalculate), + m_prepare_for_reg_writing_reply(eLazyBoolCalculate), + m_supports_p(eLazyBoolCalculate), + m_supports_x(eLazyBoolCalculate), + m_avoid_g_packets(eLazyBoolCalculate), + m_supports_QSaveRegisterState(eLazyBoolCalculate), + m_supports_qXfer_auxv_read(eLazyBoolCalculate), + m_supports_qXfer_libraries_read(eLazyBoolCalculate), + m_supports_qXfer_libraries_svr4_read(eLazyBoolCalculate), + m_supports_qXfer_features_read(eLazyBoolCalculate), + m_supports_augmented_libraries_svr4_read(eLazyBoolCalculate), + m_supports_jThreadExtendedInfo(eLazyBoolCalculate), + m_supports_jLoadedDynamicLibrariesInfos(eLazyBoolCalculate), + m_supports_qProcessInfoPID(true), + m_supports_qfProcessInfo(true), + m_supports_qUserName(true), + m_supports_qGroupName(true), + m_supports_qThreadStopInfo(true), + m_supports_z0(true), + m_supports_z1(true), + m_supports_z2(true), + m_supports_z3(true), + m_supports_z4(true), + m_supports_QEnvironment(true), + m_supports_QEnvironmentHexEncoded(true), + m_supports_qSymbol(true), + m_qSymbol_requests_done(false), + m_supports_qModuleInfo(true), + m_supports_jThreadsInfo(true), + m_curr_pid(LLDB_INVALID_PROCESS_ID), + m_curr_tid(LLDB_INVALID_THREAD_ID), + m_curr_tid_run(LLDB_INVALID_THREAD_ID), + m_num_supported_hardware_watchpoints(0), + m_async_mutex(), + m_async_packet_predicate(false), + m_async_packet(), + m_async_result(PacketResult::Success), + m_async_response(), + m_async_signal(-1), + m_interrupt_sent(false), + m_thread_id_to_used_usec_map(), + m_host_arch(), + m_process_arch(), + m_os_version_major(UINT32_MAX), + m_os_version_minor(UINT32_MAX), + m_os_version_update(UINT32_MAX), + m_os_build(), + m_os_kernel(), + m_hostname(), + m_gdb_server_name(), + m_gdb_server_version(UINT32_MAX), + m_default_packet_timeout(0), + m_max_packet_size(0) { } @@ -820,7 +820,7 @@ GDBRemoteCommunicationClient::SendPacketAndWaitForResponse { if (IsRunning()) { - Mutex::Locker async_locker (m_async_mutex); + std::lock_guard<std::recursive_mutex> guard(m_async_mutex); m_async_packet.assign(payload, payload_length); m_async_response.CopyResponseValidator(response); m_async_packet_predicate.SetValue (true, eBroadcastNever); @@ -1372,7 +1372,7 @@ GDBRemoteCommunicationClient::SendContinuePacketAndWaitForResponse bool GDBRemoteCommunicationClient::SendAsyncSignal (int signo) { - Mutex::Locker async_locker (m_async_mutex); + std::lock_guard<std::recursive_mutex> guard(m_async_mutex); m_async_signal = signo; bool timed_out = false; Mutex::Locker locker; diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h index 33114d2611f..096c4cf8101 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h @@ -13,6 +13,7 @@ // C Includes // C++ Includes #include <map> +#include <mutex> #include <string> #include <vector> @@ -631,7 +632,7 @@ protected: // If we need to send a packet while the target is running, the m_async_XXX // member variables take care of making this happen. - Mutex m_async_mutex; + std::recursive_mutex m_async_mutex; Predicate<bool> m_async_packet_predicate; std::string m_async_packet; PacketResult m_async_result; diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.h b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.h index f55b2eb3f4d..d2fd70042cc 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.h +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.h @@ -17,7 +17,6 @@ // Other libraries and framework includes // Project includes #include "lldb/lldb-private-forward.h" -#include "lldb/Host/Mutex.h" #include "lldb/Target/Process.h" #include "GDBRemoteCommunicationServer.h" diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp index 0274aa89acc..66e300a519f 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp @@ -76,23 +76,22 @@ namespace //---------------------------------------------------------------------- // GDBRemoteCommunicationServerLLGS constructor //---------------------------------------------------------------------- -GDBRemoteCommunicationServerLLGS::GDBRemoteCommunicationServerLLGS( - const lldb::PlatformSP& platform_sp, - MainLoop &mainloop) : - GDBRemoteCommunicationServerCommon ("gdb-remote.server", "gdb-remote.server.rx_packet"), - m_platform_sp (platform_sp), - m_mainloop (mainloop), - m_current_tid (LLDB_INVALID_THREAD_ID), - m_continue_tid (LLDB_INVALID_THREAD_ID), - m_debugged_process_mutex (Mutex::eMutexTypeRecursive), - m_debugged_process_sp (), - m_stdio_communication ("process.stdio"), - m_inferior_prev_state (StateType::eStateInvalid), - m_active_auxv_buffer_sp (), - m_saved_registers_mutex (), - m_saved_registers_map (), - m_next_saved_registers_id (1), - m_handshake_completed (false) +GDBRemoteCommunicationServerLLGS::GDBRemoteCommunicationServerLLGS(const lldb::PlatformSP &platform_sp, + MainLoop &mainloop) + : GDBRemoteCommunicationServerCommon("gdb-remote.server", "gdb-remote.server.rx_packet"), + m_platform_sp(platform_sp), + m_mainloop(mainloop), + m_current_tid(LLDB_INVALID_THREAD_ID), + m_continue_tid(LLDB_INVALID_THREAD_ID), + m_debugged_process_mutex(), + m_debugged_process_sp(), + m_stdio_communication("process.stdio"), + m_inferior_prev_state(StateType::eStateInvalid), + m_active_auxv_buffer_sp(), + m_saved_registers_mutex(), + m_saved_registers_map(), + m_next_saved_registers_id(1), + m_handshake_completed(false) { assert(platform_sp); RegisterPacketHandlers(); @@ -210,7 +209,7 @@ GDBRemoteCommunicationServerLLGS::LaunchProcess () Error error; { - Mutex::Locker locker (m_debugged_process_mutex); + std::lock_guard<std::recursive_mutex> guard(m_debugged_process_mutex); assert (!m_debugged_process_sp && "lldb-gdbserver creating debugged process but one already exists"); error = NativeProcessProtocol::Launch( m_process_launch_info, @@ -2593,7 +2592,7 @@ GDBRemoteCommunicationServerLLGS::Handle_QSaveRegisterState (StringExtractorGDBR // Save the register data buffer under the save id. { - Mutex::Locker locker (m_saved_registers_mutex); + std::lock_guard<std::mutex> guard(m_saved_registers_mutex); m_saved_registers_map[save_id] = register_data_sp; } @@ -2643,7 +2642,7 @@ GDBRemoteCommunicationServerLLGS::Handle_QRestoreRegisterState (StringExtractorG // Retrieve register state buffer, then remove from the list. DataBufferSP register_data_sp; { - Mutex::Locker locker (m_saved_registers_mutex); + std::lock_guard<std::mutex> guard(m_saved_registers_mutex); // Find the register set buffer for the given save id. auto it = m_saved_registers_map.find (save_id); @@ -2947,7 +2946,7 @@ GDBRemoteCommunicationServerLLGS::GetCurrentThreadID () const uint32_t GDBRemoteCommunicationServerLLGS::GetNextSavedRegistersID () { - Mutex::Locker locker (m_saved_registers_mutex); + std::lock_guard<std::mutex> guard(m_saved_registers_mutex); return m_next_saved_registers_id++; } diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h index f16057781dd..066e4985062 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h @@ -12,12 +12,12 @@ // C Includes // C++ Includes +#include <mutex> #include <unordered_map> // Other libraries and framework includes #include "lldb/lldb-private-forward.h" #include "lldb/Core/Communication.h" -#include "lldb/Host/Mutex.h" #include "lldb/Host/common/NativeProcessProtocol.h" #include "lldb/Host/MainLoop.h" @@ -119,7 +119,7 @@ protected: MainLoop::ReadHandleUP m_network_handle_up; lldb::tid_t m_current_tid; lldb::tid_t m_continue_tid; - Mutex m_debugged_process_mutex; + std::recursive_mutex m_debugged_process_mutex; NativeProcessProtocolSP m_debugged_process_sp; Communication m_stdio_communication; @@ -127,7 +127,7 @@ protected: lldb::StateType m_inferior_prev_state; lldb::DataBufferSP m_active_auxv_buffer_sp; - Mutex m_saved_registers_mutex; + std::mutex m_saved_registers_mutex; std::unordered_map<uint32_t, lldb::DataBufferSP> m_saved_registers_map; uint32_t m_next_saved_registers_id; bool m_handshake_completed : 1; diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp index b2969746ce1..e16e9e4a3b8 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp @@ -48,14 +48,14 @@ using namespace lldb_private::process_gdb_remote; // GDBRemoteCommunicationServerPlatform constructor //---------------------------------------------------------------------- GDBRemoteCommunicationServerPlatform::GDBRemoteCommunicationServerPlatform(const Socket::SocketProtocol socket_protocol, - const char* socket_scheme) : - GDBRemoteCommunicationServerCommon ("gdb-remote.server", "gdb-remote.server.rx_packet"), - m_socket_protocol(socket_protocol), - m_socket_scheme(socket_scheme), - m_spawned_pids_mutex (Mutex::eMutexTypeRecursive), - m_platform_sp (Platform::GetHostPlatform ()), - m_port_map (), - m_port_offset(0) + const char *socket_scheme) + : GDBRemoteCommunicationServerCommon("gdb-remote.server", "gdb-remote.server.rx_packet"), + m_socket_protocol(socket_protocol), + m_socket_scheme(socket_scheme), + m_spawned_pids_mutex(), + m_platform_sp(Platform::GetHostPlatform()), + m_port_map(), + m_port_offset(0) { m_pending_gdb_server.pid = LLDB_INVALID_PROCESS_ID; m_pending_gdb_server.port = 0; @@ -78,11 +78,7 @@ GDBRemoteCommunicationServerPlatform::GDBRemoteCommunicationServerPlatform(const &GDBRemoteCommunicationServerPlatform::Handle_jSignalsInfo); RegisterPacketHandler(StringExtractorGDBRemote::eServerPacketType_interrupt, - [this](StringExtractorGDBRemote packet, - Error &error, - bool &interrupt, - bool &quit) - { + [this](StringExtractorGDBRemote packet, Error &error, bool &interrupt, bool &quit) { error.SetErrorString("interrupt received"); interrupt = true; return PacketResult::Success; @@ -156,7 +152,7 @@ GDBRemoteCommunicationServerPlatform::LaunchGDBServer(const lldb_private::Args& pid = debugserver_launch_info.GetProcessID(); if (pid != LLDB_INVALID_PROCESS_ID) { - Mutex::Locker locker (m_spawned_pids_mutex); + std::lock_guard<std::recursive_mutex> guard(m_spawned_pids_mutex); m_spawned_pids.insert(pid); if (port > 0) AssociatePortWithProcess(port, pid); @@ -261,7 +257,7 @@ GDBRemoteCommunicationServerPlatform::Handle_qKillSpawnedProcess (StringExtracto // verify that we know anything about this pid. // Scope for locker { - Mutex::Locker locker (m_spawned_pids_mutex); + std::lock_guard<std::recursive_mutex> guard(m_spawned_pids_mutex); if (m_spawned_pids.find(pid) == m_spawned_pids.end()) { // not a pid we know about @@ -281,7 +277,7 @@ GDBRemoteCommunicationServerPlatform::KillSpawnedProcess (lldb::pid_t pid) { // make sure we know about this process { - Mutex::Locker locker (m_spawned_pids_mutex); + std::lock_guard<std::recursive_mutex> guard(m_spawned_pids_mutex); if (m_spawned_pids.find(pid) == m_spawned_pids.end()) return false; } @@ -293,7 +289,7 @@ GDBRemoteCommunicationServerPlatform::KillSpawnedProcess (lldb::pid_t pid) for (size_t i=0; i<10; ++i) { { - Mutex::Locker locker (m_spawned_pids_mutex); + std::lock_guard<std::recursive_mutex> guard(m_spawned_pids_mutex); if (m_spawned_pids.find(pid) == m_spawned_pids.end()) { // it is now killed @@ -305,7 +301,7 @@ GDBRemoteCommunicationServerPlatform::KillSpawnedProcess (lldb::pid_t pid) // check one more time after the final usleep { - Mutex::Locker locker (m_spawned_pids_mutex); + std::lock_guard<std::recursive_mutex> guard(m_spawned_pids_mutex); if (m_spawned_pids.find(pid) == m_spawned_pids.end()) return true; } @@ -317,7 +313,7 @@ GDBRemoteCommunicationServerPlatform::KillSpawnedProcess (lldb::pid_t pid) for (size_t i=0; i<10; ++i) { { - Mutex::Locker locker (m_spawned_pids_mutex); + std::lock_guard<std::recursive_mutex> guard(m_spawned_pids_mutex); if (m_spawned_pids.find(pid) == m_spawned_pids.end()) { // it is now killed @@ -330,7 +326,7 @@ GDBRemoteCommunicationServerPlatform::KillSpawnedProcess (lldb::pid_t pid) // check one more time after the final usleep // Scope for locker { - Mutex::Locker locker (m_spawned_pids_mutex); + std::lock_guard<std::recursive_mutex> guard(m_spawned_pids_mutex); if (m_spawned_pids.find(pid) == m_spawned_pids.end()) return true; } @@ -444,7 +440,7 @@ GDBRemoteCommunicationServerPlatform::Handle_jSignalsInfo(StringExtractorGDBRemo bool GDBRemoteCommunicationServerPlatform::DebugserverProcessReaped (lldb::pid_t pid) { - Mutex::Locker locker (m_spawned_pids_mutex); + std::lock_guard<std::recursive_mutex> guard(m_spawned_pids_mutex); FreePortForProcess(pid); m_spawned_pids.erase(pid); return true; @@ -479,7 +475,7 @@ GDBRemoteCommunicationServerPlatform::LaunchProcess () if (pid != LLDB_INVALID_PROCESS_ID) { // add to spawned pids - Mutex::Locker locker (m_spawned_pids_mutex); + std::lock_guard<std::recursive_mutex> guard(m_spawned_pids_mutex); m_spawned_pids.insert(pid); } diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.h b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.h index 1e948d4d5c6..646d267dcb9 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.h +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.h @@ -13,6 +13,7 @@ // C Includes // C++ Includes #include <map> +#include <mutex> #include <set> // Other libraries and framework includes @@ -82,7 +83,7 @@ public: protected: const Socket::SocketProtocol m_socket_protocol; const std::string m_socket_scheme; - Mutex m_spawned_pids_mutex; + std::recursive_mutex m_spawned_pids_mutex; std::set<lldb::pid_t> m_spawned_pids; lldb::PlatformSP m_platform_sp; diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp index d9d551421f4..47a861042cd 100644 --- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp @@ -267,39 +267,39 @@ ProcessGDBRemote::CanDebug (lldb::TargetSP target_sp, bool plugin_specified_by_n //---------------------------------------------------------------------- // ProcessGDBRemote constructor //---------------------------------------------------------------------- -ProcessGDBRemote::ProcessGDBRemote(lldb::TargetSP target_sp, ListenerSP listener_sp) : - Process (target_sp, listener_sp), - m_flags (0), - m_gdb_comm (), - m_debugserver_pid (LLDB_INVALID_PROCESS_ID), - m_last_stop_packet_mutex (Mutex::eMutexTypeRecursive), - m_register_info (), - m_async_broadcaster (NULL, "lldb.process.gdb-remote.async-broadcaster"), - m_async_listener_sp(Listener::MakeListener("lldb.process.gdb-remote.async-listener")), - m_async_thread_state_mutex(Mutex::eMutexTypeRecursive), - m_thread_ids (), - m_thread_pcs (), - m_jstopinfo_sp (), - m_jthreadsinfo_sp (), - m_continue_c_tids (), - m_continue_C_tids (), - m_continue_s_tids (), - m_continue_S_tids (), - m_max_memory_size (0), - m_remote_stub_max_memory_size (0), - m_addr_to_mmap_size (), - m_thread_create_bp_sp (), - m_waiting_for_attach (false), - m_destroy_tried_resuming (false), - m_command_sp (), - m_breakpoint_pc_offset (0), - m_initial_tid (LLDB_INVALID_THREAD_ID) +ProcessGDBRemote::ProcessGDBRemote(lldb::TargetSP target_sp, ListenerSP listener_sp) + : Process(target_sp, listener_sp), + m_flags(0), + m_gdb_comm(), + m_debugserver_pid(LLDB_INVALID_PROCESS_ID), + m_last_stop_packet_mutex(), + m_register_info(), + m_async_broadcaster(NULL, "lldb.process.gdb-remote.async-broadcaster"), + m_async_listener_sp(Listener::MakeListener("lldb.process.gdb-remote.async-listener")), + m_async_thread_state_mutex(), + m_thread_ids(), + m_thread_pcs(), + m_jstopinfo_sp(), + m_jthreadsinfo_sp(), + m_continue_c_tids(), + m_continue_C_tids(), + m_continue_s_tids(), + m_continue_S_tids(), + m_max_memory_size(0), + m_remote_stub_max_memory_size(0), + m_addr_to_mmap_size(), + m_thread_create_bp_sp(), + m_waiting_for_attach(false), + m_destroy_tried_resuming(false), + m_command_sp(), + m_breakpoint_pc_offset(0), + m_initial_tid(LLDB_INVALID_THREAD_ID) { - m_async_broadcaster.SetEventName (eBroadcastBitAsyncThreadShouldExit, "async thread should exit"); - m_async_broadcaster.SetEventName (eBroadcastBitAsyncContinue, "async thread continue"); - m_async_broadcaster.SetEventName (eBroadcastBitAsyncThreadDidExit, "async thread did exit"); + m_async_broadcaster.SetEventName(eBroadcastBitAsyncThreadShouldExit, "async thread should exit"); + m_async_broadcaster.SetEventName(eBroadcastBitAsyncContinue, "async thread continue"); + m_async_broadcaster.SetEventName(eBroadcastBitAsyncThreadDidExit, "async thread did exit"); - Log *log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_ASYNC)); + Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_ASYNC)); const uint32_t async_event_mask = eBroadcastBitAsyncContinue | eBroadcastBitAsyncThreadShouldExit; @@ -309,8 +309,8 @@ ProcessGDBRemote::ProcessGDBRemote(lldb::TargetSP target_sp, ListenerSP listener log->Printf("ProcessGDBRemote::%s failed to listen for m_async_broadcaster events", __FUNCTION__); } - const uint32_t gdb_event_mask = Communication::eBroadcastBitReadThreadDidExit | - GDBRemoteCommunication::eBroadcastBitGdbReadThreadGotNotify; + const uint32_t gdb_event_mask = + Communication::eBroadcastBitReadThreadDidExit | GDBRemoteCommunication::eBroadcastBitGdbReadThreadGotNotify; if (m_async_listener_sp->StartListeningForEvents(&m_gdb_comm, gdb_event_mask) != gdb_event_mask) { if (log) @@ -1729,8 +1729,8 @@ ProcessGDBRemote::UpdateThreadIDList () // Lock the thread stack while we access it //Mutex::Locker stop_stack_lock(m_last_stop_packet_mutex); - Mutex::Locker stop_stack_lock; - if (stop_stack_lock.TryLock(m_last_stop_packet_mutex)) + std::unique_lock<std::recursive_mutex> stop_stack_lock(m_last_stop_packet_mutex, std::defer_lock); + if (stop_stack_lock.try_lock()) { // Get the number of stop packets on the stack int nItems = m_stop_packet_stack.size(); @@ -2673,7 +2673,7 @@ ProcessGDBRemote::RefreshStateAfterStop () // Scope for the lock { // Lock the thread stack while we access it - Mutex::Locker stop_stack_lock(m_last_stop_packet_mutex); + std::lock_guard<std::recursive_mutex> guard(m_last_stop_packet_mutex); // Get the number of stop packets on the stack int nItems = m_stop_packet_stack.size(); // Iterate over them @@ -2975,7 +2975,7 @@ ProcessGDBRemote::SetLastStopPacket (const StringExtractorGDBRemote &response) // Scope the lock { // Lock the thread stack while we access it - Mutex::Locker stop_stack_lock(m_last_stop_packet_mutex); + std::lock_guard<std::recursive_mutex> guard(m_last_stop_packet_mutex); // We are are not using non-stop mode, there can only be one last stop // reply packet, so clear the list. @@ -3761,7 +3761,7 @@ ProcessGDBRemote::StartAsyncThread () if (log) log->Printf ("ProcessGDBRemote::%s ()", __FUNCTION__); - Mutex::Locker start_locker(m_async_thread_state_mutex); + std::lock_guard<std::recursive_mutex> guard(m_async_thread_state_mutex); if (!m_async_thread.IsJoinable()) { // Create a thread that watches our internal state and controls which @@ -3783,7 +3783,7 @@ ProcessGDBRemote::StopAsyncThread () if (log) log->Printf ("ProcessGDBRemote::%s ()", __FUNCTION__); - Mutex::Locker start_locker(m_async_thread_state_mutex); + std::lock_guard<std::recursive_mutex> guard(m_async_thread_state_mutex); if (m_async_thread.IsJoinable()) { m_async_broadcaster.BroadcastEvent (eBroadcastBitAsyncThreadShouldExit); diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h index 815435c0f74..6d373965fc4 100644 --- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h +++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h @@ -14,6 +14,7 @@ // C++ Includes #include <atomic> #include <map> +#include <mutex> #include <string> #include <vector> @@ -279,12 +280,12 @@ protected: GDBRemoteCommunicationClient m_gdb_comm; std::atomic<lldb::pid_t> m_debugserver_pid; std::vector<StringExtractorGDBRemote> m_stop_packet_stack; // The stop packet stack replaces the last stop packet variable - Mutex m_last_stop_packet_mutex; + std::recursive_mutex m_last_stop_packet_mutex; GDBRemoteDynamicRegisterInfo m_register_info; Broadcaster m_async_broadcaster; lldb::ListenerSP m_async_listener_sp; HostThread m_async_thread; - Mutex m_async_thread_state_mutex; + std::recursive_mutex m_async_thread_state_mutex; typedef std::vector<lldb::tid_t> tid_collection; typedef std::vector< std::pair<lldb::tid_t,int> > tid_sig_collection; typedef std::map<lldb::addr_t, lldb::addr_t> MMapMap; diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp index fed324a1a88..2c7914ad593 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp @@ -2069,7 +2069,7 @@ DWARFASTParserClang::CompleteTypeFromDWARF(const DWARFDIE &die, lldb_private::Ty { SymbolFileDWARF *dwarf = die.GetDWARF(); - lldb_private::Mutex::Locker locker(dwarf->GetObjectFile()->GetModule()->GetMutex()); + std::lock_guard<std::recursive_mutex> guard(dwarf->GetObjectFile()->GetModule()->GetMutex()); // Disable external storage for this type so we don't get anymore // clang::ExternalASTSource queries for this type. diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp index e3e5b7cb0ed..a2c466aacd2 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp @@ -1619,7 +1619,7 @@ SymbolFileDWARF::HasForwardDeclForClangType (const CompilerType &compiler_type) bool SymbolFileDWARF::CompleteType (CompilerType &compiler_type) { - lldb_private::Mutex::Locker locker(GetObjectFile()->GetModule()->GetMutex()); + std::lock_guard<std::recursive_mutex> guard(GetObjectFile()->GetModule()->GetMutex()); ClangASTContext *clang_type_system = llvm::dyn_cast_or_null<ClangASTContext>(compiler_type.GetTypeSystem()); if (clang_type_system) diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp index b762d641a4b..2cf497c9529 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp @@ -208,7 +208,7 @@ public: ObjectFile *oso_objfile = GetObjectFile (); if (oso_objfile) { - Mutex::Locker locker (m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); SymbolVendor* symbol_vendor = Module::GetSymbolVendor(can_create, feedback_strm); if (symbol_vendor) { diff --git a/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetItemInfoHandler.cpp b/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetItemInfoHandler.cpp index 688626e717d..38998469dcb 100644 --- a/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetItemInfoHandler.cpp +++ b/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetItemInfoHandler.cpp @@ -96,12 +96,12 @@ extern \"C\" } \n\ "; -AppleGetItemInfoHandler::AppleGetItemInfoHandler (Process *process) : - m_process (process), - m_get_item_info_impl_code (), - m_get_item_info_function_mutex(), - m_get_item_info_return_buffer_addr (LLDB_INVALID_ADDRESS), - m_get_item_info_retbuffer_mutex() +AppleGetItemInfoHandler::AppleGetItemInfoHandler(Process *process) + : m_process(process), + m_get_item_info_impl_code(), + m_get_item_info_function_mutex(), + m_get_item_info_return_buffer_addr(LLDB_INVALID_ADDRESS), + m_get_item_info_retbuffer_mutex() { } @@ -110,14 +110,14 @@ AppleGetItemInfoHandler::~AppleGetItemInfoHandler () } void -AppleGetItemInfoHandler::Detach () +AppleGetItemInfoHandler::Detach() { if (m_process && m_process->IsAlive() && m_get_item_info_return_buffer_addr != LLDB_INVALID_ADDRESS) { - Mutex::Locker locker; - locker.TryLock (m_get_item_info_retbuffer_mutex); // Even if we don't get the lock, deallocate the buffer - m_process->DeallocateMemory (m_get_item_info_return_buffer_addr); + std::unique_lock<std::mutex> lock(m_get_item_info_retbuffer_mutex, std::defer_lock); + lock.try_lock(); // Even if we don't get the lock, deallocate the buffer + m_process->DeallocateMemory(m_get_item_info_return_buffer_addr); } } @@ -143,8 +143,8 @@ AppleGetItemInfoHandler::SetupGetItemInfoFunction(Thread &thread, ValueList &get // Scope for mutex locker: { - Mutex::Locker locker(m_get_item_info_function_mutex); - + std::lock_guard<std::mutex> guard(m_get_item_info_function_mutex); + // First stage is to make the UtilityFunction to hold our injected function: if (!m_get_item_info_impl_code.get()) @@ -296,8 +296,7 @@ AppleGetItemInfoHandler::GetItemInfo (Thread &thread, uint64_t item, addr_t page page_to_free_size_value.SetValueType (Value::eValueTypeScalar); page_to_free_size_value.SetCompilerType (clang_uint64_type); - - Mutex::Locker locker(m_get_item_info_retbuffer_mutex); + std::lock_guard<std::mutex> guard(m_get_item_info_retbuffer_mutex); if (m_get_item_info_return_buffer_addr == LLDB_INVALID_ADDRESS) { addr_t bufaddr = process_sp->AllocateMemory (32, ePermissionsReadable | ePermissionsWritable, error); diff --git a/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetItemInfoHandler.h b/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetItemInfoHandler.h index 51182a62493..dc341d672d6 100644 --- a/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetItemInfoHandler.h +++ b/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetItemInfoHandler.h @@ -13,13 +13,14 @@ // C Includes // C++ Includes #include <map> +#include <mutex> #include <vector> + // Other libraries and framework includes // Project includes #include "lldb/lldb-public.h" #include "lldb/Core/Error.h" #include "lldb/Expression/UtilityFunction.h" -#include "lldb/Host/Mutex.h" #include "lldb/Symbol/CompilerType.h" // This class will insert a UtilityFunction into the inferior process for @@ -105,11 +106,10 @@ private: lldb_private::Process *m_process; std::unique_ptr<UtilityFunction> m_get_item_info_impl_code; - Mutex m_get_item_info_function_mutex; + std::mutex m_get_item_info_function_mutex; lldb::addr_t m_get_item_info_return_buffer_addr; - Mutex m_get_item_info_retbuffer_mutex; - + std::mutex m_get_item_info_retbuffer_mutex; }; } // using namespace lldb_private diff --git a/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetPendingItemsHandler.cpp b/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetPendingItemsHandler.cpp index c262ffc9fba..d311f5fb5f6 100644 --- a/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetPendingItemsHandler.cpp +++ b/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetPendingItemsHandler.cpp @@ -100,12 +100,12 @@ extern \"C\" } \n\ "; -AppleGetPendingItemsHandler::AppleGetPendingItemsHandler (Process *process) : - m_process (process), - m_get_pending_items_impl_code (), - m_get_pending_items_function_mutex(), - m_get_pending_items_return_buffer_addr (LLDB_INVALID_ADDRESS), - m_get_pending_items_retbuffer_mutex() +AppleGetPendingItemsHandler::AppleGetPendingItemsHandler(Process *process) + : m_process(process), + m_get_pending_items_impl_code(), + m_get_pending_items_function_mutex(), + m_get_pending_items_return_buffer_addr(LLDB_INVALID_ADDRESS), + m_get_pending_items_retbuffer_mutex() { } @@ -114,14 +114,13 @@ AppleGetPendingItemsHandler::~AppleGetPendingItemsHandler () } void -AppleGetPendingItemsHandler::Detach () +AppleGetPendingItemsHandler::Detach() { - if (m_process && m_process->IsAlive() && m_get_pending_items_return_buffer_addr != LLDB_INVALID_ADDRESS) { - Mutex::Locker locker; - locker.TryLock (m_get_pending_items_retbuffer_mutex); // Even if we don't get the lock, deallocate the buffer - m_process->DeallocateMemory (m_get_pending_items_return_buffer_addr); + std::unique_lock<std::mutex> lock(m_get_pending_items_retbuffer_mutex, std::defer_lock); + lock.try_lock(); // Even if we don't get the lock, deallocate the buffer + m_process->DeallocateMemory(m_get_pending_items_return_buffer_addr); } } @@ -149,8 +148,8 @@ AppleGetPendingItemsHandler::SetupGetPendingItemsFunction(Thread &thread, ValueL // Scope for mutex locker: { - Mutex::Locker locker(m_get_pending_items_function_mutex); - + std::lock_guard<std::mutex> guard(m_get_pending_items_function_mutex); + // First stage is to make the ClangUtility to hold our injected function: if (!m_get_pending_items_impl_code.get()) @@ -298,8 +297,7 @@ AppleGetPendingItemsHandler::GetPendingItems (Thread &thread, addr_t queue, addr page_to_free_size_value.SetValueType (Value::eValueTypeScalar); page_to_free_size_value.SetCompilerType (clang_uint64_type); - - Mutex::Locker locker(m_get_pending_items_retbuffer_mutex); + std::lock_guard<std::mutex> guard(m_get_pending_items_retbuffer_mutex); if (m_get_pending_items_return_buffer_addr == LLDB_INVALID_ADDRESS) { addr_t bufaddr = process_sp->AllocateMemory (32, ePermissionsReadable | ePermissionsWritable, error); diff --git a/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetPendingItemsHandler.h b/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetPendingItemsHandler.h index 445c4a0fb82..96fbf4a548c 100644 --- a/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetPendingItemsHandler.h +++ b/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetPendingItemsHandler.h @@ -13,12 +13,13 @@ // C Includes // C++ Includes #include <map> +#include <mutex> #include <vector> + // Other libraries and framework includes // Project includes #include "lldb/lldb-public.h" #include "lldb/Core/Error.h" -#include "lldb/Host/Mutex.h" #include "lldb/Symbol/CompilerType.h" // This class will insert a UtilityFunction into the inferior process for @@ -107,11 +108,10 @@ private: lldb_private::Process *m_process; std::unique_ptr<UtilityFunction> m_get_pending_items_impl_code; - Mutex m_get_pending_items_function_mutex; + std::mutex m_get_pending_items_function_mutex; lldb::addr_t m_get_pending_items_return_buffer_addr; - Mutex m_get_pending_items_retbuffer_mutex; - + std::mutex m_get_pending_items_retbuffer_mutex; }; } // using namespace lldb_private diff --git a/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetQueuesHandler.cpp b/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetQueuesHandler.cpp index e1f045124ee..e90fe6d5d17 100644 --- a/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetQueuesHandler.cpp +++ b/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetQueuesHandler.cpp @@ -96,12 +96,12 @@ extern \"C\" } \n\ "; -AppleGetQueuesHandler::AppleGetQueuesHandler (Process *process) : - m_process (process), - m_get_queues_impl_code_up (), - m_get_queues_function_mutex(), - m_get_queues_return_buffer_addr (LLDB_INVALID_ADDRESS), - m_get_queues_retbuffer_mutex() +AppleGetQueuesHandler::AppleGetQueuesHandler(Process *process) + : m_process(process), + m_get_queues_impl_code_up(), + m_get_queues_function_mutex(), + m_get_queues_return_buffer_addr(LLDB_INVALID_ADDRESS), + m_get_queues_retbuffer_mutex() { } @@ -110,14 +110,14 @@ AppleGetQueuesHandler::~AppleGetQueuesHandler () } void -AppleGetQueuesHandler::Detach () +AppleGetQueuesHandler::Detach() { if (m_process && m_process->IsAlive() && m_get_queues_return_buffer_addr != LLDB_INVALID_ADDRESS) { - Mutex::Locker locker; - locker.TryLock (m_get_queues_retbuffer_mutex); // Even if we don't get the lock, deallocate the buffer - m_process->DeallocateMemory (m_get_queues_return_buffer_addr); + std::unique_lock<std::mutex> lock(m_get_queues_retbuffer_mutex, std::defer_lock); + lock.try_lock(); // Even if we don't get the lock, deallocate the buffer + m_process->DeallocateMemory(m_get_queues_return_buffer_addr); } } @@ -159,8 +159,8 @@ AppleGetQueuesHandler::SetupGetQueuesFunction (Thread &thread, ValueList &get_qu // Scope for mutex locker: { - Mutex::Locker locker(m_get_queues_function_mutex); - + std::lock_guard<std::mutex> guard(m_get_queues_function_mutex); + // First stage is to make the ClangUtility to hold our injected function: if (!m_get_queues_impl_code_up.get()) @@ -297,8 +297,7 @@ AppleGetQueuesHandler::GetCurrentQueues (Thread &thread, addr_t page_to_free, ui page_to_free_size_value.SetValueType (Value::eValueTypeScalar); page_to_free_size_value.SetCompilerType (clang_uint64_type); - - Mutex::Locker locker(m_get_queues_retbuffer_mutex); + std::lock_guard<std::mutex> guard(m_get_queues_retbuffer_mutex); if (m_get_queues_return_buffer_addr == LLDB_INVALID_ADDRESS) { addr_t bufaddr = process_sp->AllocateMemory (32, ePermissionsReadable | ePermissionsWritable, error); diff --git a/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetQueuesHandler.h b/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetQueuesHandler.h index 6f3df5f6280..b7ca26dafc3 100644 --- a/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetQueuesHandler.h +++ b/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetQueuesHandler.h @@ -13,12 +13,13 @@ // C Includes // C++ Includes #include <map> +#include <mutex> #include <vector> + // Other libraries and framework includes // Project includes #include "lldb/lldb-public.h" #include "lldb/Core/Error.h" -#include "lldb/Host/Mutex.h" #include "lldb/Symbol/CompilerType.h" // This class will insert a UtilityFunction into the inferior process for @@ -104,11 +105,10 @@ private: lldb_private::Process *m_process; std::unique_ptr<UtilityFunction> m_get_queues_impl_code_up; - Mutex m_get_queues_function_mutex; + std::mutex m_get_queues_function_mutex; lldb::addr_t m_get_queues_return_buffer_addr; - Mutex m_get_queues_retbuffer_mutex; - + std::mutex m_get_queues_retbuffer_mutex; }; } // using namespace lldb_private diff --git a/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetThreadItemInfoHandler.cpp b/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetThreadItemInfoHandler.cpp index 266e461a8a4..85ad012c59f 100644 --- a/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetThreadItemInfoHandler.cpp +++ b/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetThreadItemInfoHandler.cpp @@ -103,12 +103,12 @@ extern \"C\" } \n\ "; -AppleGetThreadItemInfoHandler::AppleGetThreadItemInfoHandler (Process *process) : - m_process (process), - m_get_thread_item_info_impl_code (), - m_get_thread_item_info_function_mutex(), - m_get_thread_item_info_return_buffer_addr (LLDB_INVALID_ADDRESS), - m_get_thread_item_info_retbuffer_mutex() +AppleGetThreadItemInfoHandler::AppleGetThreadItemInfoHandler(Process *process) + : m_process(process), + m_get_thread_item_info_impl_code(), + m_get_thread_item_info_function_mutex(), + m_get_thread_item_info_return_buffer_addr(LLDB_INVALID_ADDRESS), + m_get_thread_item_info_retbuffer_mutex() { } @@ -117,14 +117,14 @@ AppleGetThreadItemInfoHandler::~AppleGetThreadItemInfoHandler () } void -AppleGetThreadItemInfoHandler::Detach () +AppleGetThreadItemInfoHandler::Detach() { if (m_process && m_process->IsAlive() && m_get_thread_item_info_return_buffer_addr != LLDB_INVALID_ADDRESS) { - Mutex::Locker locker; - locker.TryLock (m_get_thread_item_info_retbuffer_mutex); // Even if we don't get the lock, deallocate the buffer - m_process->DeallocateMemory (m_get_thread_item_info_return_buffer_addr); + std::unique_lock<std::mutex> lock(m_get_thread_item_info_retbuffer_mutex, std::defer_lock); + lock.try_lock(); // Even if we don't get the lock, deallocate the buffer + m_process->DeallocateMemory(m_get_thread_item_info_return_buffer_addr); } } @@ -152,8 +152,8 @@ AppleGetThreadItemInfoHandler::SetupGetThreadItemInfoFunction (Thread &thread, V // Scope for mutex locker: { - Mutex::Locker locker(m_get_thread_item_info_function_mutex); - + std::lock_guard<std::mutex> guard(m_get_thread_item_info_function_mutex); + // First stage is to make the ClangUtility to hold our injected function: if (!m_get_thread_item_info_impl_code.get()) @@ -300,8 +300,7 @@ AppleGetThreadItemInfoHandler::GetThreadItemInfo (Thread &thread, tid_t thread_i page_to_free_size_value.SetValueType (Value::eValueTypeScalar); page_to_free_size_value.SetCompilerType (clang_uint64_type); - - Mutex::Locker locker(m_get_thread_item_info_retbuffer_mutex); + std::lock_guard<std::mutex> guard(m_get_thread_item_info_retbuffer_mutex); if (m_get_thread_item_info_return_buffer_addr == LLDB_INVALID_ADDRESS) { addr_t bufaddr = process_sp->AllocateMemory (32, ePermissionsReadable | ePermissionsWritable, error); diff --git a/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetThreadItemInfoHandler.h b/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetThreadItemInfoHandler.h index c1798fb515b..21a63e8c225 100644 --- a/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetThreadItemInfoHandler.h +++ b/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetThreadItemInfoHandler.h @@ -13,12 +13,13 @@ // C Includes // C++ Includes #include <map> +#include <mutex> #include <vector> + // Other libraries and framework includes // Project includes #include "lldb/lldb-public.h" #include "lldb/Core/Error.h" -#include "lldb/Host/Mutex.h" #include "lldb/Symbol/CompilerType.h" // This class will insert a UtilityFunction into the inferior process for @@ -101,11 +102,10 @@ private: lldb_private::Process *m_process; std::unique_ptr<UtilityFunction> m_get_thread_item_info_impl_code; - Mutex m_get_thread_item_info_function_mutex; + std::mutex m_get_thread_item_info_function_mutex; lldb::addr_t m_get_thread_item_info_return_buffer_addr; - Mutex m_get_thread_item_info_retbuffer_mutex; - + std::mutex m_get_thread_item_info_retbuffer_mutex; }; } // using namespace lldb_private diff --git a/lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp b/lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp index 37af5b83019..9ec36b383af 100644 --- a/lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp +++ b/lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp @@ -83,25 +83,25 @@ SystemRuntimeMacOSX::CreateInstance (Process* process) //---------------------------------------------------------------------- // Constructor //---------------------------------------------------------------------- -SystemRuntimeMacOSX::SystemRuntimeMacOSX (Process* process) : - SystemRuntime(process), - m_break_id(LLDB_INVALID_BREAK_ID), - m_mutex(Mutex::eMutexTypeRecursive), - m_get_queues_handler(process), - m_get_pending_items_handler(process), - m_get_item_info_handler(process), - m_get_thread_item_info_handler(process), - m_page_to_free(LLDB_INVALID_ADDRESS), - m_page_to_free_size(0), - m_lib_backtrace_recording_info(), - m_dispatch_queue_offsets_addr (LLDB_INVALID_ADDRESS), - m_libdispatch_offsets(), - m_libpthread_layout_offsets_addr (LLDB_INVALID_ADDRESS), - m_libpthread_offsets(), - m_dispatch_tsd_indexes_addr (LLDB_INVALID_ADDRESS), - m_libdispatch_tsd_indexes(), - m_dispatch_voucher_offsets_addr (LLDB_INVALID_ADDRESS), - m_libdispatch_voucher_offsets() +SystemRuntimeMacOSX::SystemRuntimeMacOSX(Process *process) + : SystemRuntime(process), + m_break_id(LLDB_INVALID_BREAK_ID), + m_mutex(), + m_get_queues_handler(process), + m_get_pending_items_handler(process), + m_get_item_info_handler(process), + m_get_thread_item_info_handler(process), + m_page_to_free(LLDB_INVALID_ADDRESS), + m_page_to_free_size(0), + m_lib_backtrace_recording_info(), + m_dispatch_queue_offsets_addr(LLDB_INVALID_ADDRESS), + m_libdispatch_offsets(), + m_libpthread_layout_offsets_addr(LLDB_INVALID_ADDRESS), + m_libpthread_offsets(), + m_dispatch_tsd_indexes_addr(LLDB_INVALID_ADDRESS), + m_libdispatch_tsd_indexes(), + m_dispatch_voucher_offsets_addr(LLDB_INVALID_ADDRESS), + m_libdispatch_voucher_offsets() { } @@ -128,7 +128,7 @@ SystemRuntimeMacOSX::Detach () void SystemRuntimeMacOSX::Clear (bool clear_process) { - Mutex::Locker locker(m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); if (m_process->IsAlive() && LLDB_BREAK_ID_IS_VALID(m_break_id)) m_process->ClearBreakpointSiteByID(m_break_id); diff --git a/lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.h b/lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.h index 8fe15fa4d8a..b685a056f5c 100644 --- a/lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.h +++ b/lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.h @@ -12,8 +12,9 @@ // C Includes // C++ Includes -#include <vector> +#include <mutex> #include <string> +#include <vector> // Other libraries and framework include // Project includes @@ -23,7 +24,6 @@ #include "lldb/Core/StructuredData.h" #include "lldb/Core/UUID.h" #include "lldb/Host/FileSpec.h" -#include "lldb/Host/Mutex.h" #include "lldb/Target/Process.h" #include "lldb/Target/QueueItem.h" @@ -124,7 +124,7 @@ public: protected: lldb::user_id_t m_break_id; - mutable lldb_private::Mutex m_mutex; + mutable std::recursive_mutex m_mutex; private: struct libBacktraceRecording_info { diff --git a/lldb/source/Symbol/FuncUnwinders.cpp b/lldb/source/Symbol/FuncUnwinders.cpp index faddc107f22..e81c8cca70a 100644 --- a/lldb/source/Symbol/FuncUnwinders.cpp +++ b/lldb/source/Symbol/FuncUnwinders.cpp @@ -30,27 +30,27 @@ using namespace lldb_private; /// constructor //------------------------------------------------ -FuncUnwinders::FuncUnwinders (UnwindTable& unwind_table, AddressRange range) : - m_unwind_table (unwind_table), - m_range (range), - m_mutex (Mutex::eMutexTypeRecursive), - m_unwind_plan_assembly_sp (), - m_unwind_plan_eh_frame_sp (), - m_unwind_plan_eh_frame_augmented_sp (), - m_unwind_plan_compact_unwind (), - m_unwind_plan_arm_unwind_sp (), - m_unwind_plan_fast_sp (), - m_unwind_plan_arch_default_sp (), - m_unwind_plan_arch_default_at_func_entry_sp (), - m_tried_unwind_plan_assembly (false), - m_tried_unwind_plan_eh_frame (false), - m_tried_unwind_plan_eh_frame_augmented (false), - m_tried_unwind_plan_compact_unwind (false), - m_tried_unwind_plan_arm_unwind (false), - m_tried_unwind_fast (false), - m_tried_unwind_arch_default (false), - m_tried_unwind_arch_default_at_func_entry (false), - m_first_non_prologue_insn () +FuncUnwinders::FuncUnwinders(UnwindTable &unwind_table, AddressRange range) + : m_unwind_table(unwind_table), + m_range(range), + m_mutex(), + m_unwind_plan_assembly_sp(), + m_unwind_plan_eh_frame_sp(), + m_unwind_plan_eh_frame_augmented_sp(), + m_unwind_plan_compact_unwind(), + m_unwind_plan_arm_unwind_sp(), + m_unwind_plan_fast_sp(), + m_unwind_plan_arch_default_sp(), + m_unwind_plan_arch_default_at_func_entry_sp(), + m_tried_unwind_plan_assembly(false), + m_tried_unwind_plan_eh_frame(false), + m_tried_unwind_plan_eh_frame_augmented(false), + m_tried_unwind_plan_compact_unwind(false), + m_tried_unwind_plan_arm_unwind(false), + m_tried_unwind_fast(false), + m_tried_unwind_arch_default(false), + m_tried_unwind_arch_default_at_func_entry(false), + m_first_non_prologue_insn() { } @@ -65,7 +65,7 @@ FuncUnwinders::~FuncUnwinders () UnwindPlanSP FuncUnwinders::GetUnwindPlanAtCallSite (Target &target, int current_offset) { - Mutex::Locker locker (m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); UnwindPlanSP unwind_plan_sp = GetEHFrameUnwindPlan (target, current_offset); if (unwind_plan_sp) @@ -90,7 +90,7 @@ FuncUnwinders::GetCompactUnwindUnwindPlan (Target &target, int current_offset) if (m_tried_unwind_plan_compact_unwind) return UnwindPlanSP(); - Mutex::Locker lock (m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); m_tried_unwind_plan_compact_unwind = true; if (m_range.GetBaseAddress().IsValid()) { @@ -117,7 +117,7 @@ FuncUnwinders::GetEHFrameUnwindPlan (Target &target, int current_offset) if (m_unwind_plan_eh_frame_sp.get() || m_tried_unwind_plan_eh_frame) return m_unwind_plan_eh_frame_sp; - Mutex::Locker lock (m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); m_tried_unwind_plan_eh_frame = true; if (m_range.GetBaseAddress().IsValid()) { @@ -141,7 +141,7 @@ FuncUnwinders::GetArmUnwindUnwindPlan (Target &target, int current_offset) if (m_unwind_plan_arm_unwind_sp.get() || m_tried_unwind_plan_arm_unwind) return m_unwind_plan_arm_unwind_sp; - Mutex::Locker lock (m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); m_tried_unwind_plan_arm_unwind = true; if (m_range.GetBaseAddress().IsValid()) { @@ -175,7 +175,7 @@ FuncUnwinders::GetEHFrameAugmentedUnwindPlan (Target &target, Thread &thread, in return m_unwind_plan_eh_frame_augmented_sp; } - Mutex::Locker lock (m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); m_tried_unwind_plan_eh_frame_augmented = true; UnwindPlanSP eh_frame_plan = GetEHFrameUnwindPlan (target, current_offset); @@ -213,7 +213,7 @@ FuncUnwinders::GetAssemblyUnwindPlan (Target &target, Thread &thread, int curren return m_unwind_plan_assembly_sp; } - Mutex::Locker lock (m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); m_tried_unwind_plan_assembly = true; UnwindAssemblySP assembly_profiler_sp (GetUnwindAssemblyProfiler(target)); @@ -246,7 +246,7 @@ FuncUnwinders::GetUnwindPlanFastUnwind (Target& target, Thread& thread) if (m_unwind_plan_fast_sp.get() || m_tried_unwind_fast) return m_unwind_plan_fast_sp; - Mutex::Locker locker (m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); m_tried_unwind_fast = true; UnwindAssemblySP assembly_profiler_sp (GetUnwindAssemblyProfiler(target)); @@ -267,7 +267,7 @@ FuncUnwinders::GetUnwindPlanArchitectureDefault (Thread& thread) if (m_unwind_plan_arch_default_sp.get() || m_tried_unwind_arch_default) return m_unwind_plan_arch_default_sp; - Mutex::Locker locker (m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); m_tried_unwind_arch_default = true; Address current_pc; @@ -294,7 +294,7 @@ FuncUnwinders::GetUnwindPlanArchitectureDefaultAtFunctionEntry (Thread& thread) if (m_unwind_plan_arch_default_at_func_entry_sp.get() || m_tried_unwind_arch_default_at_func_entry) return m_unwind_plan_arch_default_at_func_entry_sp; - Mutex::Locker locker (m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); m_tried_unwind_arch_default_at_func_entry = true; Address current_pc; @@ -322,7 +322,7 @@ FuncUnwinders::GetFirstNonPrologueInsn (Target& target) if (m_first_non_prologue_insn.IsValid()) return m_first_non_prologue_insn; - Mutex::Locker locker (m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); ExecutionContext exe_ctx (target.shared_from_this(), false); UnwindAssemblySP assembly_profiler_sp (GetUnwindAssemblyProfiler(target)); if (assembly_profiler_sp) diff --git a/lldb/source/Symbol/ObjectFile.cpp b/lldb/source/Symbol/ObjectFile.cpp index 36196b01bc7..62cde26c702 100644 --- a/lldb/source/Symbol/ObjectFile.cpp +++ b/lldb/source/Symbol/ObjectFile.cpp @@ -600,7 +600,7 @@ ObjectFile::ClearSymtab () ModuleSP module_sp(GetModule()); if (module_sp) { - lldb_private::Mutex::Locker locker(module_sp->GetMutex()); + std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT)); if (log) log->Printf ("%p ObjectFile::ClearSymtab () symtab = %p", @@ -620,7 +620,7 @@ ObjectFile::GetSectionList(bool update_module_section_list) ModuleSP module_sp(GetModule()); if (module_sp) { - lldb_private::Mutex::Locker locker(module_sp->GetMutex()); + std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); CreateSections(*module_sp->GetUnifiedSectionList()); } } diff --git a/lldb/source/Symbol/SymbolVendor.cpp b/lldb/source/Symbol/SymbolVendor.cpp index 266685105b3..f168f016910 100644 --- a/lldb/source/Symbol/SymbolVendor.cpp +++ b/lldb/source/Symbol/SymbolVendor.cpp @@ -85,7 +85,7 @@ SymbolVendor::AddSymbolFileRepresentation(const ObjectFileSP &objfile_sp) ModuleSP module_sp(GetModule()); if (module_sp) { - lldb_private::Mutex::Locker locker(module_sp->GetMutex()); + std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); if (objfile_sp) { m_objfile_sp = objfile_sp; @@ -100,7 +100,7 @@ SymbolVendor::SetCompileUnitAtIndex (size_t idx, const CompUnitSP &cu_sp) ModuleSP module_sp(GetModule()); if (module_sp) { - lldb_private::Mutex::Locker locker(module_sp->GetMutex()); + std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); const size_t num_compile_units = GetNumCompileUnits(); if (idx < num_compile_units) { @@ -129,7 +129,7 @@ SymbolVendor::GetNumCompileUnits() ModuleSP module_sp(GetModule()); if (module_sp) { - lldb_private::Mutex::Locker locker(module_sp->GetMutex()); + std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); if (m_compile_units.empty()) { if (m_sym_file_ap.get()) @@ -151,7 +151,7 @@ SymbolVendor::ParseCompileUnitLanguage (const SymbolContext& sc) ModuleSP module_sp(GetModule()); if (module_sp) { - lldb_private::Mutex::Locker locker(module_sp->GetMutex()); + std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); if (m_sym_file_ap.get()) return m_sym_file_ap->ParseCompileUnitLanguage(sc); } @@ -165,7 +165,7 @@ SymbolVendor::ParseCompileUnitFunctions (const SymbolContext &sc) ModuleSP module_sp(GetModule()); if (module_sp) { - lldb_private::Mutex::Locker locker(module_sp->GetMutex()); + std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); if (m_sym_file_ap.get()) return m_sym_file_ap->ParseCompileUnitFunctions(sc); } @@ -178,7 +178,7 @@ SymbolVendor::ParseCompileUnitLineTable (const SymbolContext &sc) ModuleSP module_sp(GetModule()); if (module_sp) { - lldb_private::Mutex::Locker locker(module_sp->GetMutex()); + std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); if (m_sym_file_ap.get()) return m_sym_file_ap->ParseCompileUnitLineTable(sc); } @@ -191,7 +191,7 @@ SymbolVendor::ParseCompileUnitDebugMacros (const SymbolContext &sc) ModuleSP module_sp(GetModule()); if (module_sp) { - lldb_private::Mutex::Locker locker(module_sp->GetMutex()); + std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); if (m_sym_file_ap.get()) return m_sym_file_ap->ParseCompileUnitDebugMacros(sc); } @@ -203,7 +203,7 @@ SymbolVendor::ParseCompileUnitSupportFiles (const SymbolContext& sc, FileSpecLis ModuleSP module_sp(GetModule()); if (module_sp) { - lldb_private::Mutex::Locker locker(module_sp->GetMutex()); + std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); if (m_sym_file_ap.get()) return m_sym_file_ap->ParseCompileUnitSupportFiles(sc, support_files); } @@ -217,7 +217,7 @@ SymbolVendor::ParseImportedModules (const SymbolContext &sc, ModuleSP module_sp(GetModule()); if (module_sp) { - lldb_private::Mutex::Locker locker(module_sp->GetMutex()); + std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); if (m_sym_file_ap.get()) return m_sym_file_ap->ParseImportedModules(sc, imported_modules); } @@ -231,7 +231,7 @@ SymbolVendor::ParseFunctionBlocks (const SymbolContext &sc) ModuleSP module_sp(GetModule()); if (module_sp) { - lldb_private::Mutex::Locker locker(module_sp->GetMutex()); + std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); if (m_sym_file_ap.get()) return m_sym_file_ap->ParseFunctionBlocks(sc); } @@ -244,7 +244,7 @@ SymbolVendor::ParseTypes (const SymbolContext &sc) ModuleSP module_sp(GetModule()); if (module_sp) { - lldb_private::Mutex::Locker locker(module_sp->GetMutex()); + std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); if (m_sym_file_ap.get()) return m_sym_file_ap->ParseTypes(sc); } @@ -257,7 +257,7 @@ SymbolVendor::ParseVariablesForContext (const SymbolContext& sc) ModuleSP module_sp(GetModule()); if (module_sp) { - lldb_private::Mutex::Locker locker(module_sp->GetMutex()); + std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); if (m_sym_file_ap.get()) return m_sym_file_ap->ParseVariablesForContext(sc); } @@ -270,7 +270,7 @@ SymbolVendor::ResolveTypeUID(lldb::user_id_t type_uid) ModuleSP module_sp(GetModule()); if (module_sp) { - lldb_private::Mutex::Locker locker(module_sp->GetMutex()); + std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); if (m_sym_file_ap.get()) return m_sym_file_ap->ResolveTypeUID(type_uid); } @@ -284,7 +284,7 @@ SymbolVendor::ResolveSymbolContext (const Address& so_addr, uint32_t resolve_sco ModuleSP module_sp(GetModule()); if (module_sp) { - lldb_private::Mutex::Locker locker(module_sp->GetMutex()); + std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); if (m_sym_file_ap.get()) return m_sym_file_ap->ResolveSymbolContext(so_addr, resolve_scope, sc); } @@ -297,7 +297,7 @@ SymbolVendor::ResolveSymbolContext (const FileSpec& file_spec, uint32_t line, bo ModuleSP module_sp(GetModule()); if (module_sp) { - lldb_private::Mutex::Locker locker(module_sp->GetMutex()); + std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); if (m_sym_file_ap.get()) return m_sym_file_ap->ResolveSymbolContext(file_spec, line, check_inlines, resolve_scope, sc_list); } @@ -310,7 +310,7 @@ SymbolVendor::FindGlobalVariables (const ConstString &name, const CompilerDeclCo ModuleSP module_sp(GetModule()); if (module_sp) { - lldb_private::Mutex::Locker locker(module_sp->GetMutex()); + std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); if (m_sym_file_ap.get()) return m_sym_file_ap->FindGlobalVariables(name, parent_decl_ctx, append, max_matches, variables); } @@ -323,7 +323,7 @@ SymbolVendor::FindGlobalVariables (const RegularExpression& regex, bool append, ModuleSP module_sp(GetModule()); if (module_sp) { - lldb_private::Mutex::Locker locker(module_sp->GetMutex()); + std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); if (m_sym_file_ap.get()) return m_sym_file_ap->FindGlobalVariables(regex, append, max_matches, variables); } @@ -336,7 +336,7 @@ SymbolVendor::FindFunctions(const ConstString &name, const CompilerDeclContext * ModuleSP module_sp(GetModule()); if (module_sp) { - lldb_private::Mutex::Locker locker(module_sp->GetMutex()); + std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); if (m_sym_file_ap.get()) return m_sym_file_ap->FindFunctions(name, parent_decl_ctx, name_type_mask, include_inlines, append, sc_list); } @@ -349,7 +349,7 @@ SymbolVendor::FindFunctions(const RegularExpression& regex, bool include_inlines ModuleSP module_sp(GetModule()); if (module_sp) { - lldb_private::Mutex::Locker locker(module_sp->GetMutex()); + std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); if (m_sym_file_ap.get()) return m_sym_file_ap->FindFunctions(regex, include_inlines, append, sc_list); } @@ -363,7 +363,7 @@ SymbolVendor::FindTypes (const SymbolContext& sc, const ConstString &name, const ModuleSP module_sp(GetModule()); if (module_sp) { - lldb_private::Mutex::Locker locker(module_sp->GetMutex()); + std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); if (m_sym_file_ap.get()) return m_sym_file_ap->FindTypes(sc, name, parent_decl_ctx, append, max_matches, searched_symbol_files, types); } @@ -378,7 +378,7 @@ SymbolVendor::FindTypes (const std::vector<CompilerContext> &context, bool appen ModuleSP module_sp(GetModule()); if (module_sp) { - lldb_private::Mutex::Locker locker(module_sp->GetMutex()); + std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); if (m_sym_file_ap.get()) return m_sym_file_ap->FindTypes(context, append, types); } @@ -395,7 +395,7 @@ SymbolVendor::GetTypes (SymbolContextScope *sc_scope, ModuleSP module_sp(GetModule()); if (module_sp) { - lldb_private::Mutex::Locker locker(module_sp->GetMutex()); + std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); if (m_sym_file_ap.get()) return m_sym_file_ap->GetTypes (sc_scope, type_mask, type_list); } @@ -409,7 +409,7 @@ SymbolVendor::FindNamespace(const SymbolContext& sc, const ConstString &name, co ModuleSP module_sp(GetModule()); if (module_sp) { - lldb_private::Mutex::Locker locker(module_sp->GetMutex()); + std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); if (m_sym_file_ap.get()) namespace_decl_ctx = m_sym_file_ap->FindNamespace (sc, name, parent_decl_ctx); } @@ -422,7 +422,7 @@ SymbolVendor::Dump(Stream *s) ModuleSP module_sp(GetModule()); if (module_sp) { - lldb_private::Mutex::Locker locker(module_sp->GetMutex()); + std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); bool show_context = false; @@ -467,7 +467,7 @@ SymbolVendor::GetCompileUnitAtIndex(size_t idx) ModuleSP module_sp(GetModule()); if (module_sp) { - lldb_private::Mutex::Locker locker(module_sp->GetMutex()); + std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); const size_t num_compile_units = GetNumCompileUnits(); if (idx < num_compile_units) { diff --git a/lldb/source/Target/JITLoaderList.cpp b/lldb/source/Target/JITLoaderList.cpp index 24a73b7fd51..76c9dd67535 100644 --- a/lldb/source/Target/JITLoaderList.cpp +++ b/lldb/source/Target/JITLoaderList.cpp @@ -14,8 +14,7 @@ using namespace lldb; using namespace lldb_private; -JITLoaderList::JITLoaderList() - : m_jit_loaders_vec(), m_jit_loaders_mutex(Mutex::eMutexTypeRecursive) +JITLoaderList::JITLoaderList() : m_jit_loaders_vec(), m_jit_loaders_mutex() { } @@ -26,14 +25,14 @@ JITLoaderList::~JITLoaderList() void JITLoaderList::Append (const JITLoaderSP &jit_loader_sp) { - Mutex::Locker locker(m_jit_loaders_mutex); + std::lock_guard<std::recursive_mutex> guard(m_jit_loaders_mutex); m_jit_loaders_vec.push_back(jit_loader_sp); } void JITLoaderList::Remove (const JITLoaderSP &jit_loader_sp) { - Mutex::Locker locker(m_jit_loaders_mutex); + std::lock_guard<std::recursive_mutex> guard(m_jit_loaders_mutex); m_jit_loaders_vec.erase(std::remove(m_jit_loaders_vec.begin(), m_jit_loaders_vec.end(), jit_loader_sp), m_jit_loaders_vec.end()); @@ -48,14 +47,14 @@ JITLoaderList::GetSize() const JITLoaderSP JITLoaderList::GetLoaderAtIndex (size_t idx) { - Mutex::Locker locker(m_jit_loaders_mutex); + std::lock_guard<std::recursive_mutex> guard(m_jit_loaders_mutex); return m_jit_loaders_vec[idx]; } void JITLoaderList::DidLaunch() { - Mutex::Locker locker(m_jit_loaders_mutex); + std::lock_guard<std::recursive_mutex> guard(m_jit_loaders_mutex); for (auto const &jit_loader : m_jit_loaders_vec) jit_loader->DidLaunch(); } @@ -63,7 +62,7 @@ JITLoaderList::DidLaunch() void JITLoaderList::DidAttach() { - Mutex::Locker locker(m_jit_loaders_mutex); + std::lock_guard<std::recursive_mutex> guard(m_jit_loaders_mutex); for (auto const &jit_loader : m_jit_loaders_vec) jit_loader->DidAttach(); } @@ -71,7 +70,7 @@ JITLoaderList::DidAttach() void JITLoaderList::ModulesDidLoad(ModuleList &module_list) { - Mutex::Locker locker(m_jit_loaders_mutex); + std::lock_guard<std::recursive_mutex> guard(m_jit_loaders_mutex); for (auto const &jit_loader : m_jit_loaders_vec) jit_loader->ModulesDidLoad(module_list); } diff --git a/lldb/source/Target/Language.cpp b/lldb/source/Target/Language.cpp index 43fa9b3e5ed..a0ec227f8f5 100644 --- a/lldb/source/Target/Language.cpp +++ b/lldb/source/Target/Language.cpp @@ -36,23 +36,23 @@ GetLanguagesMap () return *g_map; } -static Mutex& -GetLanguagesMutex () +static std::mutex & +GetLanguagesMutex() { - static Mutex *g_mutex = nullptr; + static std::mutex *g_mutex = nullptr; static std::once_flag g_initialize; - + std::call_once(g_initialize, [] { - g_mutex = new Mutex(); // NOTE: INTENTIONAL LEAK due to global destructor chain + g_mutex = new std::mutex(); // NOTE: INTENTIONAL LEAK due to global destructor chain }); - + return *g_mutex; } Language* Language::FindPlugin (lldb::LanguageType language) { - Mutex::Locker locker(GetLanguagesMutex()); + std::lock_guard<std::mutex> guard(GetLanguagesMutex()); LanguagesMap& map(GetLanguagesMap()); auto iter = map.find(language), end = map.end(); if (iter != end) @@ -80,7 +80,7 @@ Language::FindPlugin (lldb::LanguageType language) void Language::ForEach (std::function<bool(Language*)> callback) { - Mutex::Locker locker(GetLanguagesMutex()); + std::lock_guard<std::mutex> guard(GetLanguagesMutex()); LanguagesMap& map(GetLanguagesMap()); for (const auto& entry : map) { diff --git a/lldb/source/Target/Platform.cpp b/lldb/source/Target/Platform.cpp index 85a167e78f5..eaf4151587c 100644 --- a/lldb/source/Target/Platform.cpp +++ b/lldb/source/Target/Platform.cpp @@ -162,10 +162,10 @@ GetPlatformList() return g_platform_list; } -static Mutex & -GetPlatformListMutex () +static std::recursive_mutex & +GetPlatformListMutex() { - static Mutex g_mutex(Mutex::eMutexTypeRecursive); + static std::recursive_mutex g_mutex; return g_mutex; } @@ -182,7 +182,7 @@ Platform::Terminate () { if (--g_initialize_count == 0) { - Mutex::Locker locker(GetPlatformListMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetPlatformListMutex()); GetPlatformList().clear(); } } @@ -204,7 +204,7 @@ Platform::SetHostPlatform (const lldb::PlatformSP &platform_sp) if (platform_sp) { - Mutex::Locker locker(GetPlatformListMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetPlatformListMutex()); GetPlatformList().push_back(platform_sp); } } @@ -309,7 +309,7 @@ Platform::Find (const ConstString &name) if (name == g_host_platform_name) return GetHostPlatform(); - Mutex::Locker locker(GetPlatformListMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetPlatformListMutex()); for (const auto &platform_sp : GetPlatformList()) { if (platform_sp->GetName() == name) @@ -341,7 +341,7 @@ Platform::Create (const ConstString &name, Error &error) if (platform_sp) { - Mutex::Locker locker(GetPlatformListMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetPlatformListMutex()); GetPlatformList().push_back(platform_sp); } @@ -357,7 +357,7 @@ Platform::Create (const ArchSpec &arch, ArchSpec *platform_arch_ptr, Error &erro // Scope for locker { // First try exact arch matches across all platforms already created - Mutex::Locker locker(GetPlatformListMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetPlatformListMutex()); for (const auto &platform_sp : GetPlatformList()) { if (platform_sp->IsCompatibleArchitecture(arch, true, platform_arch_ptr)) @@ -382,7 +382,7 @@ Platform::Create (const ArchSpec &arch, ArchSpec *platform_arch_ptr, Error &erro platform_sp = create_callback(false, &arch); if (platform_sp && platform_sp->IsCompatibleArchitecture(arch, true, platform_arch_ptr)) { - Mutex::Locker locker(GetPlatformListMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetPlatformListMutex()); GetPlatformList().push_back(platform_sp); return platform_sp; } @@ -396,7 +396,7 @@ Platform::Create (const ArchSpec &arch, ArchSpec *platform_arch_ptr, Error &erro platform_sp = create_callback(false, &arch); if (platform_sp && platform_sp->IsCompatibleArchitecture(arch, false, platform_arch_ptr)) { - Mutex::Locker locker(GetPlatformListMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetPlatformListMutex()); GetPlatformList().push_back(platform_sp); return platform_sp; } @@ -414,37 +414,37 @@ Platform::Create (const ArchSpec &arch, ArchSpec *platform_arch_ptr, Error &erro //------------------------------------------------------------------ /// Default Constructor //------------------------------------------------------------------ -Platform::Platform (bool is_host) : - m_is_host (is_host), - m_os_version_set_while_connected (false), - m_system_arch_set_while_connected (false), - m_sdk_sysroot (), - m_sdk_build (), - m_working_dir (), - m_remote_url (), - m_name (), - m_major_os_version (UINT32_MAX), - m_minor_os_version (UINT32_MAX), - m_update_os_version (UINT32_MAX), - m_system_arch(), - m_mutex (Mutex::eMutexTypeRecursive), - m_uid_map(), - m_gid_map(), - m_max_uid_name_len (0), - m_max_gid_name_len (0), - m_supports_rsync (false), - m_rsync_opts (), - m_rsync_prefix (), - m_supports_ssh (false), - m_ssh_opts (), - m_ignores_remote_hostname (false), - m_trap_handlers(), - m_calculated_trap_handlers (false), - m_module_cache (llvm::make_unique<ModuleCache> ()) -{ - Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT)); +Platform::Platform(bool is_host) + : m_is_host(is_host), + m_os_version_set_while_connected(false), + m_system_arch_set_while_connected(false), + m_sdk_sysroot(), + m_sdk_build(), + m_working_dir(), + m_remote_url(), + m_name(), + m_major_os_version(UINT32_MAX), + m_minor_os_version(UINT32_MAX), + m_update_os_version(UINT32_MAX), + m_system_arch(), + m_mutex(), + m_uid_map(), + m_gid_map(), + m_max_uid_name_len(0), + m_max_gid_name_len(0), + m_supports_rsync(false), + m_rsync_opts(), + m_rsync_prefix(), + m_supports_ssh(false), + m_ssh_opts(), + m_ignores_remote_hostname(false), + m_trap_handlers(), + m_calculated_trap_handlers(false), + m_module_cache(llvm::make_unique<ModuleCache>()) +{ + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_OBJECT)); if (log) - log->Printf ("%p Platform::Platform()", static_cast<void*>(this)); + log->Printf("%p Platform::Platform()", static_cast<void *>(this)); } //------------------------------------------------------------------ @@ -528,7 +528,7 @@ Platform::GetOSVersion (uint32_t &major, uint32_t &update, Process *process) { - Mutex::Locker locker (m_mutex); + std::lock_guard<std::mutex> guard(m_mutex); bool success = m_major_os_version != UINT32_MAX; if (IsHost()) @@ -1741,7 +1741,7 @@ Platform::GetTrapHandlerSymbolNames () { if (!m_calculated_trap_handlers) { - Mutex::Locker locker (m_mutex); + std::lock_guard<std::mutex> guard(m_mutex); if (!m_calculated_trap_handlers) { CalculateTrapHandlerSymbolNames(); diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp index a880782663a..66fe12f3e1e 100644 --- a/lldb/source/Target/Process.cpp +++ b/lldb/source/Target/Process.cpp @@ -1795,7 +1795,7 @@ Process::SetPrivateState (StateType new_state) log->Printf("Process::SetPrivateState (%s)", StateAsCString(new_state)); Mutex::Locker thread_locker(m_thread_list.GetMutex()); - Mutex::Locker locker(m_private_state.GetMutex()); + std::lock_guard<std::recursive_mutex> guard(m_private_state.GetMutex()); const StateType old_state = m_private_state.GetValueNoLock (); state_changed = old_state != new_state; diff --git a/lldb/source/Target/SectionLoadHistory.cpp b/lldb/source/Target/SectionLoadHistory.cpp index 1e5c4175a2b..196d5b07db2 100644 --- a/lldb/source/Target/SectionLoadHistory.cpp +++ b/lldb/source/Target/SectionLoadHistory.cpp @@ -23,21 +23,21 @@ using namespace lldb_private; bool SectionLoadHistory::IsEmpty() const { - Mutex::Locker locker(m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); return m_stop_id_to_section_load_list.empty(); } void SectionLoadHistory::Clear () { - Mutex::Locker locker(m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); m_stop_id_to_section_load_list.clear(); } uint32_t SectionLoadHistory::GetLastStopID() const { - Mutex::Locker locker(m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); if (m_stop_id_to_section_load_list.empty()) return 0; else @@ -108,7 +108,7 @@ SectionLoadList & SectionLoadHistory::GetCurrentSectionLoadList () { const bool read_only = true; - Mutex::Locker locker(m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); SectionLoadList *section_load_list = GetSectionLoadListForStopID (eStopIDNow, read_only); assert(section_load_list != NULL); return *section_load_list; @@ -117,7 +117,7 @@ SectionLoadHistory::GetCurrentSectionLoadList () addr_t SectionLoadHistory::GetSectionLoadAddress (uint32_t stop_id, const lldb::SectionSP §ion_sp) { - Mutex::Locker locker(m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); const bool read_only = true; SectionLoadList *section_load_list = GetSectionLoadListForStopID (stop_id, read_only); return section_load_list->GetSectionLoadAddress(section_sp); @@ -127,7 +127,7 @@ bool SectionLoadHistory::ResolveLoadAddress (uint32_t stop_id, addr_t load_addr, Address &so_addr) { // First find the top level section that this load address exists in - Mutex::Locker locker(m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); const bool read_only = true; SectionLoadList *section_load_list = GetSectionLoadListForStopID (stop_id, read_only); return section_load_list->ResolveLoadAddress (load_addr, so_addr); @@ -139,7 +139,7 @@ SectionLoadHistory::SetSectionLoadAddress (uint32_t stop_id, addr_t load_addr, bool warn_multiple) { - Mutex::Locker locker(m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); const bool read_only = false; SectionLoadList *section_load_list = GetSectionLoadListForStopID (stop_id, read_only); return section_load_list->SetSectionLoadAddress(section_sp, load_addr, warn_multiple); @@ -148,7 +148,7 @@ SectionLoadHistory::SetSectionLoadAddress (uint32_t stop_id, size_t SectionLoadHistory::SetSectionUnloaded (uint32_t stop_id, const lldb::SectionSP §ion_sp) { - Mutex::Locker locker(m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); const bool read_only = false; SectionLoadList *section_load_list = GetSectionLoadListForStopID (stop_id, read_only); return section_load_list->SetSectionUnloaded (section_sp); @@ -157,7 +157,7 @@ SectionLoadHistory::SetSectionUnloaded (uint32_t stop_id, const lldb::SectionSP bool SectionLoadHistory::SetSectionUnloaded (uint32_t stop_id, const lldb::SectionSP §ion_sp, addr_t load_addr) { - Mutex::Locker locker(m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); const bool read_only = false; SectionLoadList *section_load_list = GetSectionLoadListForStopID (stop_id, read_only); return section_load_list->SetSectionUnloaded (section_sp, load_addr); @@ -166,7 +166,7 @@ SectionLoadHistory::SetSectionUnloaded (uint32_t stop_id, const lldb::SectionSP void SectionLoadHistory::Dump (Stream &s, Target *target) { - Mutex::Locker locker(m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); StopIDToSectionLoadList::iterator pos, end = m_stop_id_to_section_load_list.end(); for (pos = m_stop_id_to_section_load_list.begin(); pos != end; ++pos) { diff --git a/lldb/source/Target/SectionLoadList.cpp b/lldb/source/Target/SectionLoadList.cpp index d79c32eeb53..1235a379550 100644 --- a/lldb/source/Target/SectionLoadList.cpp +++ b/lldb/source/Target/SectionLoadList.cpp @@ -24,13 +24,9 @@ using namespace lldb; using namespace lldb_private; - -SectionLoadList::SectionLoadList (const SectionLoadList& rhs) : - m_addr_to_sect(), - m_sect_to_addr(), - m_mutex (Mutex::eMutexTypeRecursive) +SectionLoadList::SectionLoadList(const SectionLoadList &rhs) : m_addr_to_sect(), m_sect_to_addr(), m_mutex() { - Mutex::Locker locker(rhs.m_mutex); + std::lock_guard<std::recursive_mutex> guard(rhs.m_mutex); m_addr_to_sect = rhs.m_addr_to_sect; m_sect_to_addr = rhs.m_sect_to_addr; } @@ -38,8 +34,8 @@ SectionLoadList::SectionLoadList (const SectionLoadList& rhs) : void SectionLoadList::operator=(const SectionLoadList &rhs) { - Mutex::Locker lhs_locker (m_mutex); - Mutex::Locker rhs_locker (rhs.m_mutex); + std::lock_guard<std::recursive_mutex> lhs_guard(m_mutex); + std::lock_guard<std::recursive_mutex> rhs_guard(rhs.m_mutex); m_addr_to_sect = rhs.m_addr_to_sect; m_sect_to_addr = rhs.m_sect_to_addr; } @@ -47,14 +43,14 @@ SectionLoadList::operator=(const SectionLoadList &rhs) bool SectionLoadList::IsEmpty() const { - Mutex::Locker locker(m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); return m_addr_to_sect.empty(); } void SectionLoadList::Clear () { - Mutex::Locker locker(m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); m_addr_to_sect.clear(); m_sect_to_addr.clear(); } @@ -66,7 +62,7 @@ SectionLoadList::GetSectionLoadAddress (const lldb::SectionSP §ion) const addr_t section_load_addr = LLDB_INVALID_ADDRESS; if (section) { - Mutex::Locker locker(m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); sect_to_addr_collection::const_iterator pos = m_sect_to_addr.find (section.get()); if (pos != m_sect_to_addr.end()) @@ -98,7 +94,7 @@ SectionLoadList::SetSectionLoadAddress (const lldb::SectionSP §ion, addr_t l return false; // No change // Fill in the section -> load_addr map - Mutex::Locker locker(m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); sect_to_addr_collection::iterator sta_pos = m_sect_to_addr.find(section.get()); if (sta_pos != m_sect_to_addr.end()) { @@ -185,7 +181,7 @@ SectionLoadList::SetSectionUnloaded (const lldb::SectionSP §ion_sp) section_sp->GetName().AsCString()); } - Mutex::Locker locker(m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); sect_to_addr_collection::iterator sta_pos = m_sect_to_addr.find(section_sp.get()); if (sta_pos != m_sect_to_addr.end()) @@ -222,7 +218,7 @@ SectionLoadList::SetSectionUnloaded (const lldb::SectionSP §ion_sp, addr_t l section_sp->GetName().AsCString(), load_addr); } bool erased = false; - Mutex::Locker locker(m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); sect_to_addr_collection::iterator sta_pos = m_sect_to_addr.find(section_sp.get()); if (sta_pos != m_sect_to_addr.end()) { @@ -244,8 +240,8 @@ SectionLoadList::SetSectionUnloaded (const lldb::SectionSP §ion_sp, addr_t l bool SectionLoadList::ResolveLoadAddress (addr_t load_addr, Address &so_addr) const { - // First find the top level section that this load address exists in - Mutex::Locker locker(m_mutex); + // First find the top level section that this load address exists in + std::lock_guard<std::recursive_mutex> guard(m_mutex); if (!m_addr_to_sect.empty()) { addr_to_sect_collection::const_iterator pos = m_addr_to_sect.lower_bound (load_addr); @@ -289,7 +285,7 @@ SectionLoadList::ResolveLoadAddress (addr_t load_addr, Address &so_addr) const void SectionLoadList::Dump (Stream &s, Target *target) { - Mutex::Locker locker(m_mutex); + std::lock_guard<std::recursive_mutex> guard(m_mutex); addr_to_sect_collection::const_iterator pos, end; for (pos = m_addr_to_sect.begin(), end = m_addr_to_sect.end(); pos != end; ++pos) { diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp index cae0a8d49a9..fc6b1d782e0 100644 --- a/lldb/source/Target/Target.cpp +++ b/lldb/source/Target/Target.cpp @@ -2611,11 +2611,11 @@ Target::GetSourceManager () ClangModulesDeclVendor * Target::GetClangModulesDeclVendor () { - static Mutex s_clang_modules_decl_vendor_mutex; // If this is contended we can make it per-target - + static std::mutex s_clang_modules_decl_vendor_mutex; // If this is contended we can make it per-target + { - Mutex::Locker clang_modules_decl_vendor_locker(s_clang_modules_decl_vendor_mutex); - + std::lock_guard<std::mutex> guard(s_clang_modules_decl_vendor_mutex); + if (!m_clang_modules_decl_vendor_ap) { m_clang_modules_decl_vendor_ap.reset(ClangModulesDeclVendor::Create(*this)); diff --git a/lldb/source/Target/TargetList.cpp b/lldb/source/Target/TargetList.cpp index 5f1a4399717..34954467691 100644 --- a/lldb/source/Target/TargetList.cpp +++ b/lldb/source/Target/TargetList.cpp @@ -42,11 +42,11 @@ TargetList::GetStaticBroadcasterClass () //---------------------------------------------------------------------- // TargetList constructor //---------------------------------------------------------------------- -TargetList::TargetList(Debugger &debugger) : - Broadcaster(debugger.GetBroadcasterManager(), TargetList::GetStaticBroadcasterClass().AsCString()), - m_target_list(), - m_target_list_mutex (Mutex::eMutexTypeRecursive), - m_selected_target_idx (0) +TargetList::TargetList(Debugger &debugger) + : Broadcaster(debugger.GetBroadcasterManager(), TargetList::GetStaticBroadcasterClass().AsCString()), + m_target_list(), + m_target_list_mutex(), + m_selected_target_idx(0) { CheckInWithManager(); } @@ -56,7 +56,7 @@ TargetList::TargetList(Debugger &debugger) : //---------------------------------------------------------------------- TargetList::~TargetList() { - Mutex::Locker locker(m_target_list_mutex); + std::lock_guard<std::recursive_mutex> guard(m_target_list_mutex); m_target_list.clear(); } @@ -515,7 +515,7 @@ TargetList::CreateTargetInternal (Debugger &debugger, // Don't put the dummy target in the target list, it's held separately. if (!is_dummy_target) { - Mutex::Locker locker(m_target_list_mutex); + std::lock_guard<std::recursive_mutex> guard(m_target_list_mutex); m_selected_target_idx = m_target_list.size(); m_target_list.push_back(target_sp); // Now prime this from the dummy target: @@ -533,7 +533,7 @@ TargetList::CreateTargetInternal (Debugger &debugger, bool TargetList::DeleteTarget (TargetSP &target_sp) { - Mutex::Locker locker(m_target_list_mutex); + std::lock_guard<std::recursive_mutex> guard(m_target_list_mutex); collection::iterator pos, end = m_target_list.end(); for (pos = m_target_list.begin(); pos != end; ++pos) @@ -551,7 +551,7 @@ TargetSP TargetList::FindTargetWithExecutableAndArchitecture(const FileSpec &exe_file_spec, const ArchSpec *exe_arch_ptr) const { - Mutex::Locker locker (m_target_list_mutex); + std::lock_guard<std::recursive_mutex> guard(m_target_list_mutex); TargetSP target_sp; bool full_match = (bool)exe_file_spec.GetDirectory(); @@ -580,7 +580,7 @@ TargetList::FindTargetWithExecutableAndArchitecture(const FileSpec &exe_file_spe TargetSP TargetList::FindTargetWithProcessID (lldb::pid_t pid) const { - Mutex::Locker locker(m_target_list_mutex); + std::lock_guard<std::recursive_mutex> guard(m_target_list_mutex); TargetSP target_sp; collection::const_iterator pos, end = m_target_list.end(); for (pos = m_target_list.begin(); pos != end; ++pos) @@ -601,7 +601,7 @@ TargetList::FindTargetWithProcess (Process *process) const TargetSP target_sp; if (process) { - Mutex::Locker locker(m_target_list_mutex); + std::lock_guard<std::recursive_mutex> guard(m_target_list_mutex); collection::const_iterator pos, end = m_target_list.end(); for (pos = m_target_list.begin(); pos != end; ++pos) { @@ -621,7 +621,7 @@ TargetList::GetTargetSP (Target *target) const TargetSP target_sp; if (target) { - Mutex::Locker locker(m_target_list_mutex); + std::lock_guard<std::recursive_mutex> guard(m_target_list_mutex); collection::const_iterator pos, end = m_target_list.end(); for (pos = m_target_list.begin(); pos != end; ++pos) { @@ -671,7 +671,7 @@ TargetList::SignalIfRunning (lldb::pid_t pid, int signo) if (pid == LLDB_INVALID_PROCESS_ID) { // Signal all processes with signal - Mutex::Locker locker(m_target_list_mutex); + std::lock_guard<std::recursive_mutex> guard(m_target_list_mutex); collection::iterator pos, end = m_target_list.end(); for (pos = m_target_list.begin(); pos != end; ++pos) { @@ -709,7 +709,7 @@ TargetList::SignalIfRunning (lldb::pid_t pid, int signo) int TargetList::GetNumTargets () const { - Mutex::Locker locker (m_target_list_mutex); + std::lock_guard<std::recursive_mutex> guard(m_target_list_mutex); return m_target_list.size(); } @@ -717,7 +717,7 @@ lldb::TargetSP TargetList::GetTargetAtIndex (uint32_t idx) const { TargetSP target_sp; - Mutex::Locker locker (m_target_list_mutex); + std::lock_guard<std::recursive_mutex> guard(m_target_list_mutex); if (idx < m_target_list.size()) target_sp = m_target_list[idx]; return target_sp; @@ -726,7 +726,7 @@ TargetList::GetTargetAtIndex (uint32_t idx) const uint32_t TargetList::GetIndexOfTarget (lldb::TargetSP target_sp) const { - Mutex::Locker locker (m_target_list_mutex); + std::lock_guard<std::recursive_mutex> guard(m_target_list_mutex); size_t num_targets = m_target_list.size(); for (size_t idx = 0; idx < num_targets; idx++) { @@ -739,7 +739,7 @@ TargetList::GetIndexOfTarget (lldb::TargetSP target_sp) const uint32_t TargetList::SetSelectedTarget (Target* target) { - Mutex::Locker locker (m_target_list_mutex); + std::lock_guard<std::recursive_mutex> guard(m_target_list_mutex); collection::const_iterator pos, begin = m_target_list.begin(), end = m_target_list.end(); @@ -758,7 +758,7 @@ TargetList::SetSelectedTarget (Target* target) lldb::TargetSP TargetList::GetSelectedTarget () { - Mutex::Locker locker (m_target_list_mutex); + std::lock_guard<std::recursive_mutex> guard(m_target_list_mutex); if (m_selected_target_idx >= m_target_list.size()) m_selected_target_idx = 0; return GetTargetAtIndex (m_selected_target_idx); diff --git a/lldb/source/Target/Thread.cpp b/lldb/source/Target/Thread.cpp index 3062623af8f..a2905016842 100644 --- a/lldb/source/Target/Thread.cpp +++ b/lldb/source/Target/Thread.cpp @@ -9,7 +9,6 @@ // C Includes // C++ Includes -#include <mutex> // Other libraries and framework includes // Project includes #include "lldb/Breakpoint/BreakpointLocation.h" @@ -271,36 +270,36 @@ Thread::GetStaticBroadcasterClass () return class_name; } -Thread::Thread (Process &process, lldb::tid_t tid, bool use_invalid_index_id) : - ThreadProperties (false), - UserID (tid), - Broadcaster(process.GetTarget().GetDebugger().GetBroadcasterManager(), Thread::GetStaticBroadcasterClass().AsCString()), - m_process_wp (process.shared_from_this()), - m_stop_info_sp (), - m_stop_info_stop_id (0), - m_stop_info_override_stop_id (0), - m_index_id (use_invalid_index_id ? LLDB_INVALID_INDEX32 : process.GetNextThreadIndexID(tid)), - m_reg_context_sp (), - m_state (eStateUnloaded), - m_state_mutex (Mutex::eMutexTypeRecursive), - m_plan_stack (), - m_completed_plan_stack(), - m_frame_mutex (Mutex::eMutexTypeRecursive), - m_curr_frames_sp (), - m_prev_frames_sp (), - m_resume_signal (LLDB_INVALID_SIGNAL_NUMBER), - m_resume_state (eStateRunning), - m_temporary_resume_state (eStateRunning), - m_unwinder_ap (), - m_destroy_called (false), - m_override_should_notify (eLazyBoolCalculate), - m_extended_info_fetched (false), - m_extended_info () -{ - Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT)); +Thread::Thread(Process &process, lldb::tid_t tid, bool use_invalid_index_id) + : ThreadProperties(false), + UserID(tid), + Broadcaster(process.GetTarget().GetDebugger().GetBroadcasterManager(), + Thread::GetStaticBroadcasterClass().AsCString()), + m_process_wp(process.shared_from_this()), + m_stop_info_sp(), + m_stop_info_stop_id(0), + m_stop_info_override_stop_id(0), + m_index_id(use_invalid_index_id ? LLDB_INVALID_INDEX32 : process.GetNextThreadIndexID(tid)), + m_reg_context_sp(), + m_state(eStateUnloaded), + m_state_mutex(), + m_plan_stack(), + m_completed_plan_stack(), + m_frame_mutex(), + m_curr_frames_sp(), + m_prev_frames_sp(), + m_resume_signal(LLDB_INVALID_SIGNAL_NUMBER), + m_resume_state(eStateRunning), + m_temporary_resume_state(eStateRunning), + m_unwinder_ap(), + m_destroy_called(false), + m_override_should_notify(eLazyBoolCalculate), + m_extended_info_fetched(false), + m_extended_info() +{ + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_OBJECT)); if (log) - log->Printf ("%p Thread::Thread(tid = 0x%4.4" PRIx64 ")", - static_cast<void*>(this), GetID()); + log->Printf("%p Thread::Thread(tid = 0x%4.4" PRIx64 ")", static_cast<void *>(this), GetID()); CheckInWithManager(); QueueFundamentalPlan(true); @@ -345,7 +344,7 @@ Thread::DestroyThread () m_stop_info_sp.reset(); m_reg_context_sp.reset(); m_unwinder_ap.reset(); - Mutex::Locker locker(m_frame_mutex); + std::lock_guard<std::recursive_mutex> guard(m_frame_mutex); m_curr_frames_sp.reset(); m_prev_frames_sp.reset(); } @@ -645,14 +644,14 @@ StateType Thread::GetState() const { // If any other threads access this we will need a mutex for it - Mutex::Locker locker(m_state_mutex); + std::lock_guard<std::recursive_mutex> guard(m_state_mutex); return m_state; } void Thread::SetState(StateType state) { - Mutex::Locker locker(m_state_mutex); + std::lock_guard<std::recursive_mutex> guard(m_state_mutex); m_state = state; } @@ -1823,7 +1822,7 @@ StackFrameListSP Thread::GetStackFrameList () { StackFrameListSP frame_list_sp; - Mutex::Locker locker(m_frame_mutex); + std::lock_guard<std::recursive_mutex> guard(m_frame_mutex); if (m_curr_frames_sp) { frame_list_sp = m_curr_frames_sp; @@ -1839,7 +1838,7 @@ Thread::GetStackFrameList () void Thread::ClearStackFrames () { - Mutex::Locker locker(m_frame_mutex); + std::lock_guard<std::recursive_mutex> guard(m_frame_mutex); Unwind *unwinder = GetUnwinder (); if (unwinder) diff --git a/lldb/source/Target/ThreadPlan.cpp b/lldb/source/Target/ThreadPlan.cpp index 24323337acc..bf9a05497c7 100644 --- a/lldb/source/Target/ThreadPlan.cpp +++ b/lldb/source/Target/ThreadPlan.cpp @@ -27,21 +27,21 @@ using namespace lldb_private; //---------------------------------------------------------------------- // ThreadPlan constructor //---------------------------------------------------------------------- -ThreadPlan::ThreadPlan(ThreadPlanKind kind, const char *name, Thread &thread, Vote stop_vote, Vote run_vote) : - m_thread (thread), - m_stop_vote (stop_vote), - m_run_vote (run_vote), - m_kind (kind), - m_name (name), - m_plan_complete_mutex (Mutex::eMutexTypeRecursive), - m_cached_plan_explains_stop (eLazyBoolCalculate), - m_plan_complete (false), - m_plan_private (false), - m_okay_to_discard (true), - m_is_master_plan (false), - m_plan_succeeded(true) +ThreadPlan::ThreadPlan(ThreadPlanKind kind, const char *name, Thread &thread, Vote stop_vote, Vote run_vote) + : m_thread(thread), + m_stop_vote(stop_vote), + m_run_vote(run_vote), + m_kind(kind), + m_name(name), + m_plan_complete_mutex(), + m_cached_plan_explains_stop(eLazyBoolCalculate), + m_plan_complete(false), + m_plan_private(false), + m_okay_to_discard(true), + m_is_master_plan(false), + m_plan_succeeded(true) { - SetID (GetNextID()); + SetID(GetNextID()); } //---------------------------------------------------------------------- @@ -67,14 +67,14 @@ ThreadPlan::PlanExplainsStop (Event *event_ptr) bool ThreadPlan::IsPlanComplete () { - Mutex::Locker locker(m_plan_complete_mutex); + std::lock_guard<std::recursive_mutex> guard(m_plan_complete_mutex); return m_plan_complete; } void ThreadPlan::SetPlanComplete (bool success) { - Mutex::Locker locker(m_plan_complete_mutex); + std::lock_guard<std::recursive_mutex> guard(m_plan_complete_mutex); m_plan_complete = true; m_plan_succeeded = success; } @@ -82,7 +82,7 @@ ThreadPlan::SetPlanComplete (bool success) bool ThreadPlan::MischiefManaged () { - Mutex::Locker locker(m_plan_complete_mutex); + std::lock_guard<std::recursive_mutex> guard(m_plan_complete_mutex); // Mark the plan is complete, but don't override the success flag. m_plan_complete = true; return true; diff --git a/lldb/source/Utility/SharingPtr.cpp b/lldb/source/Utility/SharingPtr.cpp index 7f1278567ff..7eedeb08afd 100644 --- a/lldb/source/Utility/SharingPtr.cpp +++ b/lldb/source/Utility/SharingPtr.cpp @@ -14,12 +14,12 @@ // If ENABLE_SP_LOGGING is defined, then log all shared pointer assignments // and allow them to be queried using a pointer by a call to: #include <execinfo.h> -#include <map> #include <assert.h> -#include "lldb/Host/Mutex.h" #include "llvm/ADT/STLExtras.h" +#include <map> +#include <mutex> #include <vector> class Backtrace @@ -70,8 +70,8 @@ extern "C" void track_sp (void *sp_this, void *ptr, long use_count) { typedef std::pair<void *, Backtrace> PtrBacktracePair; typedef std::map<void *, PtrBacktracePair> PtrToBacktraceMap; - static lldb_private::Mutex g_mutex(lldb_private::Mutex::eMutexTypeNormal); - lldb_private::Mutex::Locker locker (g_mutex); + static std::mutex g_mutex; + std::lock_guard<std::mutex> guard(g_mutex); static PtrToBacktraceMap g_map; if (sp_this) |