85 #include "pgm_controller.h"
88 using namespace r_code;
92 _PGMController::_PGMController(
_View *ipgm_view) : OController(ipgm_view) {
94 run_once_ = !ipgm_view->object_->code(IPGM_RUN).asBoolean();
97 _PGMController::~_PGMController() {
102 InputLessPGMController::InputLessPGMController(
_View *ipgm_view) : _PGMController(ipgm_view) {
104 overlays_.push_back(
new InputLessPGMOverlay(
this));
107 InputLessPGMController::~InputLessPGMController() {
110 void InputLessPGMController::signal_input_less_pgm() {
112 reductionCS_.enter();
113 if (overlays_.size()) {
115 InputLessPGMOverlay *overlay = (InputLessPGMOverlay *)overlays_.front();
116 overlay->inject_productions();
123 Group *host = get_view()->get_host();
125 if (host->get_c_act() > host->get_c_act_thr() &&
126 host->get_c_sln() > host->get_c_sln_thr()) {
130 TimeJob *next_job =
new InputLessPGMSignalingJob((
r_exec::View*)view_, Now() + time_scope_);
131 _Mem::Get()->push_time_job(next_job);
137 reductionCS_.leave();
145 PGMController::PGMController(
_View *ipgm_view) : _PGMController(ipgm_view) {
147 overlays_.push_back(
new PGMOverlay(
this));
150 PGMController::~PGMController() {
153 void PGMController::notify_reduction() {
161 Controller::__take_input<PGMController>(input);
167 uint32 oid = input->object_->get_oid();
168 if (time_scope_.count() > 0) {
170 reductionCS_.enter();
172 for (o = overlays_.begin(); o != overlays_.end();) {
174 if ((*o)->is_invalidated())
175 o = overlays_.erase(o);
178 auto birth_time = ((PGMOverlay *)*o)->get_birth_time();
179 if (birth_time.time_since_epoch().count() > 0 && now - birth_time > time_scope_) {
180 o = overlays_.erase(o);
182 Overlay *offspring = (*o)->reduce(input);
184 overlays_.push_front(offspring);
192 reductionCS_.leave();
195 reductionCS_.enter();
196 for (o = overlays_.begin(); o != overlays_.end();) {
198 if ((*o)->is_invalidated())
199 o = overlays_.erase(o);
202 Overlay *offspring = (*o)->reduce(input);
204 overlays_.push_front(offspring);
211 reductionCS_.leave();
217 AntiPGMController::AntiPGMController(
_View *ipgm_view) : _PGMController(ipgm_view), successful_match_(false) {
219 overlays_.push_back(
new AntiPGMOverlay(
this));
222 AntiPGMController::~AntiPGMController() {
225 void AntiPGMController::take_input(
r_exec::View *input) {
227 Controller::__take_input<AntiPGMController>(input);
232 reductionCS_.enter();
234 for (o = overlays_.begin(); o != overlays_.end();) {
236 if ((*o)->is_invalidated())
237 o = overlays_.erase(o);
240 Overlay *offspring = (*o)->reduce(input);
241 if (successful_match_) {
243 Overlay *overlay = *o;
246 overlays_.push_back(overlay);
247 successful_match_ =
false;
252 overlays_.push_front(offspring);
255 reductionCS_.leave();
258 void AntiPGMController::signal_anti_pgm() {
260 reductionCS_.enter();
261 if (successful_match_)
262 successful_match_ =
false;
265 Overlay *overlay = overlays_.front();
266 ((AntiPGMOverlay *)overlay)->inject_productions();
268 if (!run_once_ && is_alive()) {
271 overlays_.push_back(overlay);
274 reductionCS_.leave();
280 void AntiPGMController::restart() {
282 push_new_signaling_job();
283 successful_match_ =
true;
286 void AntiPGMController::push_new_signaling_job() {
288 Group *host = get_view()->get_host();
290 if (get_view()->get_act() > host->get_act_thr() &&
291 host->get_c_act() > host->get_c_act_thr() &&
292 host->get_c_sln() > host->get_c_sln_thr()) {
295 TimeJob *next_job =
new AntiPGMSignalingJob((
r_exec::View*)view_, Now() + Utils::GetDuration<Code>(get_object(), IPGM_TSC));
296 _Mem::Get()->push_time_job(next_job);