Browse Source

Add the ability to reset the Lamport clock

Ian Goldberg 1 year ago
parent
commit
f3cb64ea1b
2 changed files with 21 additions and 1 deletions
  1. 11 0
      mpcio.cpp
  2. 10 1
      mpcio.hpp

+ 11 - 0
mpcio.cpp

@@ -467,6 +467,17 @@ void MPCTIO::sync_lamport()
     thread_lamport = new_lamport;
 }
 
+// Only call this if you can be sure that there are no outstanding
+// messages in flight, you can call it on all existing MPCTIOs, and
+// you really want to reset the Lamport clock in the midding of a
+// run.
+void MPCTIO::reset_lamport()
+{
+    // Reset both our own Lamport clock and the parent MPCIO's
+    thread_lamport = 0;
+    mpcio.lamport = 0;
+}
+
 // Queue up data to the peer or to the server
 
 void MPCTIO::queue_peer(const void *data, size_t len)

+ 10 - 1
mpcio.hpp

@@ -309,13 +309,22 @@ public:
     // outlives your thread (in which case call it after the join), or
     // if your threads do interthread communication amongst themselves
     // (in which case call it in the sending thread before the send, and
-    // call it in the receiving thread after the receive).
+    // call it in the receiving thread after the receive).  If you want
+    // to call MPCIO::dump_stats() in the middle of a run (while the
+    // MPCTIO is still alive), call this as well.
     void sync_lamport();
 
+    // Only call this if you can be sure that there are no outstanding
+    // messages in flight, you can call it on all existing MPCTIOs, and
+    // you really want to reset the Lamport clock in the midding of a
+    // run.
+    void reset_lamport();
+
     // The normal case, where the MPCIO is created inside the thread,
     // and so destructed when the thread ends, is handled automatically
     // here.
     ~MPCTIO() {
+        send();
         sync_lamport();
     }