@@ -35,7 +35,7 @@ namespace scl::proto {
3535 * number of useful resources, such as a network, but also the ability to know
3636 * its total running time, as well as the ability to work with threads.
3737 */
38- struct ProtocolEnvironment {
38+ struct Env {
3939 /* *
4040 * @brief Interface for the environment's threading context.
4141 *
@@ -55,6 +55,10 @@ struct ProtocolEnvironment {
5555
5656 /* *
5757 * @brief Interface for the environment's clock context.
58+ *
59+ * This interface essentially models a "stopwatch" of sorts. The idea is that
60+ * it will start ticking when a protocol starts. The protocol can check the
61+ * current elapsed time at any point, and mark checkpoints.
5862 */
5963 struct Clock {
6064 virtual ~Clock (){};
@@ -63,6 +67,11 @@ struct ProtocolEnvironment {
6367 * @brief Read the current value of the clock.
6468 */
6569 virtual util::Time::Duration Read () const = 0;
70+
71+ /* *
72+ * @brief Record a checkpoint with an associated message.
73+ */
74+ virtual void Checkpoint (const std::string& message) = 0;
6675 };
6776
6877 /* *
@@ -82,16 +91,32 @@ struct ProtocolEnvironment {
8291};
8392
8493/* *
85- * @brief A protocol clock which returns the total running time.
94+ * @deprecated
95+ */
96+ using ProtocolEnvironment = Env;
97+
98+ /* *
99+ * @brief A protocol clock which operates with real time.
86100 */
87- class RealTimeClock final : public ProtocolEnvironment ::Clock {
101+ class RealTimeClock final : public Env ::Clock {
88102 public:
89- RealTimeClock () : m_init_time(util::Time::Now()){};
90- ~RealTimeClock (){};
103+ RealTimeClock () : m_init_time(util::Time::Now()) {}
104+ ~RealTimeClock () {}
91105
106+ /* *
107+ * @brief Get the current time.
108+ */
92109 util::Time::Duration Read () const {
93110 return util::Time::Now () - m_init_time;
94- };
111+ }
112+
113+ /* *
114+ * @brief Print the current time to stdout.
115+ */
116+ void Checkpoint (const std::string& message) {
117+ auto ms = std::chrono::duration<double , std::milli>(Read ()).count ();
118+ std::cout << message << " @ " << ms << " ms\n " ;
119+ }
95120
96121 private:
97122 util::Time::TimePoint m_init_time;
@@ -100,16 +125,16 @@ class RealTimeClock final : public ProtocolEnvironment::Clock {
100125/* *
101126 * @brief A protocol thread context which uses STL thread.
102127 */
103- class StlThreadContext final : public ProtocolEnvironment ::Thread {
128+ class StlThreadContext final : public Env ::Thread {
104129 public:
105- ~StlThreadContext (){};
130+ ~StlThreadContext () {}
106131
107132 /* *
108133 * @brief Sleep the current thread using std::this_thread::sleep_for.
109134 */
110135 void Sleep (std::size_t ms) override {
111136 std::this_thread::sleep_for (std::chrono::milliseconds (ms));
112- };
137+ }
113138};
114139
115140} // namespace scl::proto
0 commit comments