Skip to content

Commit

Permalink
double checks
Browse files Browse the repository at this point in the history
  • Loading branch information
thorstink committed Aug 3, 2023
1 parent 93a2e2c commit f749283
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 32 deletions.
9 changes: 5 additions & 4 deletions examples/flight/flight.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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;
}
26 changes: 13 additions & 13 deletions symmetri/include/symmetri/symmetri.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
/**
Expand Down Expand Up @@ -114,7 +114,7 @@ class PetriNet final {
friend symmetri::Eventlog(::getLog)(const PetriNet &);

private:
std::shared_ptr<symmetri::Petri>
const std::shared_ptr<symmetri::Petri>
impl; ///< Pointer to the implementation, all
///< information is stored in Petri
};
31 changes: 16 additions & 15 deletions symmetri/symmetri.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,23 @@ using namespace symmetri;
PetriNet::PetriNet(const std::set<std::string> &files,
const Marking &final_marking, const Store &store,
const PriorityTable &priorities, const std::string &case_id,
std::shared_ptr<TaskSystem> stp) {
const auto [net, m0] = readPnml(files);
areAllTransitionsInStore(store, net);
impl = std::make_shared<Petri>(net, store, priorities, m0, final_marking,
case_id, stp);
}
std::shared_ptr<TaskSystem> stp)
: impl([&] {
const auto [net, m0] = readPnml(files);
areAllTransitionsInStore(store, net);
return std::make_shared<Petri>(net, store, priorities, m0,
final_marking, case_id, stp);
}()) {}

PetriNet::PetriNet(const std::set<std::string> &files,
const Marking &final_marking, const Store &store,
const std::string &case_id,
std::shared_ptr<TaskSystem> stp) {
const auto [net, m0, priorities] = readGrml(files);
areAllTransitionsInStore(store, net);
impl = std::make_shared<Petri>(net, store, priorities, m0, final_marking,
case_id, stp);
}
const std::string &case_id, std::shared_ptr<TaskSystem> stp)
: impl([&] {
const auto [net, m0, priorities] = readGrml(files);
areAllTransitionsInStore(store, net);
return std::make_shared<Petri>(net, store, priorities, m0,
final_marking, case_id, stp);
}()) {}

PetriNet::PetriNet(const Net &net, const Marking &m0,
const Marking &final_marking, const Store &store,
Expand Down Expand Up @@ -148,6 +149,7 @@ symmetri::Result cancel(const PetriNet &app) {
model.net.transition[transition_index], state,
symmetri::Clock::now()});
}
model.active_transitions_n.clear();
});

return {getLog(app), symmetri::State::UserExit};
Expand All @@ -172,8 +174,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<Eventlog> el;
std::future<Eventlog> el_getter = el.get_future();
app.impl->active_reducers->enqueue([&](Petri &model) {
Expand Down

0 comments on commit f749283

Please sign in to comment.