From 4a4e956c26d2f73534e504c36e2ca6a2617644b8 Mon Sep 17 00:00:00 2001 From: Nicolas Dato Date: Sun, 13 Oct 2024 19:57:49 -0300 Subject: adding tests for the main library --- src/itc.c | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) (limited to 'src/itc.c') diff --git a/src/itc.c b/src/itc.c index 5b6fee9..e4698e8 100644 --- a/src/itc.c +++ b/src/itc.c @@ -37,7 +37,7 @@ void itc_free(itc **ctx, itc_free_element free_element) return; } - itc_drop(*ctx, free_element); + itc_discard_all(*ctx, free_element); sem_destroy(&(*ctx)->emptied); sem_destroy(&(*ctx)->occupied); @@ -71,7 +71,7 @@ int itc_inject(itc *ctx, int timeout_ms, void *element) { struct timespec ts; - if (ctx == NULL) { + if (ctx == NULL || element == NULL) { return -1; } @@ -87,7 +87,7 @@ int itc_inject(itc *ctx, int timeout_ms, void *element) return 0; } -void itc_flush(itc *ctx) +void itc_wait_empty(itc *ctx) { int i; @@ -97,11 +97,13 @@ void itc_flush(itc *ctx) for (i = 0; i < ctx->nslots; i++) { sem_wait(&ctx->emptied); + } + for (i = 0; i < ctx->nslots; i++) { sem_post(&ctx->emptied); } } -void itc_drop(itc *ctx, itc_free_element free_element) +void itc_discard_all(itc *ctx, itc_free_element free_element) { void *element; @@ -116,3 +118,21 @@ void itc_drop(itc *ctx, itc_free_element free_element) } } +int itc_get_queued(itc *ctx) +{ + int val; + if (ctx == NULL) { + return -1; + } + sem_getvalue(&ctx->occupied, &val); + return val; +} + +int itc_get_slots(itc *ctx) +{ + if (ctx == NULL) { + return -1; + } + return ctx->nslots; +} + -- cgit v1.2.3