aboutsummaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorPetteri Räty <petsku@petteriraty.eu>2011-05-18 10:24:09 +0300
committerPetteri Räty <petsku@petteriraty.eu>2011-05-18 15:43:01 +0300
commit1db4915f98c4a6943aa685840a2353c029ec3309 (patch)
tree61d378ee06b8ab9171d6bb1ac983114f41f2a69d /utils
parentBuiltins: support null command (diff)
downloadlibbash-1db4915f98c4a6943aa685840a2353c029ec3309.tar.gz
libbash-1db4915f98c4a6943aa685840a2353c029ec3309.tar.bz2
libbash-1db4915f98c4a6943aa685840a2353c029ec3309.zip
multithread
Diffstat (limited to 'utils')
-rw-r--r--utils/instruo.cpp99
1 files changed, 51 insertions, 48 deletions
diff --git a/utils/instruo.cpp b/utils/instruo.cpp
index bd1c981..f91bbf1 100644
--- a/utils/instruo.cpp
+++ b/utils/instruo.cpp
@@ -64,60 +64,63 @@ using std::endl;
void worker(const std::shared_ptr<PackageIDSequence> &ids)
{
- std::unordered_map<std::string, std::vector<std::string>> variables;
-
- std::shared_ptr<const PackageID> id;
unsigned total(0);
CategoryNamePart old_cat("OLDCAT");
- while(!ids->empty())
+ #pragma omp parallel
{
- id = *ids->begin();
- ids->pop_front();
- if (id->name().category() != old_cat)
+ #pragma omp single nowait
+ while(!ids->empty())
{
- std::cout << "Processing " << stringify(id->name().category()) << "..." << std::endl;
- old_cat = id->name().category();
- FSPath(CommandLine::get_instance()->a_output_directory.argument() + "/" +
- stringify(id->name().category())).mkdir(0755, {fspmkdo_ok_if_exists});
- ++total;
- }
+ std::shared_ptr<const PackageID> id = *ids->begin();
+ ids->pop_front();
+ if (id->name().category() != old_cat)
+ {
+ std::cout << "Processing " << stringify(id->name().category()) << "..." << std::endl;
+ old_cat = id->name().category();
+ FSPath(CommandLine::get_instance()->a_output_directory.argument() + "/" +
+ stringify(id->name().category())).mkdir(0755, {fspmkdo_ok_if_exists});
+ ++total;
+ }
- Context i_context("When generating metadata for ID '" + stringify(*id) + "':");
-
- variables.clear();
- variables["PN"].push_back(stringify(id->name().package()));
- variables["PV"].push_back(stringify(id->version().remove_revision()));
- variables["P"].push_back(stringify(id->name().package()) + "-" +
- stringify(id->version().remove_revision()));
- variables["PR"].push_back(id->version().revision_only());
- variables["PVR"].push_back(stringify(id->version()));
- variables["PF"].push_back(stringify(id->name().package()) + "-" + stringify(id->version()));
- variables["CATEGORY"].push_back(stringify(id->name().category()));
- std::vector<std::string> functions;
-
- std::string ebuild_path(CommandLine::get_instance()->a_repository_directory.argument() +
- variables["CATEGORY"][0] + "/" +
- variables["PN"][0] + "/" +
- variables["PN"][0] + "-" +
- variables["PVR"][0] + ".ebuild");
- try
- {
- libbash::interpret(ebuild_path, variables, functions);
- }
- catch(const interpreter_exception& e)
- {
- cerr << "Exception occurred while interpreting " << ebuild_path << ". The error message is:\n"
- << e.what() << endl;
- continue;
+ #pragma omp task
+ {
+ Context i_context("When generating metadata for ID '" + stringify(*id) + "':");
+
+ std::unordered_map<std::string, std::vector<std::string>> variables;
+ variables["PN"].push_back(stringify(id->name().package()));
+ variables["PV"].push_back(stringify(id->version().remove_revision()));
+ variables["P"].push_back(stringify(id->name().package()) + "-" +
+ stringify(id->version().remove_revision()));
+ variables["PR"].push_back(id->version().revision_only());
+ variables["PVR"].push_back(stringify(id->version()));
+ variables["PF"].push_back(stringify(id->name().package()) + "-" + stringify(id->version()));
+ variables["CATEGORY"].push_back(stringify(id->name().category()));
+ std::vector<std::string> functions;
+
+ std::string ebuild_path(CommandLine::get_instance()->a_repository_directory.argument() +
+ variables["CATEGORY"][0] + "/" +
+ variables["PN"][0] + "/" +
+ variables["PN"][0] + "-" +
+ variables["PVR"][0] + ".ebuild");
+ try
+ {
+ libbash::interpret(ebuild_path, variables, functions);
+
+ std::string output_path(CommandLine::get_instance()->a_output_directory.argument() + "/" +
+ variables["CATEGORY"][0] + "/" +
+ variables["PN"][0] + "-" +
+ variables["PVR"][0]);
+ FSPath(output_path).dirname().mkdir(0755, {fspmkdo_ok_if_exists});
+ std::ofstream output(output_path, std::ofstream::out | std::ofstream::trunc);
+ write_metadata(output, variables, functions);
+ }
+ catch(const interpreter_exception& e)
+ {
+ cerr << "Exception occurred while interpreting " << ebuild_path << ". The error message is:\n"
+ << e.what() << endl;
+ }
+ }
}
-
- std::string output_path(CommandLine::get_instance()->a_output_directory.argument() + "/" +
- variables["CATEGORY"][0] + "/" +
- variables["PN"][0] + "-" +
- variables["PVR"][0]);
- FSPath(output_path).dirname().mkdir(0755, {fspmkdo_ok_if_exists});
- std::ofstream output(output_path, std::ofstream::out | std::ofstream::trunc);
- write_metadata(output, variables, functions);
}
}