My Project
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros
worker_thread.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 WORKER_THREAD_H_
27 #define WORKER_THREAD_H_
28 #include "dedos_threads.h"
29 
30 // Forward declaration for circular dependency
31 struct local_msu;
32 
34 struct timeout_list {
35  struct timespec time;
36  struct timeout_list *next;
37 };
38 
40 struct worker_thread {
44  int n_msus;
46  pthread_mutex_t exit_lock;
52 };
53 
57 struct worker_thread *get_worker_thread(int id);
58 
63 
68 int create_worker_thread(unsigned int thread_id, enum blocking_mode mode);
69 
74 int unregister_msu_with_thread(struct local_msu *msu);
75 
80 int register_msu_with_thread(struct local_msu *msu);
81 
87 int enqueue_worker_timeout(struct worker_thread *thread, struct timespec *interval);
88 
89 #endif
Representation of a thread that holds MSUs, messages, and waits on a semaphore.
Definition: worker_thread.h:40
void stop_worker_thread(struct worker_thread *thread)
Signals the given worker thread that it should stop execution and exit its main loop.
int enqueue_worker_timeout(struct worker_thread *thread, struct timespec *interval)
Signals that the given thread should break when waiting on its semaphore once interval time has passe...
struct timeout_list * timeouts
The times at which the sem_trywait on on the local semaphore should be released.
Definition: worker_thread.h:51
#define MAX_MSU_PER_THREAD
The maximum number of MSUs which can be placed on a single thread.
Definition: dfg.h:61
Control spawned threads with message queue within DeDOS.
void stop_all_worker_threads()
Signals all worker threads to stop.
Definition: worker_thread.c:54
An entry in the linked list of timeouts.
Definition: worker_thread.h:34
struct local_msu * msus[MAX_MSU_PER_THREAD]
The MSUs on the thread.
Definition: worker_thread.h:49
blocking_mode
Whether an MSU is blocking or non-blocking.
Definition: dfg.h:161
The structure that represents an MSU located on the local machine.
Definition: local_msu.h:38
int n_msus
The number of msus on the thread.
Definition: worker_thread.h:44
int unregister_msu_with_thread(struct local_msu *msu)
Removes an MSU from the list of MSUs within its thread.
struct timeout_list * next
Definition: worker_thread.h:36
pthread_mutex_t exit_lock
Lock protecting the worker_thread::exit_signal.
Definition: worker_thread.h:46
int create_worker_thread(unsigned int thread_id, enum blocking_mode mode)
Starts a new worker thread with the given thread ID and pinned/unpinned status.
int register_msu_with_thread(struct local_msu *msu)
Registers an MSU as one that should be run on its assigned thread.
struct dedos_thread * thread
The underlying dedos_thread.
Definition: worker_thread.h:42
struct worker_thread * get_worker_thread(int id)
Definition: worker_thread.c:79
struct timespec time
Definition: worker_thread.h:35
Structure representing any thread within DeDOS.
Definition: dedos_threads.h:35