From: Tomas Mudrunka Date: Tue, 29 Jun 2021 12:22:10 +0000 (+0200) Subject: Vacant X-Git-Url: https://git.harvie.cz/?a=commitdiff_plain;h=77c7dc7ffcaa64879e90178df5585f22790f46be;p=mirrors%2FPrograms.git Vacant --- 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;