123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- #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();
- // Call when shutting system down to deallocate routing state
- void route_close();
- // For a given other node, set the received message handler to the first
- // message we would expect from them, given their roles and our roles.
- void route_init_msg_handler(nodenum_t node_num);
- #endif
|