Charades
trigger.h
1 #ifndef _TRIGGER_H_
2 #define _TRIGGER_H_
3 
4 #include "typedefs.h"
5 #include "scheduler.h"
6 #include "gvtmanager.h"
7 
8 class Trigger {
9  public:
10  virtual ~Trigger() {}
11  virtual void iteration_done() = 0;
12  virtual void reset() = 0;
13  virtual bool ready() const = 0;
14 };
15 
16 class BoundedTrigger : public Trigger {
17  private:
18  TriggerPtr trigger;
19  unsigned triggers_left;
20  public:
21  BoundedTrigger(Trigger* t, unsigned triggers) : trigger(t), triggers_left(triggers) {}
22  void iteration_done() { trigger->iteration_done(); }
23  void reset() { if (triggers_left > 0) triggers_left--; trigger->reset(); }
24  bool ready() const { return triggers_left > 0 && trigger->ready(); }
25 };
26 
27 class ConstTrigger : public Trigger {
28  private:
29  bool value;
30  public:
31  ConstTrigger(bool v) : value(v) {}
32  void iteration_done() {}
33  void reset() {}
34  bool ready() const { return value; }
35 };
36 
37 class CountTrigger : public Trigger {
38  private:
39  unsigned int iter_cnt, iter_max;
40  public:
41  CountTrigger(unsigned max) : iter_cnt(0), iter_max(max) {}
42  CountTrigger(unsigned first, unsigned max)
43  : iter_cnt(max - first), iter_max(max) {}
44  void iteration_done() { iter_cnt++; }
45  void reset() { iter_cnt = 0; }
46  bool ready() const { return iter_cnt >= iter_max; }
47 };
48 
49 // TODO: What do to on resume before GVT is computed?
50 class LeashTrigger : public Trigger {
51  private:
52  Scheduler* scheduler;
53  Time leash;
54  public:
55  LeashTrigger(Scheduler* sched, Time l) : scheduler(sched), leash(l) {}
56  void iteration_done() {}
57  void reset() {}
58  bool ready() const {
59  return scheduler->get_min_time() > scheduler->globals->g_last_gvt + leash;
60  }
61 };
62 
63 #endif
Definition: trigger.h:16
Base class defining basic scheduler functionality.
Definition: scheduler.h:36
Definition: trigger.h:27
Globals * globals
Global variables per PE.
Definition: scheduler.h:47
Declares most types used within the simulator and by models.
Definition: trigger.h:37
Time g_last_gvt
Last computed GVT, used for rollbacks.
Definition: globals.h:82
virtual Time get_min_time() const
Get the minimum time of any event on this PE.
Definition: scheduler.C:112
Definition: trigger.h:50
Definition: trigger.h:8