@@ -38,6 +38,10 @@ void OperatingSystemSwiftTasks::Terminate() {
3838 PluginManager::UnregisterPlugin (CreateInstance);
3939}
4040
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+
4145// / A wrapper around ThreadMemory providing lazy name evaluation, as this is
4246// / expensive to compute for Swift Tasks.
4347class SwiftTaskThreadMemory : public ThreadMemory {
@@ -61,8 +65,13 @@ class SwiftTaskThreadMemory : public ThreadMemory {
6165 }
6266
6367private:
68+ uint64_t GetTaskID () const {
69+ auto thread_id = GetID ();
70+ return thread_id & ~TASK_MASK;
71+ }
72+
6473 std::string GetDefaultTaskName () const {
65- return llvm::formatv (" Task {0}" , GetID ());
74+ return llvm::formatv (" Task {0}" , GetTaskID ());
6675 }
6776
6877 // / If possible, read a user-provided task name from memory, otherwise use a
@@ -80,7 +89,7 @@ class SwiftTaskThreadMemory : public ThreadMemory {
8089
8190 if (!task_name->has_value ())
8291 return GetDefaultTaskName ();
83- return llvm::formatv (" {0} (Task {1})" , *task_name, GetID ());
92+ return llvm::formatv (" {0} (Task {1})" , *task_name, GetTaskID ());
8493 }
8594
8695 std::string m_task_name = " " ;
@@ -131,7 +140,7 @@ ThreadSP
131140OperatingSystemSwiftTasks::FindOrCreateSwiftThread (ThreadList &old_thread_list,
132141 uint64_t task_id) {
133142 // 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;
135144
136145 // If we already had a thread for this Task in the last stop, re-use it.
137146 if (ThreadSP old_thread = old_thread_list.FindThreadByID (masked_task_id);
0 commit comments