My Project
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros
dedos_threads.h
Go to the documentation of this file.
1 /*
2 START OF LICENSE STUB
3  DeDOS: Declarative Dispersion-Oriented Software
4  Copyright (C) 2017 University of Pennsylvania, Georgetown University
5 
6  This program is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 END OF LICENSE STUB
19 */
26 #ifndef DEDOS_THREADS_H
27 #define DEDOS_THREADS_H
28 #include <unistd.h>
29 #include <pthread.h>
30 #include <semaphore.h>
31 #include "message_queue.h"
32 #include "dfg.h"
33 
35 struct dedos_thread {
37  pthread_t pthread;
39  int id;
43  struct msg_queue queue;
45  sem_t sem;
47  pthread_mutex_t exit_lock;
51  struct timespec last_metric;
52 };
53 
55 struct dedos_thread *get_dedos_thread(int id);
56 
62 typedef void* (*dedos_thread_init_fn)(struct dedos_thread *thread);
63 
70 typedef int (*dedos_thread_fn)(struct dedos_thread *thread, void *init_output);
71 
77 typedef void (*dedos_thread_destroy_fn)(struct dedos_thread *thread, void *init_output);
78 
89  dedos_thread_init_fn init_fn,
90  dedos_thread_destroy_fn destroy_fn,
91  enum blocking_mode mode,
92  int id,
93  struct dedos_thread *thread);
94 
96 int dedos_thread_should_exit(struct dedos_thread *thread);
98 void dedos_thread_stop(struct dedos_thread *thread);
100 void dedos_thread_join(struct dedos_thread *thread);
107 int thread_wait(struct dedos_thread *thread, struct timespec *abs_timeout);
108 
109 #endif // DEDOS_THREADS_H
thread_mode
Identifies if a thread is pinned to a core or able to be scheduled on any core.
Definition: dfg.h:91
int exit_signal
For checking if thread should exit.
Definition: dedos_threads.h:49
struct timespec last_metric
For logging thread metrics.
Definition: dedos_threads.h:51
enum thread_mode mode
[un]pinned
Definition: dedos_threads.h:41
Container for linked list message queue.
Definition: message_queue.h:56
pthread_mutex_t exit_lock
For checking if thread should exit.
Definition: dedos_threads.h:47
pthread_t pthread
The underlying pthread.
Definition: dedos_threads.h:37
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.
int dedos_thread_should_exit(struct dedos_thread *thread)
Returns 1 if the exit signal has been triggered, otherwise 0.
struct dedos_thread * get_dedos_thread(int id)
Returns the dedos_thread with the given ID.
Definition: dedos_threads.c:72
int id
A unique identifier for the thread.
Definition: dedos_threads.h:39
blocking_mode
Whether an MSU is blocking or non-blocking.
Definition: dfg.h:161
Structures and functions for enqueueing and dequeuing general-purpose messages from a queue...
void dedos_thread_stop(struct dedos_thread *thread)
Sets the exit signal for a thread, causing the main loop to quit.
void(* dedos_thread_destroy_fn)(struct dedos_thread *thread, void *init_output)
Typedef for the destructor function for a dedos_thread.
Definition: dedos_threads.h:77
Interfaces for the creation and modification of the data-flow-graph and and general description of th...
void dedos_thread_join(struct dedos_thread *thread)
Joins and destroys the dedos_thread.
sem_t sem
Locks thread until a message is available.
Definition: dedos_threads.h:45
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 ...
int(* dedos_thread_fn)(struct dedos_thread *thread, void *init_output)
Typedef for the function that should be called on a dedos_thread.
Definition: dedos_threads.h:70
struct msg_queue queue
Queue for incoming message.
Definition: dedos_threads.h:43
void *(* dedos_thread_init_fn)(struct dedos_thread *thread)
Typedef for an initialization function for a dedos_thread.
Definition: dedos_threads.h:62
Structure representing any thread within DeDOS.
Definition: dedos_threads.h:35