My Project
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros
Macros | Functions | Variables
output_thread.c File Reference

A dedos_thread which monitors a queue for output to be sent to other runtimes or the global controller. More...

#include "logging.h"
#include "worker_thread.h"
#include "dedos_threads.h"
#include "thread_message.h"
#include "msu_type.h"
#include "controller_communication.h"
#include "ctrl_runtime_messages.h"
#include "output_thread.h"
#include "stats.h"
#include <stdlib.h>
#include <netinet/ip.h>

Go to the source code of this file.

Macros

#define CHECK_MSG_SIZE(msg, target)
 Checks whether the size of the message matches the size of the target struct. More...
 
#define STAT_REPORTING_DURATION_MS   STAT_SAMPLE_PERIOD_MS
 How often to report statistics. More...
 

Functions

static void * init_output_thread (struct dedos_thread *output_thread)
 Initializes the static copy of the output thread. More...
 
static int output_thread_send_to_ctrl (struct send_to_ctrl_msg *msg)
 Process a SEND_TO_CTRL message. More...
 
static int output_thread_send_to_peer (struct send_to_peer_msg *msg)
 Process a SEND_TO_PEER message. More...
 
static int output_thread_connect_to_runtime (struct ctrl_add_runtime_msg *msg)
 Process a CONNECT_TO_RUNTIME message. More...
 
void stop_output_monitor ()
 Triggers the output thread to stop execution. More...
 
void join_output_thread ()
 Joins the underlying pthread. More...
 
static int process_output_thread_msg (struct thread_msg *msg)
 Processes a thread message that is delivered to the output thread. More...
 
static int check_output_thread_queue (struct dedos_thread *output_thread)
 Checks the queue of the output thread for messages and acts on them if present. More...
 
static int output_thread_loop (struct dedos_thread *self, void UNUSED *init_data)
 The main thread loop for the output thread. More...
 
int enqueue_for_output (struct thread_msg *msg)
 Enqueues a thread_msg for delivery to the output thread. More...
 
struct dedos_threadstart_output_monitor_thread (void)
 Starts the thread monitoring the queue for messages to be sent to other endpoints. More...
 

Variables

static struct dedos_threadstatic_output_thread
 A static copy of the output thread, so others can enqueue messages. More...
 

Detailed Description

A dedos_thread which monitors a queue for output to be sent to other runtimes or the global controller.

Definition in file output_thread.c.

Macro Definition Documentation

#define CHECK_MSG_SIZE (   msg,
  target 
)
Value:
if (msg->data_size != sizeof(target)) { \
log_warn("Message data size (%d) does not match size" \
"of target type (%d)" #target, (int)msg->data_size , \
(int)sizeof(target)); \
return -1; \
} \
#define log_warn(fmt,...)
Definition: logging.h:113

Checks whether the size of the message matches the size of the target struct.

Definition at line 96 of file output_thread.c.

#define STAT_REPORTING_DURATION_MS   STAT_SAMPLE_PERIOD_MS

How often to report statistics.

Definition at line 168 of file output_thread.c.

Function Documentation

static int check_output_thread_queue ( struct dedos_thread output_thread)
static

Checks the queue of the output thread for messages and acts on them if present.

Definition at line 151 of file output_thread.c.

int enqueue_for_output ( struct thread_msg thread_msg)

Enqueues a thread_msg for delivery to the output thread.

Message should be of type CONNECT_TO_RUNTIME, SEND_TO_PEER, or SEND_TO_CTRL.

Returns
0 on success, -1 on error

Definition at line 213 of file output_thread.c.

static void* init_output_thread ( struct dedos_thread output_thread)
static

Initializes the static copy of the output thread.

Definition at line 43 of file output_thread.c.

void join_output_thread ( )

Joins the underlying pthread.

Definition at line 90 of file output_thread.c.

static int output_thread_connect_to_runtime ( struct ctrl_add_runtime_msg msg)
static

Process a CONNECT_TO_RUNTIME message.

Definition at line 71 of file output_thread.c.

static int output_thread_loop ( struct dedos_thread self,
void UNUSED init_data 
)
static

The main thread loop for the output thread.

Checks the queue for messages, sends them, sends stats messages

Definition at line 174 of file output_thread.c.

static int output_thread_send_to_ctrl ( struct send_to_ctrl_msg msg)
static

Process a SEND_TO_CTRL message.

Definition at line 49 of file output_thread.c.

static int output_thread_send_to_peer ( struct send_to_peer_msg msg)
static

Process a SEND_TO_PEER message.

Definition at line 60 of file output_thread.c.

static int process_output_thread_msg ( struct thread_msg msg)
static

Processes a thread message that is delivered to the output thread.

Definition at line 105 of file output_thread.c.

struct dedos_thread* start_output_monitor_thread ( void  )

Starts the thread monitoring the queue for messages to be sent to other endpoints.

Definition at line 223 of file output_thread.c.

void stop_output_monitor ( )

Triggers the output thread to stop execution.

Definition at line 86 of file output_thread.c.

Variable Documentation

struct dedos_thread* static_output_thread
static

A static copy of the output thread, so others can enqueue messages.

Definition at line 40 of file output_thread.c.