My Project
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros
Classes | Typedefs | Functions
dedos_threads.h File Reference

Control spawned threads with message queue within DeDOS. More...

#include <unistd.h>
#include <pthread.h>
#include <semaphore.h>
#include "message_queue.h"
#include "dfg.h"

Go to the source code of this file.

Classes

struct  dedos_thread
 Structure representing any thread within DeDOS. More...
 

Typedefs

typedef void *(* dedos_thread_init_fn )(struct dedos_thread *thread)
 Typedef for an initialization function for a dedos_thread. More...
 
typedef int(* dedos_thread_fn )(struct dedos_thread *thread, void *init_output)
 Typedef for the function that should be called on a dedos_thread. More...
 
typedef void(* dedos_thread_destroy_fn )(struct dedos_thread *thread, void *init_output)
 Typedef for the destructor function for a dedos_thread. More...
 

Functions

struct dedos_threadget_dedos_thread (int id)
 Returns the dedos_thread with the given ID. More...
 
int start_dedos_thread (dedos_thread_fn thread_fn, dedos_thread_init_fn init_fn, dedos_thread_destroy_fn destroy_fn, enum blocking_mode mode, int id, struct dedos_thread *thread)
 Initilizes and starts execution of a dedos_thread. More...
 
int dedos_thread_should_exit (struct dedos_thread *thread)
 Returns 1 if the exit signal has been triggered, otherwise 0. More...
 
void dedos_thread_stop (struct dedos_thread *thread)
 Sets the exit signal for a thread, causing the main loop to quit. More...
 
void dedos_thread_join (struct dedos_thread *thread)
 Joins and destroys the dedos_thread. More...
 
int thread_wait (struct dedos_thread *thread, struct timespec *abs_timeout)
 To be called from the thread, causes it to wait until a message has been received or the timeout has been reached. More...
 

Detailed Description

Control spawned threads with message queue within DeDOS.

Definition in file dedos_threads.h.

Typedef Documentation

typedef void(* dedos_thread_destroy_fn)(struct dedos_thread *thread, void *init_output)

Typedef for the destructor function for a dedos_thread.

Parameters
threadThe thread bneing destroyed
init_outputThe output of the dedos_thread_init_fn

Definition at line 77 of file dedos_threads.h.

typedef int(* dedos_thread_fn)(struct dedos_thread *thread, void *init_output)

Typedef for the function that should be called on a dedos_thread.

Parameters
threadThe thread being executed
init_outputThe output of the dedos_thread_init_fn
Returns
should return 0 on success, -1 on error

Definition at line 70 of file dedos_threads.h.

typedef void*(* dedos_thread_init_fn)(struct dedos_thread *thread)

Typedef for an initialization function for a dedos_thread.

Parameters
threadThe thread under initilization
Returns
An object which is passed into the thread_fn and destroy_fn

Definition at line 62 of file dedos_threads.h.

Function Documentation

void dedos_thread_join ( struct dedos_thread thread)

Joins and destroys the dedos_thread.

Definition at line 158 of file dedos_threads.c.

int dedos_thread_should_exit ( struct dedos_thread thread)

Returns 1 if the exit signal has been triggered, otherwise 0.

Definition at line 163 of file dedos_threads.c.

void dedos_thread_stop ( struct dedos_thread thread)

Sets the exit signal for a thread, causing the main loop to quit.

Definition at line 149 of file dedos_threads.c.

struct dedos_thread* get_dedos_thread ( int  id)

Returns the dedos_thread with the given ID.

Definition at line 72 of file dedos_threads.c.

int start_dedos_thread ( dedos_thread_fn  thread_fn,
dedos_thread_init_fn  init_fn,
dedos_thread_destroy_fn  destroy_fn,
enum blocking_mode  mode,
int  id,
struct dedos_thread thread 
)

Initilizes and starts execution of a dedos_thread.

Note: Blocks until the thread is started! thread_fn The function to execute once the thread starts.

Parameters
init_fnThe function to execute once, at the start of the thread
destroy_fnThe function to execute when the thread exits
mode[un]pinned
idUnique identifier for the thread
threadThe object into which to store the thread

Definition at line 269 of file dedos_threads.c.

int thread_wait ( struct dedos_thread thread,
struct timespec *  abs_timeout 
)

To be called from the thread, causes it to wait until a message has been received or the timeout has been reached.

Parameters
threadThe thread to block from
abs_timeoutTime since epoch at which thread should block until

Definition at line 234 of file dedos_threads.c.