The ROme OpTimistic Simulator  3.0.0
A General-Purpose Multithreaded Parallel/Distributed Simulation Platform
msg_queue.c File Reference

Message queue datatype. More...

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

Go to the source code of this file.

Data Structures

struct  msg_queue
 A queue synchronized by a spinlock. More...
 

Macros

#define mqueue(from, to)   (&queues[to * n_threads + from])
 Utility macro to fetch the correct inner queue.
 

Functions

void msg_queue_global_init (void)
 Initializes the message queue at the node level.
 
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.
 
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_queuequeues
 The queues matrix, linearized in a contiguous array.
 

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 by a n * n square matrix of simpler queues. If thread t1 wants to send a message to thread t2 it puts a message in the i-th queue where i = t2 * n + t1. Insertions are then cheap, while extractions lazily lock the queues (costing linear time in the number of worked threads, which seems to be acceptable in practice).

Definition in file msg_queue.c.

Function Documentation

◆ 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.

Definition at line 98 of file msg_queue.c.

◆ 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

Definition at line 168 of file msg_queue.c.

◆ 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.

Definition at line 137 of file msg_queue.c.