@@ -38,6 +38,10 @@ void OperatingSystemSwiftTasks::Terminate() {
38
38
PluginManager::UnregisterPlugin (CreateInstance);
39
39
}
40
40
41
+ // / Mask applied to task IDs to generate thread IDs that to don't conflicts with
42
+ // / core thread IDs.
43
+ static constexpr uint64_t TASK_MASK = 0x0000000f00000000ULL ;
44
+
41
45
// / A wrapper around ThreadMemory providing lazy name evaluation, as this is
42
46
// / expensive to compute for Swift Tasks.
43
47
class SwiftTaskThreadMemory : public ThreadMemory {
@@ -61,8 +65,13 @@ class SwiftTaskThreadMemory : public ThreadMemory {
61
65
}
62
66
63
67
private:
68
+ uint64_t GetTaskID () const {
69
+ auto thread_id = GetID ();
70
+ return thread_id & ~TASK_MASK;
71
+ }
72
+
64
73
std::string GetDefaultTaskName () const {
65
- return llvm::formatv (" Task {0}" , GetID ());
74
+ return llvm::formatv (" Task {0}" , GetTaskID ());
66
75
}
67
76
68
77
// / If possible, read a user-provided task name from memory, otherwise use a
@@ -80,7 +89,7 @@ class SwiftTaskThreadMemory : public ThreadMemory {
80
89
81
90
if (!task_name->has_value ())
82
91
return GetDefaultTaskName ();
83
- return llvm::formatv (" {0} (Task {1})" , *task_name, GetID ());
92
+ return llvm::formatv (" {0} (Task {1})" , *task_name, GetTaskID ());
84
93
}
85
94
86
95
std::string m_task_name = " " ;
@@ -131,7 +140,7 @@ ThreadSP
131
140
OperatingSystemSwiftTasks::FindOrCreateSwiftThread (ThreadList &old_thread_list,
132
141
uint64_t task_id) {
133
142
// Mask higher bits to avoid conflicts with core thread IDs.
134
- uint64_t masked_task_id = 0x0000000f00000000 | task_id;
143
+ uint64_t masked_task_id = TASK_MASK | task_id;
135
144
136
145
// If we already had a thread for this Task in the last stop, re-use it.
137
146
if (ThreadSP old_thread = old_thread_list.FindThreadByID (masked_task_id);
0 commit comments