From 649d2e648aad36f097d8fbea4dc6c2f1e7ac2e37 Mon Sep 17 00:00:00 2001 From: Thomas Horstink Date: Thu, 3 Aug 2023 20:39:42 +0200 Subject: [PATCH] double checks --- examples/flight/flight.cc | 9 +++++---- symmetri/include/symmetri/symmetri.h | 26 ++++++++++++------------ symmetri/symmetri.cc | 30 ++++++++++++++-------------- 3 files changed, 33 insertions(+), 32 deletions(-) diff --git a/examples/flight/flight.cc b/examples/flight/flight.cc index 8b9b52d3..97ee9a4d 100644 --- a/examples/flight/flight.cc +++ b/examples/flight/flight.cc @@ -86,10 +86,11 @@ int main(int, char *argv[]) { auto gantt = std::thread([&] { while (running) { std::this_thread::sleep_for(std::chrono::seconds(3)); + if (!running) { + break; + } writeMermaidHtmlToFile(symmetri::mermaidFromEventlog(getLog(bignet))); } - writeMermaidHtmlToFile(symmetri::mermaidFromEventlog(getLog(bignet))); - std::cout << "gannt blocked" << std::endl; }); // Parallel to the PetriNet execution, we run a thread through which we @@ -117,7 +118,6 @@ int main(int, char *argv[]) { } std::cin.get(); }; - std::cout << "cin blocked" << std::endl; }); // this is where we call the blocking fire-function that executes the petri @@ -127,7 +127,8 @@ int main(int, char *argv[]) { // print the results and eventlog spdlog::info("Result of this net: {0}", printState(result)); printLog(el); - t.join(); // clean up gantt.join(); // clean up + t.join(); // clean up + writeMermaidHtmlToFile(symmetri::mermaidFromEventlog(el)); return 0; } diff --git a/symmetri/include/symmetri/symmetri.h b/symmetri/include/symmetri/symmetri.h index b7215eda..b5ff106f 100644 --- a/symmetri/include/symmetri/symmetri.h +++ b/symmetri/include/symmetri/symmetri.h @@ -7,6 +7,18 @@ #include "symmetri/tasks.h" #include "symmetri/types.h" +/** + * @brief The PetriNet class is a class that can create, configure and + * run a Petri net. + * + */ +class PetriNet; +symmetri::Result fire(const PetriNet &); +symmetri::Result cancel(const PetriNet &); +void pause(const PetriNet &); +void resume(const PetriNet &); +symmetri::Eventlog getLog(const PetriNet &); + namespace symmetri { /** * @brief A Store is a mapping from Transitions, represented by a string that is @@ -26,18 +38,6 @@ struct Petri; } // namespace symmetri -/** - * @brief The PetriNet class is a class that can create, configure and - * run a Petri net. - * - */ -class PetriNet; -symmetri::Result fire(const PetriNet &); -symmetri::Result cancel(const PetriNet &); -void pause(const PetriNet &); -void resume(const PetriNet &); -symmetri::Eventlog getLog(const PetriNet &); - class PetriNet final { public: /** @@ -114,7 +114,7 @@ class PetriNet final { friend symmetri::Eventlog(::getLog)(const PetriNet &); private: - std::shared_ptr + const std::shared_ptr impl; ///< Pointer to the implementation, all ///< information is stored in Petri }; diff --git a/symmetri/symmetri.cc b/symmetri/symmetri.cc index 45389d2d..e106a3c4 100644 --- a/symmetri/symmetri.cc +++ b/symmetri/symmetri.cc @@ -43,22 +43,23 @@ using namespace symmetri; PetriNet::PetriNet(const std::set &files, const Marking &final_marking, const Store &store, const PriorityTable &priorities, const std::string &case_id, - std::shared_ptr stp) { - const auto [net, m0] = readPnml(files); - areAllTransitionsInStore(store, net); - impl = std::make_shared(net, store, priorities, m0, final_marking, - case_id, stp); -} + std::shared_ptr stp) + : impl([&] { + const auto [net, m0] = readPnml(files); + areAllTransitionsInStore(store, net); + return std::make_shared(net, store, priorities, m0, + final_marking, case_id, stp); + }()) {} PetriNet::PetriNet(const std::set &files, const Marking &final_marking, const Store &store, - const std::string &case_id, - std::shared_ptr stp) { - const auto [net, m0, priorities] = readGrml(files); - areAllTransitionsInStore(store, net); - impl = std::make_shared(net, store, priorities, m0, final_marking, - case_id, stp); -} + const std::string &case_id, std::shared_ptr stp) + : impl([&] { + const auto [net, m0, priorities] = readGrml(files); + areAllTransitionsInStore(store, net); + return std::make_shared(net, store, priorities, m0, + final_marking, case_id, stp); + }()) {} PetriNet::PetriNet(const Net &net, const Marking &m0, const Marking &final_marking, const Store &store, @@ -172,8 +173,7 @@ void resume(const PetriNet &app) { }; symmetri::Eventlog getLog(const PetriNet &app) { - if (app.impl->thread_id_.load() && - app.impl->thread_id_.load().value() != getThreadId()) { + if (app.impl->thread_id_.load()) { std::promise el; std::future el_getter = el.get_future(); app.impl->active_reducers->enqueue([&](Petri &model) {