From edec4c2ef0de9df5f335152ed143d45f2f8e1c55 Mon Sep 17 00:00:00 2001 From: Dan Engelbrecht Date: Tue, 28 Nov 2023 16:39:30 -0500 Subject: close thread pool + parallel CasImpl::Initialize (#576) * close thread pool at destruction * parallell casimpl::initialize --- src/zencore/workthreadpool.cpp | 1 + src/zenstore/cas.cpp | 21 +++++++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/zencore/workthreadpool.cpp b/src/zencore/workthreadpool.cpp index bdb9de9dc..e6a6b5c54 100644 --- a/src/zencore/workthreadpool.cpp +++ b/src/zencore/workthreadpool.cpp @@ -74,6 +74,7 @@ struct WorkerThreadPool::Impl { WaitForThreadpoolWorkCallbacks(m_Work, /* CancelPendingCallbacks */ TRUE); CloseThreadpoolWork(m_Work); + CloseThreadpool(m_ThreadPool); } void ScheduleWork(Ref Work) diff --git a/src/zenstore/cas.cpp b/src/zenstore/cas.cpp index fc549a729..c6bfda8b9 100644 --- a/src/zenstore/cas.cpp +++ b/src/zenstore/cas.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -104,10 +105,22 @@ CasImpl::Initialize(const CidStoreConfiguration& InConfig) const bool IsNewStore = OpenOrCreateManifest(); // Initialize payload storage - - m_LargeStrategy.Initialize(m_Config.RootDirectory, IsNewStore); - m_TinyStrategy.Initialize(m_Config.RootDirectory, "tobs", 1u << 28, 16, IsNewStore); // 256 Mb per block - m_SmallStrategy.Initialize(m_Config.RootDirectory, "sobs", 1u << 30, 4096, IsNewStore); // 1 Gb per block + { + WorkerThreadPool WorkerPool(3, "CasImpl::Initialize"); + std::vector> Work; + Work.emplace_back( + WorkerPool.EnqueueTask(std::packaged_task{[&]() { m_LargeStrategy.Initialize(m_Config.RootDirectory, IsNewStore); }})); + Work.emplace_back(WorkerPool.EnqueueTask(std::packaged_task{[&]() { + m_TinyStrategy.Initialize(m_Config.RootDirectory, "tobs", 1u << 28, 16, IsNewStore); // 256 Mb per block + }})); + Work.emplace_back(WorkerPool.EnqueueTask(std::packaged_task{[&]() { + m_SmallStrategy.Initialize(m_Config.RootDirectory, "sobs", 1u << 30, 4096, IsNewStore); // 1 Gb per block + }})); + for (std::future& Result : Work) + { + Result.get(); + } + } } bool -- cgit v1.2.3