// // Created by anton on 6/24/22. // #include "call_frame.h" #include "helpers.h" namespace pmp::core { // public bool call_frame::evaluate() { std::unique_lock lock(evaluation_lock, std::try_to_lock); // check if lock was acquired if (!lock.owns_lock()) { return false; } // we now hold the lock // only run if we are in the initial state if (state != initial) return false; // set housekeeping variables state = running; try { result = target_function(arguments, scope); } catch (std::exception& ex) { std::cerr << "Error evaluating " << id << ": " << ex.what() << std::endl; m_has_error = true; } catch (...) { std::cerr << "Error evaluating " << id << std::endl; m_has_error = true; } // children are empty, when the "end" of an execution chain has been reached // this means that no further nodes were created during the execution // we don't need to acquire any lock, since no children will ever be added if (children.empty()) { state = completed; parent->mark_completion(); } else { // we do have children, so we must wait until they are finished to move on. state = waiting; } return true; } }