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"
@@ -210,7 +212,8 @@ class ProcMgr
210
212
}
211
213
};
212
214
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 );
214
217
215
218
#endif /* _WIN32 */
216
219
@@ -614,8 +617,8 @@ int Process::GetTID() const
614
617
615
618
void Process::InitializeSpawnHelper ()
616
619
{
617
- if (!l_ProcMgr ) {
618
- l_ProcMgr. reset ( new ProcMgr () );
620
+ if (l_ProcMgrs. empty () ) {
621
+ l_ProcMgrs = decltype (l_ProcMgrs)(Configuration::Concurrency );
619
622
}
620
623
}
621
624
@@ -637,7 +640,9 @@ void Process::Run(Process::Callback callback)
637
640
638
641
extraEnvironment.emplace_back (" LC_NUMERIC=C" );
639
642
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
+ );
641
646
}
642
647
643
648
Log (LogNotice, " Process" )
0 commit comments