Skip to content

Commit 6600ca8

Browse files
committed
Spawn Configuration::Concurrency process managers
refs #7600
1 parent 166a769 commit 6600ca8

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

lib/base/process.cpp

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
22

3+
#include "base/atomic.hpp"
34
#include "base/goprocmgr.hpp"
5+
#include "base/configuration.hpp"
46
#include "base/process.hpp"
57
#include "base/exception.hpp"
68
#include "base/convert.hpp"
@@ -210,7 +212,8 @@ class ProcMgr
210212
}
211213
};
212214

213-
static std::unique_ptr<ProcMgr> l_ProcMgr;
215+
static std::vector<ProcMgr> l_ProcMgrs;
216+
static Atomic<decltype(l_ProcMgrs)::size_type> l_ProcMgr (0);
214217

215218
#endif /* _WIN32 */
216219

@@ -614,8 +617,8 @@ int Process::GetTID() const
614617

615618
void Process::InitializeSpawnHelper()
616619
{
617-
if (!l_ProcMgr) {
618-
l_ProcMgr.reset(new ProcMgr());
620+
if (l_ProcMgrs.empty()) {
621+
l_ProcMgrs = decltype(l_ProcMgrs)(Configuration::Concurrency);
619622
}
620623
}
621624

@@ -637,7 +640,9 @@ void Process::Run(Process::Callback callback)
637640

638641
extraEnvironment.emplace_back("LC_NUMERIC=C");
639642

640-
l_ProcMgr->Spawn(m_Arguments, std::move(extraEnvironment), m_Timeout, std::move(callback));
643+
l_ProcMgrs.at(l_ProcMgr.fetch_add(1) % l_ProcMgrs.size()).Spawn(
644+
m_Arguments, std::move(extraEnvironment), m_Timeout, std::move(callback)
645+
);
641646
}
642647

643648
Log(LogNotice, "Process")

0 commit comments

Comments
 (0)