Skip to content

Commit 2d6a9ec

Browse files
committed
Clean up vestigial remnants of locking primitives
This finally removes the use of the Mutex and Condition classes. This is an intricate patch as the Mutex and Condition classes were tied together. Furthermore, many places had slightly differing uses of time values. Convert timeout values to relative everywhere to permit the use of std::chrono::duration, which is required for the use of std::condition_variable's timeout. Adjust all Condition and related Mutex classes over to std::{,recursive_}mutex and std::condition_variable. This change primarily comes at the cost of breaking the TracingMutex which was based around the Mutex class. It would be possible to write a wrapper to provide similar functionality, but that is beyond the scope of this change. llvm-svn: 277011
1 parent 5ed2b4b commit 2d6a9ec

34 files changed

+404
-1605
lines changed

lldb/include/lldb/Core/Event.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
// C Includes
1414
// C++ Includes
15+
#include <chrono>
1516
#include <memory>
1617
#include <string>
1718

@@ -141,7 +142,8 @@ class EventDataReceipt : public EventData
141142
}
142143

143144
bool
144-
WaitForEventReceived (const TimeValue *abstime = nullptr, bool *timed_out = nullptr)
145+
WaitForEventReceived(const std::chrono::microseconds &abstime = std::chrono::microseconds(0),
146+
bool *timed_out = nullptr)
145147
{
146148
return m_predicate.WaitForValueEqualTo(true, abstime, timed_out);
147149
}

lldb/include/lldb/Core/Listener.h

+12-22
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
// C Includes
1414
// C++ Includes
15+
#include <chrono>
1516
#include <list>
1617
#include <map>
1718
#include <mutex>
@@ -21,8 +22,6 @@
2122
// Other libraries and framework includes
2223
// Project includes
2324
#include "lldb/lldb-private.h"
24-
#include "lldb/Core/Broadcaster.h"
25-
#include "lldb/Host/Condition.h"
2625
#include "lldb/Core/Event.h"
2726

