Skip to content

Commit 803107f

Browse files
committed
Spawn Configuration::Concurrency process managers
refs #7600
1 parent 9a649a9 commit 803107f

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

lib/base/process.cpp

Lines changed: 9 additions & 4 deletions
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"
@@ -217,7 +219,8 @@ class ProcMgr
217219
}
218220
};
219221

220-
static std::unique_ptr<ProcMgr> l_ProcMgr;
222+
static std::vector<ProcMgr> l_ProcMgrs;
223+
static Atomic<decltype(l_ProcMgrs)::size_type> l_ProcMgr (0);
221224

222225
#endif /* _WIN32 */
223226

@@ -621,8 +624,8 @@ int Process::GetTID() const
621624

622625
void Process::InitializeSpawnHelper()
623626
{
624-
if (!l_ProcMgr) {
625-
l_ProcMgr.reset(new ProcMgr());
627+
if (l_ProcMgrs.empty()) {
628+
l_ProcMgrs = decltype(l_ProcMgrs)(Configuration::Concurrency);
626629
}
627630
}
628631

@@ -644,7 +647,9 @@ void Process::Run(Process::Callback callback)
644647

645648
extraEnvironment.emplace_back("LC_NUMERIC=C");
646649

647-
l_ProcMgr->Spawn(m_Arguments, std::move(extraEnvironment), m_Timeout, std::move(callback));
650+
l_ProcMgrs.at(l_ProcMgr.fetch_add(1) % l_ProcMgrs.size()).Spawn(
651+
m_Arguments, std::move(extraEnvironment), m_Timeout, std::move(callback)
652+
);
648653
}
649654

650655
Log(LogNotice, "Process")

0 commit comments

Comments
 (0)