1
1
/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
2
2
3
+ #include " base/atomic.hpp"
3
4
#include " base/goprocmgr.hpp"
5
+ #include " base/configuration.hpp"
4
6
#include " base/process.hpp"
5
7
#include " base/exception.hpp"
6
8
#include " base/convert.hpp"
@@ -217,7 +219,8 @@ class ProcMgr
217
219
}
218
220
};
219
221
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 );
221
224
222
225
#endif /* _WIN32 */
223
226
@@ -621,8 +624,8 @@ int Process::GetTID() const
621
624
622
625
void Process::InitializeSpawnHelper ()
623
626
{
624
- if (!l_ProcMgr ) {
625
- l_ProcMgr. reset ( new ProcMgr () );
627
+ if (l_ProcMgrs. empty () ) {
628
+ l_ProcMgrs = decltype (l_ProcMgrs)(Configuration::Concurrency );
626
629
}
627
630
}
628
631
@@ -644,7 +647,9 @@ void Process::Run(Process::Callback callback)
644
647
645
648
extraEnvironment.emplace_back (" LC_NUMERIC=C" );
646
649
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
+ );
648
653
}
649
654
650
655
Log (LogNotice, " Process" )
0 commit comments