2827
namespace lldb_private {
@@ -87,19 +86,15 @@ class Listener :
8786

8887
// Returns true if an event was received, false if we timed out.
8988
bool
90-
WaitForEvent (const TimeValue *timeout,
91-
lldb::EventSP &event_sp);
89+
WaitForEvent(const std::chrono::microseconds &timeout, lldb::EventSP &event_sp);
9290

9391
bool
94-
WaitForEventForBroadcaster (const TimeValue *timeout,
95-
Broadcaster *broadcaster,
96-
lldb::EventSP &event_sp);
92+
WaitForEventForBroadcaster(const std::chrono::microseconds &timeout, Broadcaster *broadcaster,
93+
lldb::EventSP &event_sp);
9794

9895
bool
99-
WaitForEventForBroadcasterWithType (const TimeValue *timeout,
100-
Broadcaster *broadcaster,
101-
uint32_t event_type_mask,
102-
lldb::EventSP &event_sp);
96+
WaitForEventForBroadcasterWithType(const std::chrono::microseconds &timeout, Broadcaster *broadcaster,
97+
uint32_t event_type_mask, lldb::EventSP &event_sp);
10398

10499
Event *
105100
PeekAtNextEvent ();
@@ -151,13 +146,10 @@ class Listener :
151146
typedef std::vector<lldb::BroadcasterManagerWP> broadcaster_manager_collection;
152147

153148
bool
154-
FindNextEventInternal(Mutex::Locker& lock,
149+
FindNextEventInternal(std::unique_lock<std::mutex> &lock,
155150
Broadcaster *broadcaster, // nullptr for any broadcaster
156151
const ConstString *sources, // nullptr for any event
157-
uint32_t num_sources,
158-
uint32_t event_type_mask,
159-
lldb::EventSP &event_sp,
160-
bool remove);
152+
uint32_t num_sources, uint32_t event_type_mask, lldb::EventSP &event_sp, bool remove);
161153

162154
bool
163155
GetNextEventInternal(Broadcaster *broadcaster, // nullptr for any broadcaster
@@ -167,19 +159,17 @@ class Listener :
167159
lldb::EventSP &event_sp);
168160

169161
bool
170-
WaitForEventsInternal(const TimeValue *timeout,
162+
WaitForEventsInternal(const std::chrono::microseconds &timeout,
171163
Broadcaster *broadcaster, // nullptr for any broadcaster
172164
const ConstString *sources, // nullptr for any event
173-
uint32_t num_sources,
174-
uint32_t event_type_mask,
175-
lldb::EventSP &event_sp);
165+
uint32_t num_sources, uint32_t event_type_mask, lldb::EventSP &event_sp);
176166

177167
std::string m_name;
178168
broadcaster_collection m_broadcasters;
179169
std::recursive_mutex m_broadcasters_mutex; // Protects m_broadcasters
180170
event_collection m_events;
181-
Mutex m_events_mutex; // Protects m_broadcasters and m_events
182-
Condition m_events_condition;
171+
std::mutex m_events_mutex; // Protects m_broadcasters and m_events
172+
std::condition_variable m_events_condition;
183173
broadcaster_manager_collection m_broadcaster_managers;
184174

185175
void

lldb/include/lldb/Core/ThreadSafeDenseMap.h

+11-16
Original file line numberDiff line numberDiff line change
@@ -12,54 +12,49 @@
1212

1313
// C Includes
1414
// C++ Includes
15+
#include <mutex>
1516

1617
// Other libraries and framework includes
1718
#include "llvm/ADT/DenseMap.h"
1819

1920
// Project includes
20-
#include "lldb/Host/Mutex.h"
2121

2222
namespace lldb_private {
2323

24-
template <typename _KeyType, typename _ValueType>
24+
template <typename _KeyType, typename _ValueType, typename _MutexType = std::mutex>
2525
class ThreadSafeDenseMap
2626
{
2727
public:
2828
typedef llvm::DenseMap<_KeyType,_ValueType> LLVMMapType;
29-
30-
ThreadSafeDenseMap(unsigned map_initial_capacity = 0,
31-
Mutex::Type mutex_type = Mutex::eMutexTypeNormal) :
32-
m_map(map_initial_capacity),
33-
m_mutex(mutex_type)
34-
{
35-
}
36-
29+
30+
ThreadSafeDenseMap(unsigned map_initial_capacity = 0) : m_map(map_initial_capacity), m_mutex() {}
31+
3732
void
3833
Insert (_KeyType k, _ValueType v)
3934
{
40-
Mutex::Locker locker(m_mutex);
35+
std::lock_guard<_MutexType> guard(m_mutex);
4136
m_map.insert(std::make_pair(k,v));
4237
}
4338

4439
void
4540
Erase (_KeyType k)
4641
{
47-
Mutex::Locker locker(m_mutex);
42+
std::lock_guard<_MutexType> guard(m_mutex);
4843
m_map.erase(k);
4944
}
5045

5146
_ValueType
5247
Lookup (_KeyType k)
5348
{
54-
Mutex::Locker locker(m_mutex);
49+
std::lock_guard<_MutexType> guard(m_mutex);
5550
return m_map.lookup(k);
5651
}
5752

5853
bool
5954
Lookup (_KeyType k,
6055
_ValueType& v)
6156
{
62-
Mutex::Locker locker(m_mutex);
57+
std::lock_guard<_MutexType> guard(m_mutex);
6358
auto iter = m_map.find(k),
6459
end = m_map.end();
6560
if (iter == end)
@@ -71,13 +66,13 @@ class ThreadSafeDenseMap
7166
void
7267
Clear ()
7368
{
74-
Mutex::Locker locker(m_mutex);
69+
std::lock_guard<_MutexType> guard(m_mutex);
7570
m_map.clear();
7671
}
7772

7873
protected:
7974
LLVMMapType m_map;
80-
Mutex m_mutex;
75+
_MutexType m_mutex;
8176
};
8277

8378
} // namespace lldb_private

lldb/include/lldb/Core/ThreadSafeDenseSet.h

+42-47
Original file line numberDiff line numberDiff line change
@@ -12,61 +12,56 @@
1212

1313
// C Includes
1414
// C++ Includes
15+
#include <mutex>
1516

1617
// Other libraries and framework includes
1718
#include "llvm/ADT/DenseSet.h"
1819

1920
// Project includes
20-
#include "lldb/Host/Mutex.h"
2121

2222
namespace lldb_private {
23-
24-
template <typename _ElementType>
25-
class ThreadSafeDenseSet
23+
24+
template <typename _ElementType, typename _MutexType = std::mutex>
25+
class ThreadSafeDenseSet
26+
{
27+
public:
28+
typedef llvm::DenseSet<_ElementType> LLVMSetType;
29+
30+
ThreadSafeDenseSet(unsigned set_initial_capacity = 0) : m_set(set_initial_capacity), m_mutex() {}
31+
32+
void
33+
Insert(_ElementType e)
2634
{
27-
public:
28-
typedef llvm::DenseSet<_ElementType> LLVMSetType;
29-
30-
ThreadSafeDenseSet(unsigned set_initial_capacity = 0,
31-
Mutex::Type mutex_type = Mutex::eMutexTypeNormal) :
32-
m_set(set_initial_capacity),
33-
m_mutex(mutex_type)
34-
{
35-
}
36-
37-
void
38-
Insert (_ElementType e)
39-
{
40-
Mutex::Locker locker(m_mutex);
41-
m_set.insert(e);
42-
}
43-
44-
void
45-
Erase (_ElementType e)
46-
{
47-
Mutex::Locker locker(m_mutex);
48-
m_set.erase(e);
49-
}
50-
51-
bool
52-
Lookup (_ElementType e)
53-
{
54-
Mutex::Locker locker(m_mutex);
55-
return (m_set.count(e) > 0);
56-
}
57-
58-
void
59-
Clear ()
60-
{
61-
Mutex::Locker locker(m_mutex);
62-
m_set.clear();
63-
}
64-
65-
protected:
66-
LLVMSetType m_set;
67-
Mutex m_mutex;
68-
};
69-
35+
std::lock_guard<_MutexType> guard(m_mutex);
36+
m_set.insert(e);
37+
}
38+
39+
void
40+
Erase(_ElementType e)
41+
{
42+
std::lock_guard<_MutexType> guard(m_mutex);
43+
m_set.erase(e);
44+
}
45+
46+
bool
47+
Lookup(_ElementType e)
48+
{
49+
std::lock_guard<_MutexType> guard(m_mutex);
50+
return (m_set.count(e) > 0);
51+
}
52+
53+
void
54+
Clear()
55+
{
56+
stds::lock_guard<_MutexType> guard(m_mutex);
57+
m_set.clear();
58+
}
59+
60+
protected:
61+
LLVMSetType m_set;
62+
_MutexType m_mutex;
63+
};
64+
7065
} // namespace lldb_private
7166

7267
#endif // liblldb_ThreadSafeDenseSet_h_

0 commit comments

Comments
 (0)