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_thread * | get_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... | |
Control spawned threads with message queue within DeDOS.
Definition in file dedos_threads.h.
typedef void(* dedos_thread_destroy_fn)(struct dedos_thread *thread, void *init_output) |
Typedef for the destructor function for a dedos_thread.
thread | The thread bneing destroyed |
init_output | The 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.
thread | The thread being executed |
init_output | The output of the dedos_thread_init_fn |
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.
thread | The thread under initilization |
Definition at line 62 of file dedos_threads.h.
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.
init_fn | The function to execute once, at the start of the thread |
destroy_fn | The function to execute when the thread exits |
mode | [un]pinned |
id | Unique identifier for the thread |
thread | The 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.
thread | The thread to block from |
abs_timeout | Time since epoch at which thread should block until |
Definition at line 234 of file dedos_threads.c.