Browse Source

Move definition of MsgBuffer from route.cpp to route.hpp

Changes extracted from aa86ecf9c1ff064a932fe6346e54aa474158df71:

Client -> Ingestion send (unencrypted) message bundles. Ingestion servers queue them into a msgBuffer
Sajin Sasy 1 year ago
parent
commit
e544d6db67
2 changed files with 54 additions and 53 deletions
  1. 0 53
      Enclave/route.cpp
  2. 54 0
      Enclave/route.hpp

+ 0 - 53
Enclave/route.cpp

@@ -1,4 +1,3 @@
-#include <pthread.h>
 #include "Enclave_t.h"
 #include "config.hpp"
 #include "utils.hpp"
@@ -10,58 +9,6 @@
 
 #define PROFILE_ROUTING
 
-struct MsgBuffer {
-    pthread_mutex_t mutex;
-    uint8_t *buf;
-    // The number of messages (not bytes) in, or on their way into, the
-    // buffer
-    uint32_t reserved;
-    // The number of messages definitely in the buffer
-    uint32_t inserted;
-    // The number of messages that can fit in buf
-    uint32_t bufsize;
-    // The number of nodes we've heard from
-    nodenum_t nodes_received;
-    // Have we completed the previous round yet?
-    bool completed_prev_round;
-
-    MsgBuffer() : buf(NULL), reserved(0), inserted(0), bufsize(0),
-            nodes_received(0), completed_prev_round(false) {
-        pthread_mutex_init(&mutex, NULL);
-    }
-
-    ~MsgBuffer() {
-        delete[] buf;
-    }
-
-    // The number passed is messages, not bytes
-    void alloc(uint32_t msgs) {
-        delete[] buf;
-        buf = NULL;
-        reserved = 0;
-        inserted = 0;
-        // This may throw bad_alloc, but we'll catch it higher up
-        buf = new uint8_t[size_t(msgs) * g_teems_config.msg_size];
-        memset(buf, 0, size_t(msgs) * g_teems_config.msg_size);
-        bufsize = msgs;
-        nodes_received = 0;
-        completed_prev_round = false;
-    }
-
-    // Reset the contents of the buffer
-    void reset() {
-        memset(buf, 0, bufsize * g_teems_config.msg_size);
-        reserved = 0;
-        inserted = 0;
-        nodes_received = 0;
-        completed_prev_round = false;
-    }
-
-    // You can't copy a MsgBuffer
-    MsgBuffer(const MsgBuffer&) = delete;
-    MsgBuffer &operator=(const MsgBuffer&) = delete;
-};
-
 enum RouteStep {
     ROUTE_NOT_STARTED,
     ROUTE_ROUND_1,

+ 54 - 0
Enclave/route.hpp

@@ -1,6 +1,60 @@
 #ifndef __ROUTE_HPP__
 #define __ROUTE_HPP__
 
+#include <pthread.h>
+
+struct MsgBuffer {
+    pthread_mutex_t mutex;
+    uint8_t *buf;
+    // The number of messages (not bytes) in, or on their way into, the
+    // buffer
+    uint32_t reserved;
+    // The number of messages definitely in the buffer
+    uint32_t inserted;
+    // The number of messages that can fit in buf
+    uint32_t bufsize;
+    // The number of nodes we've heard from
+    nodenum_t nodes_received;
+    // Have we completed the previous round yet?
+    bool completed_prev_round;
+
+    MsgBuffer() : buf(NULL), reserved(0), inserted(0), bufsize(0),
+            nodes_received(0), completed_prev_round(false) {
+        pthread_mutex_init(&mutex, NULL);
+    }
+
+    ~MsgBuffer() {
+        delete[] buf;
+    }
+
+    // The number passed is messages, not bytes
+    void alloc(uint32_t msgs) {
+        delete[] buf;
+        buf = NULL;
+        reserved = 0;
+        inserted = 0;
+        // This may throw bad_alloc, but we'll catch it higher up
+        buf = new uint8_t[size_t(msgs) * g_teems_config.msg_size];
+        memset(buf, 0, size_t(msgs) * g_teems_config.msg_size);
+        bufsize = msgs;
+        nodes_received = 0;
+        completed_prev_round = false;
+    }
+
+    // Reset the contents of the buffer
+    void reset() {
+        memset(buf, 0, bufsize * g_teems_config.msg_size);
+        reserved = 0;
+        inserted = 0;
+        nodes_received = 0;
+        completed_prev_round = false;
+    }
+
+    // You can't copy a MsgBuffer
+    MsgBuffer(const MsgBuffer&) = delete;
+    MsgBuffer &operator=(const MsgBuffer&) = delete;
+};
+
 // Call this near the end of ecall_config_load, but before
 // comms_init_nodestate. Returns true on success, false on failure.
 bool route_init();