cleanup rule counters
parent
201e57916c
commit
ed8b0a428e
35
main.cc
35
main.cc
|
@ -125,10 +125,7 @@ struct ObState {
|
||||||
Map<ConstCharRange, Vector<SubRule>> cache;
|
Map<ConstCharRange, Vector<SubRule>> cache;
|
||||||
|
|
||||||
struct RuleCounter {
|
struct RuleCounter {
|
||||||
RuleCounter(Vector<RuleCounter *> &ctrs): cond(), mtx(), counter(0),
|
RuleCounter(): cond(), mtx(), counter(0), result(0) {}
|
||||||
result(0) {
|
|
||||||
ctrs.push(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
void wait() {
|
void wait() {
|
||||||
mtx.lock();
|
mtx.lock();
|
||||||
|
@ -152,17 +149,6 @@ struct ObState {
|
||||||
mtx.unlock();
|
mtx.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
int wait_result(Vector<RuleCounter *> &ctrs, int ret) {
|
|
||||||
ctrs.pop();
|
|
||||||
if (ret)
|
|
||||||
return ret;
|
|
||||||
wait();
|
|
||||||
ret = result;
|
|
||||||
if (ret)
|
|
||||||
return ret;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
Cond cond;
|
Cond cond;
|
||||||
Mutex mtx;
|
Mutex mtx;
|
||||||
volatile int counter;
|
volatile int counter;
|
||||||
|
@ -171,6 +157,17 @@ struct ObState {
|
||||||
|
|
||||||
Vector<RuleCounter *> counters;
|
Vector<RuleCounter *> counters;
|
||||||
|
|
||||||
|
template<typename F>
|
||||||
|
int wait_result(F func) {
|
||||||
|
RuleCounter ctr;
|
||||||
|
counters.push(&ctr);
|
||||||
|
int ret = func();
|
||||||
|
counters.pop();
|
||||||
|
if (ret) return ret;
|
||||||
|
ctr.wait();
|
||||||
|
return ctr.result;
|
||||||
|
}
|
||||||
|
|
||||||
template<typename ...A>
|
template<typename ...A>
|
||||||
int error(int retcode, ConstCharRange fmt, A &&...args) {
|
int error(int retcode, ConstCharRange fmt, A &&...args) {
|
||||||
ostd::err.write(progname, ": ");
|
ostd::err.write(progname, ": ");
|
||||||
|
@ -202,8 +199,9 @@ struct ObState {
|
||||||
|
|
||||||
int exec_func(ConstCharRange tname, const Vector<SubRule> &rlist) {
|
int exec_func(ConstCharRange tname, const Vector<SubRule> &rlist) {
|
||||||
Vector<String> subdeps;
|
Vector<String> subdeps;
|
||||||
int ret = RuleCounter(counters)
|
int ret = wait_result([&rlist, &subdeps, &tname, this]() {
|
||||||
.wait_result(counters, exec_list(rlist, subdeps, tname));
|
return exec_list(rlist, subdeps, tname);
|
||||||
|
});
|
||||||
if (!ret && ob_check_exec(tname, subdeps)) {
|
if (!ret && ob_check_exec(tname, subdeps)) {
|
||||||
Uint32 *func = nullptr;
|
Uint32 *func = nullptr;
|
||||||
for (auto &sr: rlist.iter()) {
|
for (auto &sr: rlist.iter()) {
|
||||||
|
@ -317,8 +315,7 @@ struct ObState {
|
||||||
}
|
}
|
||||||
|
|
||||||
int exec_main(ConstCharRange target) {
|
int exec_main(ConstCharRange target) {
|
||||||
RuleCounter cnt(counters);
|
return wait_result([&target, this]() { return exec_rule(target); });
|
||||||
return cnt.wait_result(counters, exec_rule(target));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void rule_add(const char *tgt, const char *dep, ostd::Uint32 *body,
|
void rule_add(const char *tgt, const char *dep, ostd::Uint32 *body,
|
||||||
|
|
Loading…
Reference in New Issue