per-state threadpool

master
Daniel Kolesa 2015-10-20 22:05:53 +01:00
parent e348f58108
commit d5ec6eea73
1 changed files with 7 additions and 5 deletions

12
main.cc
View File

@ -25,8 +25,6 @@ using cscript::CsState;
using cscript::TvalRange;
using cscript::StackedValue;
static ThreadPool tpool;
/* check funcs */
static bool ob_check_ts(ConstCharRange tname, const Vector<String> &deps) {
@ -98,6 +96,7 @@ static ConstCharRange ob_compare_subst(ConstCharRange expanded,
struct ObState {
CsState cs;
ConstCharRange progname;
ThreadPool tpool;
int jobs = 1;
bool ignore_env = false;
@ -170,6 +169,10 @@ struct ObState {
Vector<RuleCounter *> counters;
~ObState() {
tpool.destroy();
}
template<typename ...A>
int error(int retcode, ConstCharRange fmt, A &&...args) {
ostd::err.write(progname, ": ");
@ -397,13 +400,13 @@ int main(int argc, char **argv) {
}
}
tpool.init(os.jobs);
os.tpool.init(os.jobs);
os.cs.add_command("shell", "C", [](CsState &cs, ConstCharRange s) {
auto cnt = ((ObState &)cs).counters.back();
cnt->incr();
char *ds = String(s).disown();
tpool.push([cnt, ds]() {
((ObState &)cs).tpool.push([cnt, ds]() {
int ret = system(ds);
delete[] ds;
if (ret && !cnt->result)
@ -449,6 +452,5 @@ int main(int argc, char **argv) {
ret = maincnt.wait_result(os.counters, ret);
if (ret)
return ret;
tpool.destroy();
return 0;
}