forked from OctaForge/OctaBuild
fixes and cleanups
parent
906ea3bace
commit
5bd9f470f4
46
main.cc
46
main.cc
|
@ -36,13 +36,14 @@ using cscript::Bytecode;
|
||||||
/* thread pool */
|
/* thread pool */
|
||||||
|
|
||||||
struct ThreadPool {
|
struct ThreadPool {
|
||||||
ThreadPool() {}
|
ThreadPool():
|
||||||
|
cond(), mtx(), thrs(), tasks(nullptr), last_task(nullptr),
|
||||||
|
running(false)
|
||||||
|
{}
|
||||||
|
|
||||||
~ThreadPool() {
|
~ThreadPool() {
|
||||||
if (running) {
|
|
||||||
destroy();
|
destroy();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
static void *thr_func(void *ptr) {
|
static void *thr_func(void *ptr) {
|
||||||
static_cast<ThreadPool *>(ptr)->run();
|
static_cast<ThreadPool *>(ptr)->run();
|
||||||
|
@ -63,6 +64,10 @@ struct ThreadPool {
|
||||||
|
|
||||||
void destroy() {
|
void destroy() {
|
||||||
mtx.lock();
|
mtx.lock();
|
||||||
|
if (!running) {
|
||||||
|
mtx.unlock();
|
||||||
|
return;
|
||||||
|
}
|
||||||
running = false;
|
running = false;
|
||||||
mtx.unlock();
|
mtx.unlock();
|
||||||
cond.broadcast();
|
cond.broadcast();
|
||||||
|
@ -235,32 +240,35 @@ struct ObState: CsState {
|
||||||
Map<ConstCharRange, Vector<SubRule>> cache;
|
Map<ConstCharRange, Vector<SubRule>> cache;
|
||||||
|
|
||||||
struct RuleCounter {
|
struct RuleCounter {
|
||||||
RuleCounter(): cond(), mtx(), counter(0), result(0) {}
|
RuleCounter(): p_cond(), p_mtx(), p_counter(0), p_result(0) {}
|
||||||
|
|
||||||
void wait() {
|
void wait() {
|
||||||
UniqueLock<Mutex> l(mtx);
|
UniqueLock<Mutex> l(p_mtx);
|
||||||
while (counter) {
|
while (p_counter) {
|
||||||
cond.wait(l);
|
p_cond.wait(l);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void incr() {
|
void incr() {
|
||||||
UniqueLock<Mutex> l(mtx);
|
UniqueLock<Mutex> l(p_mtx);
|
||||||
++counter;
|
++p_counter;
|
||||||
}
|
}
|
||||||
|
|
||||||
void decr() {
|
void decr() {
|
||||||
UniqueLock<Mutex> l(mtx);
|
UniqueLock<Mutex> l(p_mtx);
|
||||||
if (!--counter) {
|
if (!--p_counter) {
|
||||||
l.unlock();
|
l.unlock();
|
||||||
cond.broadcast();
|
p_cond.broadcast();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Condition cond;
|
ostd::AtomicInt &get_result() { return p_result; }
|
||||||
Mutex mtx;
|
|
||||||
int volatile counter;
|
private:
|
||||||
ostd::AtomicInt result;
|
Condition p_cond;
|
||||||
|
Mutex p_mtx;
|
||||||
|
int p_counter;
|
||||||
|
ostd::AtomicInt p_result;
|
||||||
};
|
};
|
||||||
|
|
||||||
Vector<RuleCounter *> counters;
|
Vector<RuleCounter *> counters;
|
||||||
|
@ -275,7 +283,7 @@ struct ObState: CsState {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
ctr.wait();
|
ctr.wait();
|
||||||
return ctr.result;
|
return ctr.get_result();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename ...A>
|
template<typename ...A>
|
||||||
|
@ -575,8 +583,8 @@ int main(int argc, char **argv) {
|
||||||
cnt->incr();
|
cnt->incr();
|
||||||
tpool.push([cnt, ds = String(args[0].get_strr())]() {
|
tpool.push([cnt, ds = String(args[0].get_strr())]() {
|
||||||
int ret = system(ds.data());
|
int ret = system(ds.data());
|
||||||
if (ret && !cnt->result) {
|
if (ret && !cnt->get_result()) {
|
||||||
cnt->result = ret;
|
cnt->get_result() = ret;
|
||||||
}
|
}
|
||||||
cnt->decr();
|
cnt->decr();
|
||||||
});
|
});
|
||||||
|
|
|
@ -5,13 +5,13 @@ OB_CXXFLAGS = "-g -Wall -Wextra -Wshadow -Wold-style-cast -O2"
|
||||||
CS_PATH = "../libcubescript"
|
CS_PATH = "../libcubescript"
|
||||||
OS_PATH = "../octastd"
|
OS_PATH = "../octastd"
|
||||||
|
|
||||||
FILES = [main_ob.o globs_ob.o cubescript_ob.o]
|
FILES = [main_ob.o globs_ob.o]
|
||||||
|
|
||||||
OB_CXXFLAGS = [@OB_CXXFLAGS -std=c++14 -I. -I@CS_PATH -I@OS_PATH -pthread]
|
OB_CXXFLAGS = [@OB_CXXFLAGS -std=c++14 -I. -I@CS_PATH -I@OS_PATH -pthread]
|
||||||
|
|
||||||
rule obuild $FILES [
|
rule obuild $FILES [
|
||||||
echo " LD" $target
|
echo " LD" $target
|
||||||
shell $CXX $OB_CXXFLAGS -o obuild_ob $sources
|
shell $CXX $OB_CXXFLAGS -o obuild_ob $sources [@CS_PATH/libcubescript.a]
|
||||||
]
|
]
|
||||||
|
|
||||||
rule %_ob.o %.cc [
|
rule %_ob.o %.cc [
|
||||||
|
@ -19,8 +19,6 @@ rule %_ob.o %.cc [
|
||||||
shell $CXX $OB_CXXFLAGS -c -o $target $source
|
shell $CXX $OB_CXXFLAGS -c -o $target $source
|
||||||
]
|
]
|
||||||
|
|
||||||
duprule cubescript_ob.o %_ob.o [@CS_PATH/cubescript.cc]
|
|
||||||
|
|
||||||
action clean [
|
action clean [
|
||||||
echo " CLEAN" $FILES obuild_ob
|
echo " CLEAN" $FILES obuild_ob
|
||||||
shell rm -f $FILES obuild_ob
|
shell rm -f $FILES obuild_ob
|
||||||
|
@ -28,6 +26,5 @@ action clean [
|
||||||
|
|
||||||
depend main_ob.o [@CS_PATH/cubescript.hh]
|
depend main_ob.o [@CS_PATH/cubescript.hh]
|
||||||
depend globs_ob.o [@CS_PATH/cubescript.hh]
|
depend globs_ob.o [@CS_PATH/cubescript.hh]
|
||||||
depend cubescript_ob.o [@CS_PATH/cubescript.hh]
|
|
||||||
|
|
||||||
rule default obuild
|
rule default obuild
|
||||||
|
|
Loading…
Reference in New Issue