[Lldb-commits] [PATCH] D37930: Use ThreadLauncher to launch TaskPool threads

Francis Ricci via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Fri Sep 15 13:55:40 PDT 2017


fjricci created this revision.

This allows for the stack size to be configured, which isn't
possible with std::thread. Prevents overflowing the stack when
performing complex operations in the task pool on darwin,
where the default pthread stack size is only 512kb.


https://reviews.llvm.org/D37930

Files:
  source/Utility/TaskPool.cpp


Index: source/Utility/TaskPool.cpp
===================================================================
--- source/Utility/TaskPool.cpp
+++ source/Utility/TaskPool.cpp
@@ -8,6 +8,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "lldb/Utility/TaskPool.h"
+#include "lldb/Host/ThreadLauncher.h"
 
 #include <cstdint> // for uint32_t
 #include <queue>   // for queue
@@ -23,6 +24,8 @@
 private:
   TaskPoolImpl();
 
+  static lldb::thread_result_t WorkerPtr(void *pool);
+
   static void Worker(TaskPoolImpl *pool);
 
   std::queue<std::function<void()>> m_tasks;
@@ -54,10 +57,17 @@
     // This prevents the thread
     // from exiting prematurely and triggering a linux libc bug
     // (https://sourceware.org/bugzilla/show_bug.cgi?id=19951).
-    std::thread(Worker, this).detach();
+    lldb_private::ThreadLauncher::LaunchThread("task-pool.worker", WorkerPtr,
+                                               this, nullptr, 8 * 1024 * 1024)
+        .Release();
   }
 }
 
+lldb::thread_result_t TaskPoolImpl::WorkerPtr(void *pool) {
+  Worker((TaskPoolImpl *)pool);
+  return 0;
+}
+
 void TaskPoolImpl::Worker(TaskPoolImpl *pool) {
   while (true) {
     std::unique_lock<std::mutex> lock(pool->m_tasks_mutex);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D37930.115484.patch
Type: text/x-patch
Size: 1264 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20170915/98c85fcc/attachment.bin>


More information about the lldb-commits mailing list