summaryrefslogtreecommitdiffstats
path: root/contrib/llvm/tools/lldb/source/Utility/TaskPool.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm/tools/lldb/source/Utility/TaskPool.cpp')
-rw-r--r--contrib/llvm/tools/lldb/source/Utility/TaskPool.cpp102
1 files changed, 42 insertions, 60 deletions
diff --git a/contrib/llvm/tools/lldb/source/Utility/TaskPool.cpp b/contrib/llvm/tools/lldb/source/Utility/TaskPool.cpp
index c5c63a2..f66f7bf 100644
--- a/contrib/llvm/tools/lldb/source/Utility/TaskPool.cpp
+++ b/contrib/llvm/tools/lldb/source/Utility/TaskPool.cpp
@@ -9,81 +9,63 @@
#include "lldb/Utility/TaskPool.h"
-namespace
-{
- class TaskPoolImpl
- {
- public:
- static TaskPoolImpl&
- GetInstance();
+namespace {
+class TaskPoolImpl {
+public:
+ static TaskPoolImpl &GetInstance();
- void
- AddTask(std::function<void()>&& task_fn);
+ void AddTask(std::function<void()> &&task_fn);
- private:
- TaskPoolImpl();
+private:
+ TaskPoolImpl();
- static void
- Worker(TaskPoolImpl* pool);
+ static void Worker(TaskPoolImpl *pool);
- std::queue<std::function<void()>> m_tasks;
- std::mutex m_tasks_mutex;
- uint32_t m_thread_count;
- };
+ std::queue<std::function<void()>> m_tasks;
+ std::mutex m_tasks_mutex;
+ uint32_t m_thread_count;
+};
} // end of anonymous namespace
-TaskPoolImpl&
-TaskPoolImpl::GetInstance()
-{
- static TaskPoolImpl g_task_pool_impl;
- return g_task_pool_impl;
+TaskPoolImpl &TaskPoolImpl::GetInstance() {
+ static TaskPoolImpl g_task_pool_impl;
+ return g_task_pool_impl;
}
-void
-TaskPool::AddTaskImpl(std::function<void()>&& task_fn)
-{
- TaskPoolImpl::GetInstance().AddTask(std::move(task_fn));
+void TaskPool::AddTaskImpl(std::function<void()> &&task_fn) {
+ TaskPoolImpl::GetInstance().AddTask(std::move(task_fn));
}
-TaskPoolImpl::TaskPoolImpl() :
- m_thread_count(0)
-{
-}
+TaskPoolImpl::TaskPoolImpl() : m_thread_count(0) {}
-void
-TaskPoolImpl::AddTask(std::function<void()>&& task_fn)
-{
- static const uint32_t max_threads = std::thread::hardware_concurrency();
+void TaskPoolImpl::AddTask(std::function<void()> &&task_fn) {
+ static const uint32_t max_threads = std::thread::hardware_concurrency();
- std::unique_lock<std::mutex> lock(m_tasks_mutex);
- m_tasks.emplace(std::move(task_fn));
- if (m_thread_count < max_threads)
- {
- m_thread_count++;
- // Note that this detach call needs to happen with the m_tasks_mutex held. 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();
- }
+ std::unique_lock<std::mutex> lock(m_tasks_mutex);
+ m_tasks.emplace(std::move(task_fn));
+ if (m_thread_count < max_threads) {
+ m_thread_count++;
+ // Note that this detach call needs to happen with the m_tasks_mutex held.
+ // 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();
+ }
}
-void
-TaskPoolImpl::Worker(TaskPoolImpl* pool)
-{
- while (true)
- {
- std::unique_lock<std::mutex> lock(pool->m_tasks_mutex);
- if (pool->m_tasks.empty())
- {
- pool->m_thread_count--;
- break;
- }
+void TaskPoolImpl::Worker(TaskPoolImpl *pool) {
+ while (true) {
+ std::unique_lock<std::mutex> lock(pool->m_tasks_mutex);
+ if (pool->m_tasks.empty()) {
+ pool->m_thread_count--;
+ break;
+ }
- std::function<void()> f = pool->m_tasks.front();
- pool->m_tasks.pop();
- lock.unlock();
+ std::function<void()> f = pool->m_tasks.front();
+ pool->m_tasks.pop();
+ lock.unlock();
- f();
- }
+ f();
+ }
}
OpenPOWER on IntegriCloud