The ROme OpTimistic Simulator  3.0.0
A General-Purpose Multithreaded Parallel/Distributed Simulation Platform
msg_allocator.h
Go to the documentation of this file.
1 
11 #pragma once
12 
13 #include <lp/msg.h>
14 
15 #include <memory.h>
16 
17 extern void msg_allocator_init(void);
18 extern void msg_allocator_fini(void);
19 
20 extern struct lp_msg* msg_allocator_alloc(unsigned payload_size);
21 extern void msg_allocator_free (struct lp_msg *msg);
22 extern void msg_allocator_free_at_gvt (struct lp_msg *msg);
23 extern void msg_allocator_fossil_collect(simtime_t current_gvt);
24 
25 inline struct lp_msg* msg_allocator_pack(lp_id_t receiver, simtime_t timestamp,
26  unsigned event_type, const void *payload, unsigned payload_size)
27 {
28  struct lp_msg *msg = msg_allocator_alloc(payload_size);
29 
30  msg->dest = receiver;
31  msg->dest_t = timestamp;
32  msg->m_type = event_type;
33  msg->pl_size = payload_size;
34 
35  if(likely(payload_size))
36  memcpy(msg->pl, payload, payload_size);
37  return msg;
38 }
simtime_t
double simtime_t
The type used to represent logical time in the simulation.
Definition: core.h:62
lp_msg::m_type
uint_fast32_t m_type
The message type, a user controlled field.
Definition: msg.h:40
lp_msg
A model simulation message.
Definition: msg.h:34
msg.h
Message management functions.
lp_msg::dest
lp_id_t dest
The id of the recipient LP.
Definition: msg.h:36
likely
#define likely(exp)
Optimize the branch as likely taken.
Definition: core.h:57
lp_msg::pl
unsigned char pl[48]
The initial part of the payload.
Definition: msg.h:54
lp_id_t
uint64_t lp_id_t
Used to uniquely identify LPs in the simulation.
Definition: core.h:75
lp_msg::pl_size
uint_fast32_t pl_size
The message payload size.
Definition: msg.h:46
lp_msg::dest_t
simtime_t dest_t
The intended destination logical time of this message.
Definition: msg.h:38