My Project
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros
message_queue.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 <stdbool.h>
29 #include <inttypes.h>
30 #include <unistd.h>
31 #include <pthread.h>
32 #include <semaphore.h>
33 
39 };
40 
42 struct dedos_msg {
44  struct dedos_msg *next;
48  void *data;
50  ssize_t data_size;
52  struct timespec delivery_time;
53 };
54 
56 struct msg_queue {
58  struct dedos_msg *head;
59  struct dedos_msg *tail;
60  pthread_mutex_t mutex;
61  bool shared;
62  sem_t *sem;
63 };
64 
70 struct dedos_msg *dequeue_msg(struct msg_queue *q);
71 
76 int enqueue_msg(struct msg_queue *q, struct dedos_msg *msg);
77 
82 int schedule_msg(struct msg_queue *q, struct dedos_msg *msg, struct timespec *interval);
83 
88 int init_msg_queue(struct msg_queue *q, sem_t *sem);
89 #endif //DEDOS_THREADS_H_
Container for linked list message queue.
Definition: message_queue.h:56
A linked-list entry containing a message.
Definition: message_queue.h:42
enum dedos_msg_type type
Target of delivery: runtime, thread, or MSU.
Definition: message_queue.h:46
int schedule_msg(struct msg_queue *q, struct dedos_msg *msg, struct timespec *interval)
Schedules a message to be delivered once interval time has passed.
Definition: message_queue.c:38
int init_msg_queue(struct msg_queue *q, sem_t *sem)
Initilializes a mesasge queue to have no messages in it, and sets up the mutex and semaphore...
sem_t * sem
Post to this semaphore on each new enqueue.
Definition: message_queue.h:62
struct dedos_msg * tail
Last entry in the queue.
Definition: message_queue.h:59
struct dedos_msg * head
First entry in the queue.
Definition: message_queue.h:58
struct timespec delivery_time
Message is ignored until this time (in CLOCK_MONOTONIC_COARSE) has passed.
Definition: message_queue.h:52
int enqueue_msg(struct msg_queue *q, struct dedos_msg *msg)
Enqueues a message to be delivered as soon as possible.
Definition: message_queue.c:34
uint32_t num_msgs
Number of messages currently in the queue.
Definition: message_queue.h:57
dedos_msg_type
Messages can either be for delivery to runtime, thread, or MSU.
Definition: message_queue.h:35
struct dedos_msg * next
The next message in the list, or NULL if N/A.
Definition: message_queue.h:44
bool shared
Whether the queue needs to be locked (always true at the moment)
Definition: message_queue.h:61
struct dedos_msg * dequeue_msg(struct msg_queue *q)
Dequeues the first available message from q.
Definition: message_queue.c:87
void * data
Payload.
Definition: message_queue.h:48
unsigned int uint32_t
Definition: uthash.h:96
pthread_mutex_t mutex
Mutex if the queue is shared.
Definition: message_queue.h:60
ssize_t data_size
Size of payload.
Definition: message_queue.h:50