SELKIELogger  1.0.0
queue.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2023 Swansea University
3  *
4  * This file is part of the SELKIELogger suite of tools.
5  *
6  * SELKIELogger is free software: you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License as published by the Free
8  * Software Foundation, either version 3 of the License, or (at your option)
9  * any later version.
10  *
11  * SELKIELogger is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14  * more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this SELKIELogger product.
18  * If not, see <http://www.gnu.org/licenses/>.
19 */
20 
21 #ifndef SELKIELoggerBase_Queue
22 #define SELKIELoggerBase_Queue
23 
24 #include <pthread.h>
25 #include <stdbool.h>
26 
27 #include "messages.h"
28 
41 typedef struct queueitem queueitem;
42 
51 typedef struct msgqueue {
54  pthread_mutex_t lock;
55  bool valid;
57 
67 struct queueitem {
70 };
71 
73 bool queue_init(msgqueue *queue);
74 
76 void queue_destroy(msgqueue *queue);
77 
79 bool queue_push(msgqueue *queue, msg_t *item);
80 
82 bool queue_push_qi(msgqueue *queue, queueitem *item);
83 
85 msg_t *queue_pop(msgqueue *queue);
86 
88 int queue_count(const msgqueue *queue);
90 #endif
int queue_count(const msgqueue *queue)
Iterate over queue and return current number of items.
Definition: queue.c:219
struct msgqueue msgqueue
Represent a simple FIFO message queue.
bool queue_push(msgqueue *queue, msg_t *item)
Add a message to the tail of the queue.
Definition: queue.c:103
msg_t * queue_pop(msgqueue *queue)
Remove topmost item from the queue and return it, if queue is not empty.
Definition: queue.c:186
bool queue_push_qi(msgqueue *queue, queueitem *item)
Add a queue item to the tail of the queue.
Definition: queue.c:128
void queue_destroy(msgqueue *queue)
Invalidate queue and destroy all contents.
Definition: queue.c:64
bool queue_init(msgqueue *queue)
Ensure queue structure is set to known good values and marked valid.
Definition: queue.c:35
Queuable message.
Definition: messages.h:71
Represent a simple FIFO message queue.
Definition: queue.h:51
queueitem * head
Points to first message, or NULL if empty.
Definition: queue.h:52
bool valid
Queue status.
Definition: queue.h:55
pthread_mutex_t lock
Queue lock.
Definition: queue.h:54
queueitem * tail
brief Tail entry hint
Definition: queue.h:53
msg_t * item
Queued message.
Definition: queue.h:68
queueitem * next
Pointer to next item, or NULL for queue tail.
Definition: queue.h:69