[Lldb-commits] [lldb] r313537 - Use ThreadLauncher to launch TaskPool threads
Francis Ricci via lldb-commits
lldb-commits at lists.llvm.org
Mon Sep 18 08:18:49 PDT 2017
Author: fjricci
Date: Mon Sep 18 08:18:48 2017
New Revision: 313537
URL: http://llvm.org/viewvc/llvm-project?rev=313537&view=rev
Log:
Use ThreadLauncher to launch TaskPool threads
Summary:
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.
Reviewers: labath, tberghammer, clayborg
Subscribers: lldb-commits
Differential Revision: https://reviews.llvm.org/D37930
Modified:
lldb/trunk/source/Utility/TaskPool.cpp
Modified: lldb/trunk/source/Utility/TaskPool.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Utility/TaskPool.cpp?rev=313537&r1=313536&r2=313537&view=diff
==============================================================================
--- lldb/trunk/source/Utility/TaskPool.cpp (original)
+++ lldb/trunk/source/Utility/TaskPool.cpp Mon Sep 18 08:18:48 2017
@@ -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 @@ public:
private:
TaskPoolImpl();
+ static lldb::thread_result_t WorkerPtr(void *pool);
+
static void Worker(TaskPoolImpl *pool);
std::queue<std::function<void()>> m_tasks;
@@ -45,6 +48,7 @@ TaskPoolImpl::TaskPoolImpl() : m_thread_
void TaskPoolImpl::AddTask(std::function<void()> &&task_fn) {
static const uint32_t max_threads = std::thread::hardware_concurrency();
+ const size_t min_stack_size = 8 * 1024 * 1024;
std::unique_lock<std::mutex> lock(m_tasks_mutex);
m_tasks.emplace(std::move(task_fn));
@@ -54,10 +58,17 @@ void TaskPoolImpl::AddTask(std::function
// 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, min_stack_size)
+ .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);
More information about the lldb-commits
mailing list