diff options
author | Nicolas Dato <nicolas.dato@gmail.com> | 2024-10-13 19:57:49 -0300 |
---|---|---|
committer | Nicolas Dato <nicolas.dato@gmail.com> | 2024-10-13 19:57:49 -0300 |
commit | 4a4e956c26d2f73534e504c36e2ca6a2617644b8 (patch) | |
tree | 72bc232f93514b3206da986e4d4aad1e3024e7d8 /src/itc.c | |
parent | 37e2f4899b5d3e594c1080e25c04b40bc29d53a4 (diff) | |
download | libtuberia-4a4e956c26d2f73534e504c36e2ca6a2617644b8.tar.gz |
adding tests for the main library
Diffstat (limited to 'src/itc.c')
-rw-r--r-- | src/itc.c | 28 |
1 files changed, 24 insertions, 4 deletions
@@ -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; +} + |