ROOT-Sim core  3.0.0-rc.2
A General-Purpose Multi-threaded Parallel/Distributed Simulation Library
msg.h
Go to the documentation of this file.
1 
11 #pragma once
12 
13 #include <core/core.h>
14 
15 #include <limits.h>
16 #include <stdatomic.h>
17 #include <stddef.h>
18 #include <string.h>
19 
21 #define MSG_PAYLOAD_BASE_SIZE 32
22 
29 #define msg_is_before(a, b) ((a)->dest_t < (b)->dest_t || ((a)->dest_t == (b)->dest_t && msg_is_before_extended(a, b)))
30 
36 #define msg_preamble_size() (offsetof(struct lp_msg, dest))
37 
43 #define msg_remote_data(msg) (&(msg)->dest)
44 
50 #define msg_remote_size(msg) (offsetof(struct lp_msg, pl) - msg_preamble_size() + (msg)->pl_size)
51 
56 #define msg_remote_anti_size() (offsetof(struct lp_msg, m_seq) - msg_preamble_size() + sizeof(uint32_t))
57 
59 struct lp_msg {
61  struct lp_msg *next;
66  union {
68  _Atomic uint32_t flags;
70  uint32_t raw_flags;
71  };
72 #ifndef NDEBUG
77 #endif
79  uint32_t m_seq;
81  uint32_t m_type;
83  uint32_t pl_size;
85  unsigned char pl[MSG_PAYLOAD_BASE_SIZE];
87  unsigned char extra_pl[];
88 };
89 
90 enum msg_flag { MSG_FLAG_ANTI = 1, MSG_FLAG_PROCESSED = 2 };
91 
103 static inline bool msg_is_before_extended(const struct lp_msg *restrict a, const struct lp_msg *restrict b)
104 {
105  if ((a->raw_flags & MSG_FLAG_ANTI) != (b->raw_flags & MSG_FLAG_ANTI))
106  return (a->raw_flags & MSG_FLAG_ANTI) > (b->raw_flags & MSG_FLAG_ANTI);
107 
108  if (a->m_type != b->m_type)
109  return a->m_type > b->m_type;
110 
111  if (a->pl_size != b->pl_size)
112  return a->pl_size < b->pl_size;
113 
114  return memcmp(a->pl, b->pl, a->pl_size) > 0;
115 }
double simtime_t
Simulation time data type.
Definition: ROOT-Sim.h:27
uint64_t lp_id_t
Logical Process ID data type.
Definition: ROOT-Sim.h:33
Core ROOT-Sim functionalities.
static bool msg_is_before_extended(const struct lp_msg *restrict a, const struct lp_msg *restrict b)
Compute a deterministic order for messages with same timestamp.
Definition: msg.h:103
#define MSG_PAYLOAD_BASE_SIZE
The minimum size of the payload to which message allocations are snapped to.
Definition: msg.h:21
A model simulation message.
Definition: msg.h:59
uint32_t raw_flags
The message unique id, used for inter-node anti messages.
Definition: msg.h:70
uint32_t m_type
The message type, a user controlled field.
Definition: msg.h:81
unsigned char pl[MSG_PAYLOAD_BASE_SIZE]
The initial part of the payload.
Definition: msg.h:85
unsigned char extra_pl[]
The continuation of the payload.
Definition: msg.h:87
struct lp_msg * next
The next element in the message list (used in the message queue)
Definition: msg.h:61
_Atomic uint32_t flags
The flags to handle local anti messages.
Definition: msg.h:68
lp_id_t send
The sender of the message.
Definition: msg.h:74
simtime_t send_t
The send time of the message.
Definition: msg.h:76
simtime_t dest_t
The intended destination logical time of this message.
Definition: msg.h:65
lp_id_t dest
The id of the recipient LP.
Definition: msg.h:63
uint32_t m_seq
The message sequence number.
Definition: msg.h:79
uint32_t pl_size
The message payload size.
Definition: msg.h:83