ROOT-Sim core  3.0.0-rc.2
A General-Purpose Multi-threaded Parallel/Distributed Simulation Library
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_on_gvt(simtime_t current_gvt);
24 
25 static inline struct lp_msg *msg_allocator_pack(lp_id_t receiver, simtime_t timestamp, unsigned event_type,
26  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 
34  if(likely(payload_size))
35  memcpy(msg->pl, payload, payload_size);
36  return msg;
37 }
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
#define likely(exp)
Optimize the branch as likely taken.
Definition: core.h:49
Message management functions.
struct lp_msg * msg_allocator_pack(lp_id_t receiver, simtime_t timestamp, unsigned event_type, const void *payload, unsigned payload_size)
Allocate a new message and populate it.
void msg_allocator_free_at_gvt(struct lp_msg *msg)
Free a message after its destination time is committed.
Definition: msg_allocator.c:81
void msg_allocator_free(struct lp_msg *msg)
Free a message.
Definition: msg_allocator.c:69
void msg_allocator_fini(void)
Finalize the message allocator thread-local data structures.
Definition: msg_allocator.c:32
struct lp_msg * msg_allocator_alloc(unsigned payload_size)
Allocate a new message with given payload size.
Definition: msg_allocator.c:51
void msg_allocator_on_gvt(simtime_t current_gvt)
Free the committed messages after a new GVT has been computed.
Definition: msg_allocator.c:90
void msg_allocator_init(void)
Initialize the message allocator thread-local data structures.
Definition: msg_allocator.c:23
A model simulation message.
Definition: msg.h:59
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
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