37 if (queue->
valid || queue->
head || queue->
tail) {
return false; }
38 pthread_mutexattr_t ma = {0};
39 pthread_mutexattr_init(&ma);
40 pthread_mutexattr_settype(&ma, PTHREAD_MUTEX_ERRORCHECK);
41 pthread_mutex_init(&(queue->
lock), &ma);
42 pthread_mutexattr_destroy(&ma);
44 if (pthread_mutex_lock(&(queue->
lock))) {
53 pthread_mutex_unlock(&(queue->
lock));
66 if (pthread_mutex_lock(&(queue->
lock))) {
67 perror(
"queue_destroy");
71 if (queue->
head == NULL) {
75 pthread_mutex_unlock(&(queue->
lock));
76 pthread_mutex_destroy(&(queue->
lock));
91 pthread_mutex_unlock(&(queue->
lock));
92 pthread_mutex_destroy(&(queue->
lock));
129 if (!queue->
valid) {
return false; }
133 if (pthread_mutex_lock(&(queue->
lock))) {
135 perror(
"queue_push_qi");
142 if (queue->
head == NULL) {
145 pthread_mutex_unlock(&(queue->
lock));
170 pthread_mutex_unlock(&(queue->
lock));
187 int e = pthread_mutex_lock(&(queue->
lock));
195 if (head == NULL || !queue->
valid) {
197 pthread_mutex_unlock(&(queue->
lock));
206 if (queue->
tail == head) { queue->
tail = NULL; }
207 pthread_mutex_unlock(&(queue->
lock));
220 if (!queue->
valid) {
return -1; }
222 if (queue->
head == NULL) {
return 0; }
void msg_destroy(msg_t *msg)
Destroy a message.
int queue_count(const msgqueue *queue)
Iterate over queue and return current number of items.
bool queue_push(msgqueue *queue, msg_t *msg)
Add a message to the tail of the queue.
msg_t * queue_pop(msgqueue *queue)
Remove topmost item from the queue and return it, if queue is not empty.
bool queue_push_qi(msgqueue *queue, queueitem *item)
Add a queue item to the tail of the queue.
void queue_destroy(msgqueue *queue)
Invalidate queue and destroy all contents.
bool queue_init(msgqueue *queue)
Ensure queue structure is set to known good values and marked valid.
Represent a simple FIFO message queue.
queueitem * head
Points to first message, or NULL if empty.
pthread_mutex_t lock
Queue lock.
queueitem * tail
brief Tail entry hint
msg_t * item
Queued message.
queueitem * next
Pointer to next item, or NULL for queue tail.