Browse Source

Post a closure from the ecall_comms_start callback

instead of explicitly raising a condition variable, which is waited on
in the thread that called ecall_comms_start
Ian Goldberg 1 year ago
parent
commit
3ca79eff8c
1 changed files with 6 additions and 16 deletions
  1. 6 16
      App/teems.cpp

+ 6 - 16
App/teems.cpp

@@ -1,8 +1,6 @@
 #include <iostream>
 #include <cstdio>
 #include <cstring>
-#include <condition_variable>
-#include <mutex>
 
 #include <boost/asio.hpp>
 #include <boost/thread.hpp>
@@ -245,19 +243,15 @@ int main(int argc, char **argv)
 
     // Queue up the actual work
     boost::asio::post(io_context, [&]{
-        // Create a condition variable and mutex to block on until
-        // communication with all other nodes is established
-        bool comms_ready = false;
-        std::mutex m;
-        std::condition_variable cv;
 
         // Start enclave-to-enclave communications
         ecall_comms_start([&]{
-            {
-                std::lock_guard lk(m);
-                comms_ready = true;
-            }
-            cv.notify_one();
+            boost::asio::post(io_context, [&]{
+                // This runs when we have completed our handshakes with
+                // all other nodes
+                printf("Starting\n");
+                start(netio, argv);
+            });
         });
         printf("Reading\n");
         for (nodenum_t node_num = 0; node_num < netio.num_nodes; ++node_num) {
@@ -273,10 +267,6 @@ int main(int argc, char **argv)
                     printf("Epoch %u\n", epoch);
                 });
         }
-        std::unique_lock lk(m);
-        cv.wait(lk, [&]{ return comms_ready; });
-        printf("Starting\n");
-        start(netio, argv);
     });
 
     // Start another thread; one will perform the work and the other