Load autoloaded automation scripts in parallel
This commit is contained in:
parent
a75b7f6ca8
commit
df73591a54
1 changed files with 14 additions and 7 deletions
|
@ -56,6 +56,7 @@
|
||||||
#include <boost/algorithm/string/trim.hpp>
|
#include <boost/algorithm/string/trim.hpp>
|
||||||
#include <boost/format.hpp>
|
#include <boost/format.hpp>
|
||||||
#include <boost/tokenizer.hpp>
|
#include <boost/tokenizer.hpp>
|
||||||
|
#include <future>
|
||||||
|
|
||||||
#include <wx/dcmemory.h>
|
#include <wx/dcmemory.h>
|
||||||
#include <wx/log.h>
|
#include <wx/log.h>
|
||||||
|
@ -340,19 +341,25 @@ namespace Automation4 {
|
||||||
{
|
{
|
||||||
scripts.clear();
|
scripts.clear();
|
||||||
|
|
||||||
int error_count = 0;
|
std::vector<std::future<std::unique_ptr<Script>>> script_futures;
|
||||||
|
|
||||||
boost::char_separator<char> sep("|");
|
boost::char_separator<char> sep("|");
|
||||||
for (auto const& tok : boost::tokenizer<boost::char_separator<char>>(path, sep)) {
|
for (auto const& tok : boost::tokenizer<boost::char_separator<char>>(path, sep)) {
|
||||||
auto dirname = config::path->Decode(tok);
|
auto dirname = config::path->Decode(tok);
|
||||||
if (!agi::fs::DirectoryExists(dirname)) continue;
|
if (!agi::fs::DirectoryExists(dirname)) continue;
|
||||||
|
|
||||||
for (auto filename : agi::fs::DirectoryIterator(dirname, "*.*")) {
|
for (auto filename : agi::fs::DirectoryIterator(dirname, "*.*"))
|
||||||
auto s = ScriptFactory::CreateFromFile(dirname/filename, false, false);
|
script_futures.emplace_back(std::async(std::launch::async, [=] {
|
||||||
if (s) {
|
return ScriptFactory::CreateFromFile(dirname/filename, false, false);
|
||||||
if (!s->GetLoadedState()) ++error_count;
|
}));
|
||||||
scripts.emplace_back(std::move(s));
|
}
|
||||||
}
|
|
||||||
|
int error_count = 0;
|
||||||
|
for (auto& future : script_futures) {
|
||||||
|
auto s = future.get();
|
||||||
|
if (s) {
|
||||||
|
if (!s->GetLoadedState()) ++error_count;
|
||||||
|
scripts.emplace_back(std::move(s));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue