ROOT-Sim core  3.0.0-rc.2
A General-Purpose Multi-threaded Parallel/Distributed Simulation Library
Classes | Macros | Functions | Variables
msg_queue.c File Reference

Message queue datatype. More...

#include <datatypes/msg_queue.h>
#include <core/sync.h>
#include <datatypes/heap.h>
#include <lp/lp.h>
#include <mm/msg_allocator.h>
#include <stdalign.h>
#include <stdatomic.h>
Include dependency graph for msg_queue.c:

Classes

struct  q_elem
 An element in the message queue. More...
 
struct  msg_buffer
 The multi-threaded message buffer, implemented as a non-blocking list. More...
 

Macros

#define q_elem_is_before(ma, mb)   ((ma).t < (mb).t || ((ma).t == (mb).t && msg_is_before_extended(ma.m, mb.m)))
 Determine an ordering between two elements in a queue.
 

Functions

static __thread heap_declare (struct q_elem)
 The private thread queue. More...
 
void msg_queue_init (void)
 Initializes the message queue for the current thread.
 
void msg_queue_fini (void)
 Finalizes the message queue for the current thread.
 
void msg_queue_global_fini (void)
 Finalizes the message queue at the node level.
 
static void msg_queue_insert_queued (void)
 Move the messages from the thread specific list into the thread private queue.
 
struct lp_msgmsg_queue_extract (void)
 Extracts the next message from the queue. More...
 
simtime_t msg_queue_time_peek (void)
 Peeks the timestamp of the next message from the queue. More...
 
void msg_queue_insert (struct lp_msg *msg)
 Inserts a message in the queue. More...
 

Variables

static struct msg_bufferqueues
 The buffers vector.
 

Detailed Description

Message queue datatype.

This is the message queue for the parallel runtime. The design is pretty simple. A queue for n threads is composed of a vector of n simpler private thread queues plus n public buffers. If thread t1 wants to send a message to thread t2 it puts a message in its buffer. Insertions are then cheap, while extractions simply empty the buffer into the private queue. This way the critically thread locked code is minimal.

Function Documentation

◆ heap_declare()

static __thread heap_declare ( struct q_elem  )
static

The private thread queue.

Initializes the message queue at the node level

◆ msg_queue_extract()

struct lp_msg* msg_queue_extract ( void  )

Extracts the next message from the queue.

Returns
a pointer to the message to be processed or NULL if there isn't one

The extracted message is a best effort lowest timestamp for the current thread. Guaranteeing the lowest timestamp may increase the contention on the queues.

◆ msg_queue_insert()

void msg_queue_insert ( struct lp_msg msg)

Inserts a message in the queue.

Parameters
msgthe message to insert in the queue

◆ msg_queue_time_peek()

simtime_t msg_queue_time_peek ( void  )

Peeks the timestamp of the next message from the queue.

Returns
the lowest timestamp of the next message to be processed or SIMTIME_MAX is there's no message to process

This returns the lowest timestamp of the next message to be processed for the current thread. This is calculated in a precise fashion since this value is used in the gvt calculation.