From 77c7dc7ffcaa64879e90178df5585f22790f46be Mon Sep 17 00:00:00 2001 From: Tomas Mudrunka Date: Tue, 29 Jun 2021 14:22:10 +0200 Subject: [PATCH] Vacant --- c/pthread_extra/pthread_extra.h | 5 ++++- c/pthread_extra/pthread_msgqueue.c | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/c/pthread_extra/pthread_extra.h b/c/pthread_extra/pthread_extra.h index 0652e0a..861b847 100644 --- a/c/pthread_extra/pthread_extra.h +++ b/c/pthread_extra/pthread_extra.h @@ -64,11 +64,14 @@ typedef struct pthread_mq_t { bool pthread_mq_init(pthread_mq_t *mq, size_t msg_size, size_t msg_count_max); void pthread_mq_free(pthread_mq_t *mq); -size_t pthread_mq_waiting(pthread_mq_t *mq); + bool pthread_mq_reset(pthread_mq_t *mq); bool pthread_mq_send_generic(pthread_mq_t *mq, void * data, bool to_front, const struct timespec *restrict abs_timeout); bool pthread_mq_receive_generic(pthread_mq_t *mq, void * data, bool peek, const struct timespec *restrict abs_timeout); +size_t pthread_mq_waiting(pthread_mq_t *mq); +size_t pthread_mq_vacant(pthread_mq_t *mq); + // Multi mutex locking #define pthread_mutex_swap(a, b) { pthread_mutex_t *s; s = (a); a = (b); b = s; } diff --git a/c/pthread_extra/pthread_msgqueue.c b/c/pthread_extra/pthread_msgqueue.c index ff1a37f..b856296 100644 --- a/c/pthread_extra/pthread_msgqueue.c +++ b/c/pthread_extra/pthread_msgqueue.c @@ -39,6 +39,10 @@ size_t pthread_mq_waiting(pthread_mq_t *mq) { return mq->msg_count; } +size_t pthread_mq_vacant(pthread_mq_t *mq) { + return (mq->msg_count_max - mq->msg_count); +} + bool pthread_mq_reset(pthread_mq_t *mq) { if(pthread_mutex_lock(&mq->lock)) return false; mq->msg_count = 0; -- 2.30.2