123 changes: 0 additions & 123 deletions lldb/include/lldb/Host/Condition.h

This file was deleted.

1 change: 0 additions & 1 deletion lldb/include/lldb/Host/Editline.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
#include <string>
#include <vector>

#include "lldb/Host/Condition.h"
#include "lldb/Host/ConnectionFileDescriptor.h"
#include "lldb/Host/FileSpec.h"
#include "lldb/Host/Predicate.h"
Expand Down
313 changes: 0 additions & 313 deletions lldb/include/lldb/Host/Mutex.h

This file was deleted.

146 changes: 101 additions & 45 deletions lldb/include/lldb/Host/Predicate.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
#include <time.h>

// C++ Includes
#include <condition_variable>
#include <mutex>

// Other libraries and framework includes
// Project includes
#include "lldb/lldb-defines.h"
#include "lldb/Host/Mutex.h"
#include "lldb/Host/Condition.h"

//#define DB_PTHREAD_LOG_EVENTS

Expand Down Expand Up @@ -97,7 +98,7 @@ class Predicate
T
GetValue () const
{
Mutex::Locker locker(m_mutex);
std::lock_guard<std::mutex> guard(m_mutex);
T value = m_value;
return value;
}
Expand All @@ -120,7 +121,7 @@ class Predicate
void
SetValue (T value, PredicateBroadcastType broadcast_type)
{
Mutex::Locker locker(m_mutex);
std::lock_guard<std::mutex> guard(m_mutex);
#ifdef DB_PTHREAD_LOG_EVENTS
printf("%s (value = 0x%8.8x, broadcast_type = %i)\n", __FUNCTION__, value, broadcast_type);
#endif
Expand Down Expand Up @@ -148,7 +149,7 @@ class Predicate
void
SetValueBits (T bits, PredicateBroadcastType broadcast_type)
{
Mutex::Locker locker(m_mutex);
std::lock_guard<std::mutex> guard(m_mutex);
#ifdef DB_PTHREAD_LOG_EVENTS
printf("%s (bits = 0x%8.8x, broadcast_type = %i)\n", __FUNCTION__, bits, broadcast_type);
#endif
Expand Down Expand Up @@ -176,7 +177,7 @@ class Predicate
void
ResetValueBits (T bits, PredicateBroadcastType broadcast_type)
{
Mutex::Locker locker(m_mutex);
std::lock_guard<std::mutex> guard(m_mutex);
#ifdef DB_PTHREAD_LOG_EVENTS
printf("%s (bits = 0x%8.8x, broadcast_type = %i)\n", __FUNCTION__, bits, broadcast_type);
#endif
Expand Down Expand Up @@ -213,21 +214,30 @@ class Predicate
/// occurred.
//------------------------------------------------------------------
T
WaitForSetValueBits(T bits, const TimeValue *abstime = nullptr)
WaitForSetValueBits(T bits, const std::chrono::microseconds &timeout = std::chrono::microseconds(0))
{
int err = 0;
// pthread_cond_timedwait() or pthread_cond_wait() will atomically
// unlock the mutex and wait for the condition to be set. When either
// function returns, they will re-lock the mutex. We use an auto lock/unlock
// class (Mutex::Locker) to allow us to return at any point in this
// class (std::lock_guard) to allow us to return at any point in this
// function and not have to worry about unlocking the mutex.
Mutex::Locker locker(m_mutex);
std::unique_lock<std::mutex> lock(m_mutex);
#ifdef DB_PTHREAD_LOG_EVENTS
printf("%s (bits = 0x%8.8x, abstime = %p), m_value = 0x%8.8x\n", __FUNCTION__, bits, abstime, m_value);
printf("%s (bits = 0x%8.8x, timeout = %llu), m_value = 0x%8.8x\n", __FUNCTION__, bits, timeout.count(),
m_value);
#endif
while (err == 0 && ((m_value & bits) == 0))
while ((m_value & bits) == 0)
{
err = m_condition.Wait (m_mutex, abstime);
if (timeout == std::chrono::microseconds(0))
{
m_condition.wait(lock);
}
else
{
std::cv_status result = m_condition.wait_for(lock, timeout);
if (result == std::cv_status::timeout)
break;
}
}
#ifdef DB_PTHREAD_LOG_EVENTS
printf("%s (bits = 0x%8.8x), m_value = 0x%8.8x, returning 0x%8.8x\n", __FUNCTION__, bits, m_value, m_value & bits);
Expand Down Expand Up @@ -262,23 +272,31 @@ class Predicate
/// unrecoverable error occurs.
//------------------------------------------------------------------
T
WaitForResetValueBits(T bits, const TimeValue *abstime = nullptr)
WaitForResetValueBits(T bits, const std::chrono::microseconds &timeout = std::chrono::microseconds(0))
{
int err = 0;

// pthread_cond_timedwait() or pthread_cond_wait() will atomically
// unlock the mutex and wait for the condition to be set. When either
// function returns, they will re-lock the mutex. We use an auto lock/unlock
// class (Mutex::Locker) to allow us to return at any point in this
// class (std::lock_guard) to allow us to return at any point in this
// function and not have to worry about unlocking the mutex.
Mutex::Locker locker(m_mutex);
std::unique_lock<std::mutex> lock(m_mutex);

#ifdef DB_PTHREAD_LOG_EVENTS
printf("%s (bits = 0x%8.8x, abstime = %p), m_value = 0x%8.8x\n", __FUNCTION__, bits, abstime, m_value);
printf("%s (bits = 0x%8.8x, timeout = %llu), m_value = 0x%8.8x\n", __FUNCTION__, bits, timeout.count(),
m_value);
#endif
while (err == 0 && ((m_value & bits) != 0))
while ((m_value & bits) != 0)
{
err = m_condition.Wait (m_mutex, abstime);
if (timeout == std::chrono::microseconds(0))
{
m_condition.wait(lock);
}
else
{
std::cv_status result = m_condition.wait_for(lock, timeout);
if (result == std::cv_status::timeout)
break;
}
}

#ifdef DB_PTHREAD_LOG_EVENTS
Expand Down Expand Up @@ -317,25 +335,39 @@ class Predicate
/// @li \b false otherwise
//------------------------------------------------------------------
bool
WaitForValueEqualTo(T value, const TimeValue *abstime = nullptr, bool *timed_out = nullptr)
WaitForValueEqualTo(T value, const std::chrono::microseconds &timeout = std::chrono::microseconds(0),
bool *timed_out = nullptr)
{
int err = 0;
// pthread_cond_timedwait() or pthread_cond_wait() will atomically
// unlock the mutex and wait for the condition to be set. When either
// function returns, they will re-lock the mutex. We use an auto lock/unlock
// class (Mutex::Locker) to allow us to return at any point in this
// class (std::lock_guard) to allow us to return at any point in this
// function and not have to worry about unlocking the mutex.
Mutex::Locker locker(m_mutex);
std::unique_lock<std::mutex> lock(m_mutex);

#ifdef DB_PTHREAD_LOG_EVENTS
printf("%s (value = 0x%8.8x, abstime = %p), m_value = 0x%8.8x\n", __FUNCTION__, value, abstime, m_value);
printf("%s (value = 0x%8.8x, timeout = %llu), m_value = 0x%8.8x\n", __FUNCTION__, value, timeout.count(),
m_value);
#endif
if (timed_out)
*timed_out = false;

while (err == 0 && m_value != value)
while (m_value != value)
{
err = m_condition.Wait (m_mutex, abstime, timed_out);
if (timeout == std::chrono::microseconds(0))
{
m_condition.wait(lock);
}
else
{
std::cv_status result = m_condition.wait_for(lock, timeout);
if (result == std::cv_status::timeout)
{
if (timed_out)
*timed_out = true;
break;
}
}
}

return m_value == value;
Expand Down Expand Up @@ -378,26 +410,39 @@ class Predicate
//------------------------------------------------------------------
bool
WaitForValueEqualToAndSetValueTo(T wait_value, T new_value,
const TimeValue *abstime = nullptr,
const std::chrono::microseconds &timeout = std::chrono::microseconds(0),
bool *timed_out = nullptr)
{
int err = 0;
// pthread_cond_timedwait() or pthread_cond_wait() will atomically
// unlock the mutex and wait for the condition to be set. When either
// function returns, they will re-lock the mutex. We use an auto lock/unlock
// class (Mutex::Locker) to allow us to return at any point in this
// class (std::lock_guard) to allow us to return at any point in this
// function and not have to worry about unlocking the mutex.
Mutex::Locker locker(m_mutex);
std::unique_lock<std::mutex> lock(m_mutex);

#ifdef DB_PTHREAD_LOG_EVENTS
printf("%s (wait_value = 0x%8.8x, new_value = 0x%8.8x, abstime = %p), m_value = 0x%8.8x\n", __FUNCTION__, wait_value, new_value, abstime, m_value);
printf("%s (wait_value = 0x%8.8x, new_value = 0x%8.8x, timeout = %llu), m_value = 0x%8.8x\n", __FUNCTION__,
wait_value, new_value, timeout.count(), m_value);
#endif
if (timed_out)
*timed_out = false;

while (err == 0 && m_value != wait_value)
while (m_value != wait_value)
{
err = m_condition.Wait (m_mutex, abstime, timed_out);
if (timeout == std::chrono::microseconds(0))
{
m_condition.wait(lock);
}
else
{
std::cv_status result = m_condition.wait_for(m_mutex, timeout);
if (result == std::cv_status::timeout)
{
if (timed_out)
*timed_out = true;
break;
}
}
}

if (m_value == wait_value)
Expand Down Expand Up @@ -438,21 +483,31 @@ class Predicate
/// @li \b false otherwise
//------------------------------------------------------------------
bool
WaitForValueNotEqualTo(T value, T &new_value, const TimeValue *abstime = nullptr)
WaitForValueNotEqualTo(T value, T &new_value,
const std::chrono::microseconds &timeout = std::chrono::microseconds(0))
{
int err = 0;
// pthread_cond_timedwait() or pthread_cond_wait() will atomically
// unlock the mutex and wait for the condition to be set. When either
// function returns, they will re-lock the mutex. We use an auto lock/unlock
// class (Mutex::Locker) to allow us to return at any point in this
// class (std::lock_guard) to allow us to return at any point in this
// function and not have to worry about unlocking the mutex.
Mutex::Locker locker(m_mutex);
std::unique_lock<std::mutex> lock(m_mutex);
#ifdef DB_PTHREAD_LOG_EVENTS
printf("%s (value = 0x%8.8x, abstime = %p), m_value = 0x%8.8x\n", __FUNCTION__, value, abstime, m_value);
printf("%s (value = 0x%8.8x, timeout = %llu), m_value = 0x%8.8x\n", __FUNCTION__, value, timeout.count(),
m_value);
#endif
while (err == 0 && m_value == value)
while (m_value == value)
{
err = m_condition.Wait (m_mutex, abstime);
if (timeout == std::chrono::microseconds(0))
{
m_condition.wait(lock);
}
else
{
std::cv_status result = m_condition.wait_for(lock, timeout);
if (result == std::cv_status::timeout)
break;
}
}

if (m_value != value)
Expand All @@ -469,8 +524,9 @@ class Predicate
// blocking between the main thread and the spotlight index thread.
//----------------------------------------------------------------------
T m_value; ///< The templatized value T that we are protecting access to
mutable Mutex m_mutex; ///< The mutex to use when accessing the data
Condition m_condition; ///< The pthread condition variable to use for signaling that data available or changed.
mutable std::mutex m_mutex; ///< The mutex to use when accessing the data
std::condition_variable
m_condition; ///< The pthread condition variable to use for signaling that data available or changed.

private:
//------------------------------------------------------------------
Expand All @@ -496,7 +552,7 @@ class Predicate
printf("%s (old_value = 0x%8.8x, broadcast_type = %i) m_value = 0x%8.8x, broadcast = %u\n", __FUNCTION__, old_value, broadcast_type, m_value, broadcast);
#endif
if (broadcast)
m_condition.Broadcast();
m_condition.notify_all();
}

DISALLOW_COPY_AND_ASSIGN(Predicate);
Expand Down
1 change: 0 additions & 1 deletion lldb/include/lldb/Host/ProcessRunLock.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
// Other libraries and framework includes
// Project includes
#include "lldb/lldb-defines.h"
#include "lldb/Host/Condition.h"

//----------------------------------------------------------------------
/// Enumerations for broadcasting.
Expand Down
24 changes: 10 additions & 14 deletions lldb/include/lldb/Target/Process.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <limits.h>

// C++ Includes
#include <chrono>
#include <list>
#include <memory>
#include <mutex>
Expand Down Expand Up @@ -2920,12 +2921,9 @@ class Process :
// function releases the run lock after the stop. Setting use_run_lock to false
// will avoid this behavior.
lldb::StateType
WaitForProcessToStop(const TimeValue *timeout,
lldb::EventSP *event_sp_ptr = nullptr,
bool wait_always = true,
lldb::ListenerSP hijack_listener = lldb::ListenerSP(),
Stream *stream = nullptr,
bool use_run_lock = true);
WaitForProcessToStop(const std::chrono::microseconds &timeout, lldb::EventSP *event_sp_ptr = nullptr,
bool wait_always = true, lldb::ListenerSP hijack_listener = lldb::ListenerSP(),
Stream *stream = nullptr, bool use_run_lock = true);

uint32_t
GetIOHandlerID () const
Expand All @@ -2947,8 +2945,7 @@ class Process :
SyncIOHandler (uint32_t iohandler_id, uint64_t timeout_msec);

lldb::StateType
WaitForStateChangedEvents(const TimeValue *timeout,
lldb::EventSP &event_sp,
WaitForStateChangedEvents(const std::chrono::microseconds &timeout, lldb::EventSP &event_sp,
lldb::ListenerSP hijack_listener); // Pass an empty ListenerSP to use builtin listener

//--------------------------------------------------------------------------------------
Expand Down Expand Up @@ -3538,21 +3535,20 @@ class Process :
HaltPrivate();

lldb::StateType
WaitForProcessStopPrivate (const TimeValue *timeout, lldb::EventSP &event_sp);
WaitForProcessStopPrivate(const std::chrono::microseconds &timeout, lldb::EventSP &event_sp);

// This waits for both the state change broadcaster, and the control broadcaster.
// If control_only, it only waits for the control broadcaster.

bool
WaitForEventsPrivate (const TimeValue *timeout, lldb::EventSP &event_sp, bool control_only);
WaitForEventsPrivate(const std::chrono::microseconds &timeout, lldb::EventSP &event_sp, bool control_only);

lldb::StateType
WaitForStateChangedEventsPrivate (const TimeValue *timeout, lldb::EventSP &event_sp);
WaitForStateChangedEventsPrivate(const std::chrono::microseconds &timeout, lldb::EventSP &event_sp);

lldb::StateType
WaitForState (const TimeValue *timeout,
const lldb::StateType *match_states,
const uint32_t num_match_states);
WaitForState(const std::chrono::microseconds &timeout, const lldb::StateType *match_states,
const uint32_t num_match_states);

size_t
WriteMemoryPrivate (lldb::addr_t addr, const void *buf, size_t size, Error &error);
Expand Down
31 changes: 9 additions & 22 deletions lldb/source/API/SBListener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include "lldb/Core/Listener.h"
#include "lldb/Core/Log.h"
#include "lldb/Core/StreamString.h"
#include "lldb/Host/TimeValue.h"


using namespace lldb;
Expand Down Expand Up @@ -202,15 +201,14 @@ SBListener::WaitForEvent (uint32_t timeout_secs, SBEvent &event)

if (m_opaque_sp)
{
TimeValue time_value;
std::chrono::microseconds timeout = std::chrono::microseconds(0);
if (timeout_secs != UINT32_MAX)
{
assert (timeout_secs != 0); // Take this out after all calls with timeout set to zero have been removed....
time_value = TimeValue::Now();
time_value.OffsetWithSeconds (timeout_secs);
timeout = std::chrono::seconds(timeout_secs);
}
EventSP event_sp;
if (m_opaque_sp->WaitForEvent (time_value.IsValid() ? &time_value : NULL, event_sp))
if (m_opaque_sp->WaitForEvent(timeout, event_sp))
{
event.reset (event_sp);
success = true;
Expand Down Expand Up @@ -247,16 +245,11 @@ SBListener::WaitForEventForBroadcaster
{
if (m_opaque_sp && broadcaster.IsValid())
{
TimeValue time_value;
std::chrono::microseconds timeout = std::chrono::microseconds(0);
if (num_seconds != UINT32_MAX)
{
time_value = TimeValue::Now();
time_value.OffsetWithSeconds (num_seconds);
}
timeout = std::chrono::seconds(num_seconds);
EventSP event_sp;
if (m_opaque_sp->WaitForEventForBroadcaster (time_value.IsValid() ? &time_value : NULL,
broadcaster.get(),
event_sp))
if (m_opaque_sp->WaitForEventForBroadcaster(timeout, broadcaster.get(), event_sp))
{
event.reset (event_sp);
return true;
Expand All @@ -278,17 +271,11 @@ SBListener::WaitForEventForBroadcasterWithType
{
if (m_opaque_sp && broadcaster.IsValid())
{
TimeValue time_value;
std::chrono::microseconds timeout = std::chrono::microseconds(0);
if (num_seconds != UINT32_MAX)
{
time_value = TimeValue::Now();
time_value.OffsetWithSeconds (num_seconds);
}
timeout = std::chrono::seconds(num_seconds);
EventSP event_sp;
if (m_opaque_sp->WaitForEventForBroadcasterWithType (time_value.IsValid() ? &time_value : NULL,
broadcaster.get(),
event_type_mask,
event_sp))
if (m_opaque_sp->WaitForEventForBroadcasterWithType(timeout, broadcaster.get(), event_type_mask, event_sp))
{
event.reset (event_sp);
return true;
Expand Down
14 changes: 5 additions & 9 deletions lldb/source/Core/Communication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,18 +156,14 @@ Communication::Read (void *dst, size_t dst_len, uint32_t timeout_usec, Connectio
status = eConnectionStatusNoConnection;
return 0;
}
// Set the timeout appropriately
TimeValue timeout_time;
if (timeout_usec != UINT32_MAX)
{
timeout_time = TimeValue::Now();
timeout_time.OffsetWithMicroSeconds (timeout_usec);
}

ListenerSP listener_sp(Listener::MakeListener("Communication::Read"));
listener_sp->StartListeningForEvents (this, eBroadcastBitReadThreadGotBytes | eBroadcastBitReadThreadDidExit);
EventSP event_sp;
while (listener_sp->WaitForEvent (timeout_time.IsValid() ? &timeout_time : nullptr, event_sp))
std::chrono::microseconds timeout = std::chrono::microseconds(0);
if (timeout_usec != UINT32_MAX)
timeout = std::chrono::microseconds(timeout_usec);
while (listener_sp->WaitForEvent(timeout, event_sp))
{
const uint32_t event_type = event_sp->GetType();
if (event_type & eBroadcastBitReadThreadGotBytes)
Expand Down Expand Up @@ -439,7 +435,7 @@ Communication::SynchronizeWithReadThread ()

// Wait for the synchronization event.
EventSP event_sp;
listener_sp->WaitForEvent(nullptr, event_sp);
listener_sp->WaitForEvent(std::chrono::microseconds(0), event_sp);
}

void
Expand Down
4 changes: 2 additions & 2 deletions lldb/source/Core/Debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1608,7 +1608,7 @@ Debugger::DefaultEventHandler()
while (!done)
{
EventSP event_sp;
if (listener_sp->WaitForEvent(nullptr, event_sp))
if (listener_sp->WaitForEvent(std::chrono::microseconds(0), event_sp))
{
if (event_sp)
{
Expand Down Expand Up @@ -1705,7 +1705,7 @@ Debugger::StartEventHandlerThread()
// eBroadcastBitEventThreadIsListening so we don't need to check the event, we just need
// to wait an infinite amount of time for it (nullptr timeout as the first parameter)
lldb::EventSP event_sp;
listener_sp->WaitForEvent(nullptr, event_sp);
listener_sp->WaitForEvent(std::chrono::microseconds(0), event_sp);
}
return m_event_handler_thread.IsJoinable();
}
Expand Down
113 changes: 53 additions & 60 deletions lldb/source/Core/Listener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include "lldb/Core/Log.h"
#include "lldb/Core/StreamString.h"
#include "lldb/Core/Event.h"
#include "lldb/Host/TimeValue.h"

using namespace lldb;
using namespace lldb_private;
Expand All @@ -41,7 +40,7 @@ namespace
} // anonymous namespace

Listener::Listener(const char *name)
: m_name(name), m_broadcasters(), m_broadcasters_mutex(), m_events(), m_events_mutex(Mutex::eMutexTypeNormal)
: m_name(name), m_broadcasters(), m_broadcasters_mutex(), m_events(), m_events_mutex()
{
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
if (log != nullptr)
Expand All @@ -63,7 +62,7 @@ void
Listener::Clear()
{
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
std::lock_guard<std::recursive_mutex> guard(m_broadcasters_mutex);
std::lock_guard<std::recursive_mutex> broadcasters_guard(m_broadcasters_mutex);
broadcaster_collection::iterator pos, end = m_broadcasters.end();
for (pos = m_broadcasters.begin(); pos != end; ++pos)
{
Expand All @@ -73,7 +72,7 @@ Listener::Clear()
}
m_broadcasters.clear();

Mutex::Locker event_locker(m_events_mutex);
std::lock_guard<std::mutex> events_guard(m_events_mutex);
m_events.clear();
size_t num_managers = m_broadcaster_managers.size();

Expand All @@ -96,7 +95,7 @@ Listener::StartListeningForEvents (Broadcaster* broadcaster, uint32_t event_mask
// Scope for "locker"
// Tell the broadcaster to add this object as a listener
{
std::lock_guard<std::recursive_mutex> guard(m_broadcasters_mutex);
std::lock_guard<std::recursive_mutex> broadcasters_guard(m_broadcasters_mutex);
Broadcaster::BroadcasterImplWP impl_wp(broadcaster->GetBroadcasterImpl());
m_broadcasters.insert(std::make_pair(impl_wp, BroadcasterInfo(event_mask)));
}
Expand All @@ -123,7 +122,7 @@ Listener::StartListeningForEvents (Broadcaster* broadcaster, uint32_t event_mask
// Scope for "locker"
// Tell the broadcaster to add this object as a listener
{
std::lock_guard<std::recursive_mutex> guard(m_broadcasters_mutex);
std::lock_guard<std::recursive_mutex> broadcasters_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)));
Expand Down Expand Up @@ -154,7 +153,7 @@ Listener::StopListeningForEvents (Broadcaster* broadcaster, uint32_t event_mask)
{
// Scope for "locker"
{
std::lock_guard<std::recursive_mutex> guard(m_broadcasters_mutex);
std::lock_guard<std::recursive_mutex> broadcasters_guard(m_broadcasters_mutex);
m_broadcasters.erase (broadcaster->GetBroadcasterImpl());
}
// Remove the broadcaster from our set of broadcasters
Expand All @@ -171,13 +170,13 @@ Listener::BroadcasterWillDestruct (Broadcaster *broadcaster)
{
// Scope for "broadcasters_locker"
{
std::lock_guard<std::recursive_mutex> guard(m_broadcasters_mutex);
std::lock_guard<std::recursive_mutex> broadcasters_guard(m_broadcasters_mutex);
m_broadcasters.erase (broadcaster->GetBroadcasterImpl());
}

// Scope for "event_locker"
{
Mutex::Locker event_locker(m_events_mutex);
std::lock_guard<std::mutex> events_guard(m_events_mutex);
// Remove all events for this broadcaster object.
event_collection::iterator pos = m_events.begin();
while (pos != m_events.end())
Expand Down Expand Up @@ -212,9 +211,9 @@ Listener::AddEvent (EventSP &event_sp)
static_cast<void*>(this), m_name.c_str(),
static_cast<void*>(event_sp.get()));

Mutex::Locker locker(m_events_mutex);
std::lock_guard<std::mutex> guard(m_events_mutex);
m_events.push_back (event_sp);
m_events_condition.Broadcast();
m_events_condition.notify_all();
}

class EventBroadcasterMatches
Expand Down Expand Up @@ -279,15 +278,11 @@ class EventMatcher
};

bool
Listener::FindNextEventInternal
(
Mutex::Locker& lock,
Broadcaster *broadcaster, // nullptr for any broadcaster
const ConstString *broadcaster_names, // nullptr for any event
uint32_t num_broadcaster_names,
uint32_t event_type_mask,
EventSP &event_sp,
bool remove)
Listener::FindNextEventInternal(std::unique_lock<std::mutex> &lock,
Broadcaster *broadcaster, // nullptr for any broadcaster
const ConstString *broadcaster_names, // nullptr for any event
uint32_t num_broadcaster_names, uint32_t event_type_mask, EventSP &event_sp,
bool remove)
{
// NOTE: callers of this function must lock m_events_mutex using a Mutex::Locker
// and pass the locker as the first argument. m_events_mutex is no longer recursive.
Expand Down Expand Up @@ -325,7 +320,7 @@ Listener::FindNextEventInternal
// Unlock the event queue here. We've removed this event and are about to return
// it so it should be okay to get the next event off the queue here - and it might
// be useful to do that in the "DoOnRemoval".
lock.Unlock();
lock.unlock();
event_sp->DoOnRemoval();
}
return true;
Expand All @@ -338,29 +333,29 @@ Listener::FindNextEventInternal
Event *
Listener::PeekAtNextEvent ()
{
Mutex::Locker lock(m_events_mutex);
std::unique_lock<std::mutex> guard(m_events_mutex);
EventSP event_sp;
if (FindNextEventInternal(lock, nullptr, nullptr, 0, 0, event_sp, false))
if (FindNextEventInternal(guard, nullptr, nullptr, 0, 0, event_sp, false))
return event_sp.get();
return nullptr;
}

Event *
Listener::PeekAtNextEventForBroadcaster (Broadcaster *broadcaster)
{
Mutex::Locker lock(m_events_mutex);
std::unique_lock<std::mutex> guard(m_events_mutex);
EventSP event_sp;
if (FindNextEventInternal(lock, broadcaster, nullptr, 0, 0, event_sp, false))
if (FindNextEventInternal(guard, broadcaster, nullptr, 0, 0, event_sp, false))
return event_sp.get();
return nullptr;
}

Event *
Listener::PeekAtNextEventForBroadcasterWithType (Broadcaster *broadcaster, uint32_t event_type_mask)
{
Mutex::Locker lock(m_events_mutex);
std::unique_lock<std::mutex> guard(m_events_mutex);
EventSP event_sp;
if (FindNextEventInternal(lock, broadcaster, nullptr, 0, event_type_mask, event_sp, false))
if (FindNextEventInternal(guard, broadcaster, nullptr, 0, event_type_mask, event_sp, false))
return event_sp.get();
return nullptr;
}
Expand All @@ -372,8 +367,9 @@ Listener::GetNextEventInternal(Broadcaster *broadcaster, // nullptr
uint32_t event_type_mask,
EventSP &event_sp)
{
Mutex::Locker lock(m_events_mutex);
return FindNextEventInternal (lock, broadcaster, broadcaster_names, num_broadcaster_names, event_type_mask, event_sp, true);
std::unique_lock<std::mutex> guard(m_events_mutex);
return FindNextEventInternal(guard, broadcaster, broadcaster_names, num_broadcaster_names, event_type_mask,
event_sp, true);
}

bool
Expand All @@ -395,20 +391,17 @@ Listener::GetNextEventForBroadcasterWithType (Broadcaster *broadcaster, uint32_t
}

bool
Listener::WaitForEventsInternal(const TimeValue *timeout,
Listener::WaitForEventsInternal(const std::chrono::microseconds &timeout,
Broadcaster *broadcaster, // nullptr for any broadcaster
const ConstString *broadcaster_names, // nullptr for any event
uint32_t num_broadcaster_names,
uint32_t event_type_mask,
EventSP &event_sp)
uint32_t num_broadcaster_names, uint32_t event_type_mask, EventSP &event_sp)
{
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EVENTS));
if (log != nullptr)
log->Printf ("%p Listener::WaitForEventsInternal (timeout = { %p }) for %s",
static_cast<void*>(this), static_cast<const void*>(timeout),
m_name.c_str());
log->Printf("%p Listener::WaitForEventsInternal (timeout = %llu us) for %s", static_cast<void *>(this),
static_cast<unsigned long long>(timeout.count()), m_name.c_str());

Mutex::Locker lock(m_events_mutex);
std::unique_lock<std::mutex> lock(m_events_mutex);

while (true)
{
Expand All @@ -418,23 +411,26 @@ Listener::WaitForEventsInternal(const TimeValue *timeout,
}
else
{
bool timed_out = false;
if (m_events_condition.Wait(m_events_mutex, timeout, &timed_out) != 0)
std::cv_status result = std::cv_status::no_timeout;
if (timeout == std::chrono::microseconds(0))
m_events_condition.wait(lock);
else
result = m_events_condition.wait_for(lock, timeout);

if (result == std::cv_status::timeout)
{
if (timed_out)
{
log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EVENTS);
if (log != nullptr)
log->Printf ("%p Listener::WaitForEventsInternal() timed out for %s",
static_cast<void*>(this), m_name.c_str());
}
else
{
log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EVENTS);
if (log != nullptr)
log->Printf ("%p Listener::WaitForEventsInternal() unknown error for %s",
static_cast<void*>(this), m_name.c_str());
}
log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EVENTS);
if (log)
log->Printf("%p Listener::WaitForEventsInternal() timed out for %s", static_cast<void *>(this),
m_name.c_str());
return false;
}
else if (result != std::cv_status::no_timeout)
{
log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EVENTS);
if (log)
log->Printf("%p Listener::WaitForEventsInternal() unknown error for %s", static_cast<void *>(this),
m_name.c_str());
return false;
}
}
Expand All @@ -444,24 +440,21 @@ Listener::WaitForEventsInternal(const TimeValue *timeout,
}

bool
Listener::WaitForEventForBroadcasterWithType(const TimeValue *timeout,
Broadcaster *broadcaster,
uint32_t event_type_mask,
EventSP &event_sp)
Listener::WaitForEventForBroadcasterWithType(const std::chrono::microseconds &timeout, Broadcaster *broadcaster,
uint32_t event_type_mask, EventSP &event_sp)
{
return WaitForEventsInternal(timeout, broadcaster, nullptr, 0, event_type_mask, event_sp);
}

bool
Listener::WaitForEventForBroadcaster(const TimeValue *timeout,
Broadcaster *broadcaster,
Listener::WaitForEventForBroadcaster(const std::chrono::microseconds &timeout, Broadcaster *broadcaster,
EventSP &event_sp)
{
return WaitForEventsInternal(timeout, broadcaster, nullptr, 0, 0, event_sp);
}

bool
Listener::WaitForEvent (const TimeValue *timeout, EventSP &event_sp)
Listener::WaitForEvent(const std::chrono::microseconds &timeout, EventSP &event_sp)
{
return WaitForEventsInternal(timeout, nullptr, nullptr, 0, 0, event_sp);
}
Expand Down
4 changes: 0 additions & 4 deletions lldb/source/Host/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ macro(add_host_subdirectory group)
endmacro()

add_host_subdirectory(common
common/Condition.cpp
common/File.cpp
common/FileCache.cpp
common/FileSpec.cpp
Expand All @@ -17,7 +16,6 @@ add_host_subdirectory(common
common/HostThread.cpp
common/IOObject.cpp
common/LockFileBase.cpp
common/Mutex.cpp
common/MonitoringProcessLauncher.cpp
common/NativeBreakpoint.cpp
common/NativeBreakpointList.cpp
Expand Down Expand Up @@ -60,7 +58,6 @@ add_host_subdirectory(posix

if (CMAKE_SYSTEM_NAME MATCHES "Windows")
add_host_subdirectory(windows
windows/Condition.cpp
windows/ConnectionGenericFileWindows.cpp
windows/EditLineWin.cpp
windows/FileSystem.cpp
Expand All @@ -69,7 +66,6 @@ if (CMAKE_SYSTEM_NAME MATCHES "Windows")
windows/HostProcessWindows.cpp
windows/HostThreadWindows.cpp
windows/LockFileWindows.cpp
windows/Mutex.cpp
windows/PipeWindows.cpp
windows/ProcessLauncherWindows.cpp
windows/ProcessRunLock.cpp
Expand Down
108 changes: 0 additions & 108 deletions lldb/source/Host/common/Condition.cpp

This file was deleted.

12 changes: 2 additions & 10 deletions lldb/source/Host/common/Host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -620,25 +620,17 @@ Host::RunShellCommand(const Args &args,

if (error.Success())
{
TimeValue *timeout_ptr = nullptr;
TimeValue timeout_time(TimeValue::Now());
if (timeout_sec > 0) {
timeout_time.OffsetWithSeconds(timeout_sec);
timeout_ptr = &timeout_time;
}
bool timed_out = false;
shell_info_sp->process_reaped.WaitForValueEqualTo(true, timeout_ptr, &timed_out);
shell_info_sp->process_reaped.WaitForValueEqualTo(true, std::chrono::seconds(timeout_sec), &timed_out);
if (timed_out)
{
error.SetErrorString("timed out waiting for shell command to complete");

// Kill the process since it didn't complete within the timeout specified
Kill (pid, SIGKILL);
// Wait for the monitor callback to get the message
timeout_time = TimeValue::Now();
timeout_time.OffsetWithSeconds(1);
timed_out = false;
shell_info_sp->process_reaped.WaitForValueEqualTo(true, &timeout_time, &timed_out);
shell_info_sp->process_reaped.WaitForValueEqualTo(true, std::chrono::seconds(1), &timed_out);
}
else
{
Expand Down
398 changes: 0 additions & 398 deletions lldb/source/Host/common/Mutex.cpp

This file was deleted.

6 changes: 1 addition & 5 deletions lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -877,11 +877,7 @@ ConnectionFileDescriptor::GetListeningPort(uint32_t timeout_sec)
if (timeout_sec == UINT32_MAX)
m_port_predicate.WaitForValueNotEqualTo(0, bound_port);
else
{
TimeValue timeout = TimeValue::Now();
timeout.OffsetWithSeconds(timeout_sec);
m_port_predicate.WaitForValueNotEqualTo(0, bound_port, &timeout);
}
m_port_predicate.WaitForValueNotEqualTo(0, bound_port, std::chrono::seconds(timeout_sec));
return bound_port;
}

Expand Down
98 changes: 0 additions & 98 deletions lldb/source/Host/windows/Condition.cpp

This file was deleted.

109 changes: 0 additions & 109 deletions lldb/source/Host/windows/Mutex.cpp

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,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"

Expand Down
3 changes: 2 additions & 1 deletion lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,8 @@ PlatformLinux::DebugProcess (ProcessLaunchInfo &launch_info,
// Handle the hijacking of process events.
if (listener_sp)
{
const StateType state = process_sp->WaitForProcessToStop (NULL, NULL, false, listener_sp);
const StateType state =
process_sp->WaitForProcessToStop(std::chrono::microseconds(0), NULL, false, listener_sp);

if (state == eStateStopped)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,10 @@ CommunicationKDP::GetSequenceMutex(std::unique_lock<std::recursive_mutex> &lock)
return (lock = std::unique_lock<std::recursive_mutex>(m_sequence_mutex, std::try_to_lock)).owns_lock();
}


bool
CommunicationKDP::WaitForNotRunningPrivate (const TimeValue *timeout_ptr)
CommunicationKDP::WaitForNotRunningPrivate(const std::chrono::microseconds &timeout)
{
return m_is_running.WaitForValueEqualTo (false, timeout_ptr, NULL);
return m_is_running.WaitForValueEqualTo(false, timoeut, NULL);
}

size_t
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ class CommunicationKDP : public lldb_private::Communication
uint32_t timeout_usec);

bool
WaitForNotRunningPrivate (const lldb_private::TimeValue *timeout_ptr);
WaitForNotRunningPrivate(const std::chrono::microseconds &timeout);

void
MakeRequestPacketHeader (CommandType request_type,
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -941,7 +941,7 @@ ProcessKDP::AsyncThread (void *arg)
if (log)
log->Printf ("ProcessKDP::AsyncThread (pid = %" PRIu64 ") listener.WaitForEvent (NULL, event_sp)...",
pid);
if (listener_sp->WaitForEvent (NULL, event_sp))
if (listener_sp->WaitForEvent(stsd::chrono::micrseconds(0), event_sp))
{
uint32_t event_type = event_sp->GetType();
if (log)
Expand Down
61 changes: 30 additions & 31 deletions lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,23 +152,22 @@ GDBRemoteCommunication::History::Dump (Log *log) const
//----------------------------------------------------------------------
// GDBRemoteCommunication constructor
//----------------------------------------------------------------------
GDBRemoteCommunication::GDBRemoteCommunication(const char *comm_name,
const char *listener_name) :
Communication(comm_name),
GDBRemoteCommunication::GDBRemoteCommunication(const char *comm_name, const char *listener_name)
: Communication(comm_name),
#ifdef LLDB_CONFIGURATION_DEBUG
m_packet_timeout (1000),
m_packet_timeout(1000),
#else
m_packet_timeout (1),
m_packet_timeout(1),
#endif
m_echo_number(0),
m_supports_qEcho (eLazyBoolCalculate),
m_sequence_mutex (Mutex::eMutexTypeRecursive),
m_public_is_running (false),
m_private_is_running (false),
m_history (512),
m_send_acks (true),
m_compression_type (CompressionType::None),
m_listen_url ()
m_echo_number(0),
m_supports_qEcho(eLazyBoolCalculate),
m_sequence_mutex(),
m_public_is_running(false),
m_private_is_running(false),
m_history(512),
m_send_acks(true),
m_compression_type(CompressionType::None),
m_listen_url()
{
}

Expand Down Expand Up @@ -229,7 +228,7 @@ GDBRemoteCommunication::SendNack ()
GDBRemoteCommunication::PacketResult
GDBRemoteCommunication::SendPacket (const char *payload, size_t payload_length)
{
Mutex::Locker locker(m_sequence_mutex);
std::lock_guard<std::recursive_mutex> guard(m_sequence_mutex);
return SendPacketNoLock (payload, payload_length);
}

Expand Down Expand Up @@ -323,20 +322,19 @@ GDBRemoteCommunication::GetAck ()
}

bool
GDBRemoteCommunication::GetSequenceMutex (Mutex::Locker& locker, const char *failure_message)
GDBRemoteCommunication::GetSequenceMutex(std::unique_lock<std::recursive_mutex> &lock, const char *failure_message)
{
if (IsRunning())
return locker.TryLock (m_sequence_mutex, failure_message);
return (lock = std::unique_lock<std::recursive_mutex>(m_sequence_mutex, std::try_to_lock)).owns_lock();

locker.Lock (m_sequence_mutex);
lock = std::unique_lock<std::recursive_mutex>(m_sequence_mutex);
return true;
}


bool
GDBRemoteCommunication::WaitForNotRunningPrivate (const TimeValue *timeout_ptr)
GDBRemoteCommunication::WaitForNotRunningPrivate(const std::chrono::microseconds &timeout)
{
return m_private_is_running.WaitForValueEqualTo (false, timeout_ptr, NULL);
return m_private_is_running.WaitForValueEqualTo(false, timeout, NULL);
}

GDBRemoteCommunication::PacketResult
Expand All @@ -356,20 +354,22 @@ GDBRemoteCommunication::ReadPacket (StringExtractorGDBRemote &response, uint32_t
GDBRemoteCommunication::PacketResult
GDBRemoteCommunication::PopPacketFromQueue (StringExtractorGDBRemote &response, uint32_t timeout_usec)
{
// Calculate absolute timeout value
TimeValue timeout = TimeValue::Now();
timeout.OffsetWithMicroSeconds(timeout_usec);
auto until = std::chrono::system_clock::now() + std::chrono::microseconds(timeout_usec);

do
while (true)
{
// scope for the mutex
{
// lock down the packet queue
Mutex::Locker locker(m_packet_queue_mutex);
std::unique_lock<std::mutex> lock(m_packet_queue_mutex);

// Wait on condition variable.
if (m_packet_queue.size() == 0)
m_condition_queue_not_empty.Wait(m_packet_queue_mutex, &timeout);
{
std::cv_status result = m_condition_queue_not_empty.wait_until(lock, until);
if (result == std::cv_status::timeout)
break;
}

if (m_packet_queue.size() > 0)
{
Expand All @@ -389,7 +389,7 @@ GDBRemoteCommunication::PopPacketFromQueue (StringExtractorGDBRemote &response,
return PacketResult::ErrorDisconnected;

// Loop while not timed out
} while (TimeValue::Now() < timeout);
}

return PacketResult::ErrorReplyTimeout;
}
Expand Down Expand Up @@ -1479,12 +1479,11 @@ void GDBRemoteCommunication::AppendBytesToCache (const uint8_t * bytes, size_t l
// scope for the mutex
{
// lock down the packet queue
Mutex::Locker locker(m_packet_queue_mutex);
std::lock_guard<std::mutex> guard(m_packet_queue_mutex);
// push a new packet into the queue
m_packet_queue.push(packet);
// Signal condition variable that we have a packet
m_condition_queue_not_empty.Signal();

m_condition_queue_not_empty.notify_one();
}
}

Expand Down
15 changes: 8 additions & 7 deletions lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

// C Includes
// C++ Includes
#include <condition_variable>
#include <mutex>
#include <string>
#include <queue>
#include <vector>
Expand All @@ -22,7 +24,6 @@
#include "lldb/Core/Communication.h"
#include "lldb/Core/Listener.h"
#include "lldb/Host/HostThread.h"
#include "lldb/Host/Mutex.h"
#include "lldb/Host/Predicate.h"
#include "lldb/Host/TimeValue.h"
#include "lldb/Interpreter/Args.h"
Expand Down Expand Up @@ -114,7 +115,7 @@ class GDBRemoteCommunication : public Communication
size_t payload_length);

bool
GetSequenceMutex(Mutex::Locker& locker, const char *failure_message = nullptr);
GetSequenceMutex(std::unique_lock<std::recursive_mutex> &lock, const char *failure_message = nullptr);

PacketType
CheckForPacket (const uint8_t *src,
Expand Down Expand Up @@ -285,9 +286,9 @@ class GDBRemoteCommunication : public Communication
uint32_t m_echo_number;
LazyBool m_supports_qEcho;
#ifdef ENABLE_MUTEX_ERROR_CHECKING
TrackingMutex m_sequence_mutex;
#error TrackingMutex is no longer supported
#else
Mutex m_sequence_mutex; // Restrict access to sending/receiving packets to a single thread at a time
std::recursive_mutex m_sequence_mutex; // Restrict access to sending/receiving packets to a single thread at a time
#endif
Predicate<bool> m_public_is_running;
Predicate<bool> m_private_is_running;
Expand Down Expand Up @@ -320,7 +321,7 @@ class GDBRemoteCommunication : public Communication
bool sync_on_timeout);

bool
WaitForNotRunningPrivate (const TimeValue *timeout_ptr);
WaitForNotRunningPrivate(const std::chrono::microseconds &timeout);

bool
CompressionIsEnabled ()
Expand Down Expand Up @@ -364,8 +365,8 @@ class GDBRemoteCommunication : public Communication

private:
std::queue<StringExtractorGDBRemote> m_packet_queue; // The packet queue
lldb_private::Mutex m_packet_queue_mutex; // Mutex for accessing queue
Condition m_condition_queue_not_empty; // Condition variable to wait for packets
std::mutex m_packet_queue_mutex; // Mutex for accessing queue
std::condition_variable m_condition_queue_not_empty; // Condition variable to wait for packets

HostThread m_listen_thread;
std::string m_listen_url;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -720,9 +720,10 @@ GDBRemoteCommunicationClient::SendPacketsAndConcatenateResponses
std::string &response_string
)
{
Mutex::Locker locker;
if (!GetSequenceMutex(locker,
"ProcessGDBRemote::SendPacketsAndConcatenateResponses() failed due to not getting the sequence mutex"))
std::unique_lock<std::recursive_mutex> lock;
if (!GetSequenceMutex(
lock,
"ProcessGDBRemote::SendPacketsAndConcatenateResponses() failed due to not getting the sequence mutex"))
{
Log *log (ProcessGDBRemoteLog::GetLogIfAnyCategoryIsSet (GDBR_LOG_PROCESS | GDBR_LOG_PACKETS));
if (log)
Expand Down Expand Up @@ -821,15 +822,15 @@ GDBRemoteCommunicationClient::SendPacketAndWaitForResponse
)
{
PacketResult packet_result = PacketResult::ErrorSendFailed;
Mutex::Locker locker;
std::unique_lock<std::recursive_mutex> lock;
Log *log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PROCESS));

// In order to stop async notifications from being processed in the middle of the
// send/receive sequence Hijack the broadcast. Then rebroadcast any events when we are done.
static ListenerSP hijack_listener_sp(Listener::MakeListener("lldb.NotifyHijacker"));
HijackBroadcaster(hijack_listener_sp, eBroadcastBitGdbReadThreadGotNotify);

if (GetSequenceMutex (locker))
if (GetSequenceMutex(lock))
{
packet_result = SendPacketAndWaitForResponseNoLock (payload, payload_length, response);
}
Expand All @@ -848,19 +849,22 @@ GDBRemoteCommunicationClient::SendPacketAndWaitForResponse
log->Printf ("async: async packet = %s", m_async_packet.c_str());

bool timed_out = false;
if (SendInterrupt(locker, 2, timed_out))
if (SendInterrupt(lock, 2, timed_out))
{
if (m_interrupt_sent)
{
m_interrupt_sent = false;
TimeValue timeout_time;
timeout_time = TimeValue::Now();
timeout_time.OffsetWithSeconds (m_packet_timeout);

std::chrono::time_point<std::chrono::system_clock> until;
until = std::chrono::system_clock::now() + std::chrono::seconds(m_packet_timeout);

if (log)
log->Printf ("async: sent interrupt");

if (m_async_packet_predicate.WaitForValueEqualTo (false, &timeout_time, &timed_out))
if (m_async_packet_predicate.WaitForValueEqualTo(
false, std::chrono::duration_cast<std::chrono::microseconds>(
until - std::chrono::system_clock::now()),
&timed_out))
{
if (log)
log->Printf ("async: got response");
Expand All @@ -876,7 +880,10 @@ GDBRemoteCommunicationClient::SendPacketAndWaitForResponse
}

// Make sure we wait until the continue packet has been sent again...
if (m_private_is_running.WaitForValueEqualTo (true, &timeout_time, &timed_out))
if (m_private_is_running.WaitForValueEqualTo(
true, std::chrono::duration_cast<std::chrono::microseconds>(
until - std::chrono::system_clock::now()),
&timed_out))
{
if (log)
{
Expand Down Expand Up @@ -1045,7 +1052,7 @@ GDBRemoteCommunicationClient::SendvContPacket
log->Printf("GDBRemoteCommunicationClient::%s ()", __FUNCTION__);

// we want to lock down packet sending while we continue
Mutex::Locker locker(m_sequence_mutex);
std::lock_guard<std::recursive_mutex> guard(m_sequence_mutex);

// here we broadcast this before we even send the packet!!
// this signals doContinue() to exit
Expand Down Expand Up @@ -1094,7 +1101,7 @@ GDBRemoteCommunicationClient::SendContinuePacketAndWaitForResponse
if (log)
log->Printf ("GDBRemoteCommunicationClient::%s ()", __FUNCTION__);

Mutex::Locker locker(m_sequence_mutex);
std::lock_guard<std::recursive_mutex> guard(m_sequence_mutex);
StateType state = eStateRunning;

m_public_is_running.SetValue (true, eBroadcastNever);
Expand Down Expand Up @@ -1394,8 +1401,8 @@ GDBRemoteCommunicationClient::SendAsyncSignal (int signo)
std::lock_guard<std::recursive_mutex> guard(m_async_mutex);
m_async_signal = signo;
bool timed_out = false;
Mutex::Locker locker;
if (SendInterrupt (locker, 1, timed_out))
std::unique_lock<std::recursive_mutex> lock;
if (SendInterrupt(lock, 1, timed_out))
return true;
m_async_signal = -1;
return false;
Expand All @@ -1412,20 +1419,16 @@ GDBRemoteCommunicationClient::SendAsyncSignal (int signo)
// (gdb remote protocol requires this), and do what we need to do, then resume.

bool
GDBRemoteCommunicationClient::SendInterrupt
(
Mutex::Locker& locker,
uint32_t seconds_to_wait_for_stop,
bool &timed_out
)
GDBRemoteCommunicationClient::SendInterrupt(std::unique_lock<std::recursive_mutex> &lock,
uint32_t seconds_to_wait_for_stop, bool &timed_out)
{
timed_out = false;
Log *log (ProcessGDBRemoteLog::GetLogIfAnyCategoryIsSet (GDBR_LOG_PROCESS | GDBR_LOG_PACKETS));

if (IsRunning())
{
// Only send an interrupt if our debugserver is running...
if (GetSequenceMutex (locker))
if (GetSequenceMutex(lock))
{
if (log)
log->Printf ("SendInterrupt () - got sequence mutex without having to interrupt");
Expand All @@ -1444,13 +1447,8 @@ GDBRemoteCommunicationClient::SendInterrupt
m_interrupt_sent = true;
if (seconds_to_wait_for_stop)
{
TimeValue timeout;
if (seconds_to_wait_for_stop)
{
timeout = TimeValue::Now();
timeout.OffsetWithSeconds (seconds_to_wait_for_stop);
}
if (m_private_is_running.WaitForValueEqualTo (false, &timeout, &timed_out))
if (m_private_is_running.WaitForValueEqualTo(false, std::chrono::seconds(seconds_to_wait_for_stop),
&timed_out))
{
if (log)
log->PutCString ("SendInterrupt () - sent interrupt, private state stopped");
Expand Down Expand Up @@ -3653,10 +3651,10 @@ size_t
GDBRemoteCommunicationClient::GetCurrentThreadIDs (std::vector<lldb::tid_t> &thread_ids,
bool &sequence_mutex_unavailable)
{
Mutex::Locker locker;
std::unique_lock<std::recursive_mutex> lock;
thread_ids.clear();
if (GetSequenceMutex (locker, "ProcessGDBRemote::UpdateThreadList() failed due to not getting the sequence mutex"))

if (GetSequenceMutex(lock, "ProcessGDBRemote::UpdateThreadList() failed due to not getting the sequence mutex"))
{
sequence_mutex_unavailable = false;
StringExtractorGDBRemote response;
Expand Down Expand Up @@ -4203,8 +4201,8 @@ GDBRemoteCommunicationClient::AvoidGPackets (ProcessGDBRemote *process)
bool
GDBRemoteCommunicationClient::ReadRegister(lldb::tid_t tid, uint32_t reg, StringExtractorGDBRemote &response)
{
Mutex::Locker locker;
if (GetSequenceMutex (locker, "Didn't get sequence mutex for p packet."))
std::unique_lock<std::recursive_mutex> lock;
if (GetSequenceMutex(lock, "Didn't get sequence mutex for p packet."))
{
const bool thread_suffix_supported = GetThreadSuffixSupported();

Expand All @@ -4228,8 +4226,8 @@ GDBRemoteCommunicationClient::ReadRegister(lldb::tid_t tid, uint32_t reg, String
bool
GDBRemoteCommunicationClient::ReadAllRegisters (lldb::tid_t tid, StringExtractorGDBRemote &response)
{
Mutex::Locker locker;
if (GetSequenceMutex (locker, "Didn't get sequence mutex for g packet."))
std::unique_lock<std::recursive_mutex> lock;
if (GetSequenceMutex(lock, "Didn't get sequence mutex for g packet."))
{
const bool thread_suffix_supported = GetThreadSuffixSupported();

Expand All @@ -4256,8 +4254,8 @@ GDBRemoteCommunicationClient::SaveRegisterState (lldb::tid_t tid, uint32_t &save
return false;

m_supports_QSaveRegisterState = eLazyBoolYes;
Mutex::Locker locker;
if (GetSequenceMutex (locker, "Didn't get sequence mutex for QSaveRegisterState."))
std::unique_lock<std::recursive_mutex> lock;
if (GetSequenceMutex(lock, "Didn't get sequence mutex for QSaveRegisterState."))
{
const bool thread_suffix_supported = GetThreadSuffixSupported();
if (thread_suffix_supported || SetCurrentThread(tid))
Expand Down Expand Up @@ -4298,9 +4296,9 @@ GDBRemoteCommunicationClient::RestoreRegisterState (lldb::tid_t tid, uint32_t sa
// order to be useful
if (m_supports_QSaveRegisterState == eLazyBoolNo)
return false;
Mutex::Locker locker;
if (GetSequenceMutex (locker, "Didn't get sequence mutex for QRestoreRegisterState."))

std::unique_lock<std::recursive_mutex> lock;
if (GetSequenceMutex(lock, "Didn't get sequence mutex for QRestoreRegisterState."))
{
const bool thread_suffix_supported = GetThreadSuffixSupported();
if (thread_suffix_supported || SetCurrentThread(tid))
Expand Down Expand Up @@ -4530,8 +4528,10 @@ GDBRemoteCommunicationClient::ServeSymbolLookups(lldb_private::Process *process)

if (m_supports_qSymbol && m_qSymbol_requests_done == false)
{
Mutex::Locker locker;
if (GetSequenceMutex(locker, "GDBRemoteCommunicationClient::ServeSymbolLookups() failed due to not getting the sequence mutex"))
std::unique_lock<std::recursive_mutex> lock;
if (GetSequenceMutex(
lock,
"GDBRemoteCommunicationClient::ServeSymbolLookups() failed due to not getting the sequence mutex"))
{
StreamString packet;
packet.PutCString ("qSymbol::");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,7 @@ class GDBRemoteCommunicationClient : public GDBRemoteCommunication
SendAsyncSignal (int signo);

bool
SendInterrupt (Mutex::Locker &locker,
uint32_t seconds_to_wait_for_stop,
bool &timed_out);
SendInterrupt(std::unique_lock<std::recursive_mutex> &lock, uint32_t seconds_to_wait_for_stop, bool &timed_out);

lldb::pid_t
GetCurrentProcessID (bool allow_lazy = true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,8 @@ GDBRemoteRegisterContext::WriteRegisterBytes (const RegisterInfo *reg_info, Data
reg_info->byte_size, // dst length
m_reg_data.GetByteOrder())) // dst byte order
{
Mutex::Locker locker;
if (gdb_comm.GetSequenceMutex (locker, "Didn't get sequence mutex for write register."))
std::unique_lock<std::recursive_mutex> lock;
if (gdb_comm.GetSequenceMutex(lock, "Didn't get sequence mutex for write register."))
{
const bool thread_suffix_supported = gdb_comm.GetThreadSuffixSupported();
ProcessSP process_sp (m_thread.GetProcess());
Expand Down Expand Up @@ -570,8 +570,8 @@ GDBRemoteRegisterContext::ReadAllRegisterValues (lldb::DataBufferSP &data_sp)

const bool use_g_packet = gdb_comm.AvoidGPackets ((ProcessGDBRemote *)process) == false;

Mutex::Locker locker;
if (gdb_comm.GetSequenceMutex (locker, "Didn't get sequence mutex for read all registers."))
std::unique_lock<std::recursive_mutex> lock;
if (gdb_comm.GetSequenceMutex(lock, "Didn't get sequence mutex for read all registers."))
{
SyncThreadState(process);

Expand Down Expand Up @@ -679,8 +679,8 @@ GDBRemoteRegisterContext::WriteAllRegisterValues (const lldb::DataBufferSP &data
const bool use_g_packet = gdb_comm.AvoidGPackets ((ProcessGDBRemote *)process) == false;
StringExtractorGDBRemote response;
Mutex::Locker locker;
if (gdb_comm.GetSequenceMutex (locker, "Didn't get sequence mutex for write all registers."))
std::unique_lock<std::recursive_mutex> lock;
if (gdb_comm.GetSequenceMutex(lock, "Didn't get sequence mutex for write all registers."))
{
const bool thread_suffix_supported = gdb_comm.GetThreadSuffixSupported();
ProcessSP process_sp (m_thread.GetProcess());
Expand Down
11 changes: 4 additions & 7 deletions lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1590,9 +1590,6 @@ ProcessGDBRemote::DoResume ()
else
{
EventSP event_sp;
TimeValue timeout;
timeout = TimeValue::Now();
timeout.OffsetWithSeconds (5);
if (!m_async_thread.IsJoinable())
{
error.SetErrorString ("Trying to resume but the async thread is dead.");
Expand All @@ -1603,7 +1600,7 @@ ProcessGDBRemote::DoResume ()

m_async_broadcaster.BroadcastEvent (eBroadcastBitAsyncContinue, new EventDataBytes (continue_packet.GetData(), continue_packet.GetSize()));

if (listener_sp->WaitForEvent (&timeout, event_sp) == false)
if (listener_sp->WaitForEvent(std::chrono::seconds(5), event_sp) == false)
{
error.SetErrorString("Resume timed out.");
if (log)
Expand Down Expand Up @@ -2717,7 +2714,7 @@ ProcessGDBRemote::DoHalt (bool &caused_stop)
Error error;

bool timed_out = false;
Mutex::Locker locker;
std::unique_lock<std::recursive_mutex> lock;

if (m_public_state.GetValue() == eStateAttaching)
{
Expand All @@ -2727,7 +2724,7 @@ ProcessGDBRemote::DoHalt (bool &caused_stop)
}
else
{
if (!m_gdb_comm.SendInterrupt (locker, 2, timed_out))
if (!m_gdb_comm.SendInterrupt(lock, 2, timed_out))
{
if (timed_out)
error.SetErrorString("timed out sending interrupt packet");
Expand Down Expand Up @@ -3860,7 +3857,7 @@ ProcessGDBRemote::AsyncThread (void *arg)
{
if (log)
log->Printf ("ProcessGDBRemote::%s (arg = %p, pid = %" PRIu64 ") listener.WaitForEvent (NULL, event_sp)...", __FUNCTION__, arg, process->GetID());
if (process->m_async_listener_sp->WaitForEvent (NULL, event_sp))
if (process->m_async_listener_sp->WaitForEvent(std::chrono::microseconds(0), event_sp))
{
const uint32_t event_type = event_sp->GetType();
if (event_sp->BroadcasterIs (&process->m_async_broadcaster))
Expand Down
Loading