aboutsummaryrefslogtreecommitdiff
path: root/src/itc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/itc.c')
-rw-r--r--src/itc.c28
1 files changed, 24 insertions, 4 deletions
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;
+}
+