Browse Source

feat: get all cases status

legacy
Dnomd343 2 years ago
parent
commit
e4145de935
  1. 11
      all_cases/all_cases.cc
  2. 1
      all_cases/all_cases.h
  3. 25
      all_cases/main.cc

11
all_cases/all_cases.cc

@ -34,3 +34,14 @@ void AllCases::build_all_cases() { // build all cases
} }
AllCases::all_cases_building.unlock(); AllCases::all_cases_building.unlock();
} }
AllCases::Status AllCases::all_cases_status() { // get all cases status
if (all_cases_available) {
return AVAILABLE; // all cases already built
}
if (!all_cases_building.try_lock()) { // fail to lock mutex -> another thread working
return BUILDING;
}
all_cases_building.unlock(); // release mutex
return NO_INIT;
}

1
all_cases/all_cases.h

@ -8,6 +8,7 @@
class AllCases : public BasicRanges { class AllCases : public BasicRanges {
public: public:
static void build_all_cases(); static void build_all_cases();
static enum Status all_cases_status();
static const std::vector<uint32_t> (*get_all_cases())[16]; static const std::vector<uint32_t> (*get_all_cases())[16];
private: private:

25
all_cases/main.cc

@ -16,6 +16,18 @@ void get_status() {
std::cout << "basic ranges available" << std::endl; std::cout << "basic ranges available" << std::endl;
break; break;
} }
switch (AllCases::all_cases_status()) {
case AllCases::NO_INIT:
std::cout << "all cases no init" << std::endl;
break;
case AllCases::BUILDING:
std::cout << "all cases building" << std::endl;
break;
case AllCases::AVAILABLE:
std::cout << "all cases available" << std::endl;
break;
}
} }
int main() { int main() {
@ -36,18 +48,27 @@ int main() {
// std::cout << BasicRanges::get_basic_ranges()->size() << std::endl; // std::cout << BasicRanges::get_basic_ranges()->size() << std::endl;
get_status();
std::thread t1(AllCases::build_all_cases); std::thread t1(AllCases::build_all_cases);
std::thread t2(AllCases::build_all_cases); std::thread t2(AllCases::build_all_cases);
std::thread t3(AllCases::build_all_cases); std::thread t3(AllCases::build_all_cases);
std::thread t(get_status);
t1.join(); t1.join();
t2.join(); t2.join();
t3.join(); t3.join();
t.join();
AllCases::build_all_cases(); // AllCases::build_all_cases();
get_status();
for (auto const &all_case : *AllCases::get_all_cases()) { for (auto const &all_case : *AllCases::get_all_cases()) {
std::cout << all_case.size() << std::endl; std::cout << " " << all_case.size() << std::endl;
} }
std::cout << BasicRanges::get_basic_ranges() << std::endl;
std::cout << AllCases::get_basic_ranges() << std::endl;
return 0; return 0;
} }

Loading…
Cancel
Save