From 277dd31b08afcadceec7852012aa8b3c2cecbea7 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sun, 14 Apr 2013 02:07:40 -0700 Subject: gras: move code into component files --- lib/task_fail.cpp | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 lib/task_fail.cpp (limited to 'lib/task_fail.cpp') diff --git a/lib/task_fail.cpp b/lib/task_fail.cpp new file mode 100644 index 0000000..c30b668 --- /dev/null +++ b/lib/task_fail.cpp @@ -0,0 +1,58 @@ +// Copyright (C) by Josh Blum. See LICENSE.txt for licensing information. + +#include "element_impl.hpp" +#include + +using namespace gras; + +void Block::mark_output_fail(const size_t which_output) +{ + (*this)->block->output_fail(which_output); +} + +void Block::mark_input_fail(const size_t which_input) +{ + (*this)->block->input_fail(which_input); +} + +void BlockActor::input_fail(const size_t i) +{ + //input failed, accumulate and try again + if (not this->input_queues.is_accumulated(i)) + { + this->input_queues.accumulate(i); + this->task_kicker(); + return; + } + + //otherwise check for done, else wait for more + if (this->inputs_done[i]) + { + this->mark_done(); + return; + } + + //check that the input is not already maxed + if (this->input_queues.is_front_maximal(i)) + { + throw std::runtime_error("input_fail called on maximum_items buffer"); + } + + //mark fail: not ready until a new buffer appears + this->input_queues.fail(i); +} + +void BlockActor::output_fail(const size_t i) +{ + SBuffer &buff = this->output_queues.front(i); + + //check that the input is not already maxed + const size_t front_items = buff.length/this->output_configs[i].item_size; + if (front_items >= this->output_configs[i].maximum_items) + { + throw std::runtime_error("output_fail called on maximum_items buffer"); + } + + //mark fail: not ready until a new buffer appears + this->output_queues.fail(i); +} -- cgit