diff options
author | Vito Caputo <vcaputo@pengaru.com> | 2023-08-13 22:54:39 -0700 |
---|---|---|
committer | Vito Caputo <vcaputo@pengaru.com> | 2023-08-13 22:54:39 -0700 |
commit | e5226da128493945a2248331c6ad30f14f5ac7a2 (patch) | |
tree | 796986226b38279413a91d3dddb9fe09c90cb86c /src | |
parent | 34f25316966ae80059d8dcfe36103e4a986aeec5 (diff) |
til_stream: return skipped count from til_stream_gc_module_contexts()
Preparatory commit for making til_stream_free() assert on leaked
module contexts.
Diffstat (limited to 'src')
-rw-r--r-- | src/til_stream.c | 15 | ||||
-rw-r--r-- | src/til_stream.h | 2 |
2 files changed, 12 insertions, 5 deletions
diff --git a/src/til_stream.c b/src/til_stream.c index 021e0d4..0f35a17 100644 --- a/src/til_stream.c +++ b/src/til_stream.c @@ -646,9 +646,10 @@ int til_stream_find_module_contexts(til_stream_t *stream, const char *path, size } -void til_stream_gc_module_contexts(til_stream_t *stream) +/* returns count of remaining contexts or zero if none remain */ +unsigned til_stream_gc_module_contexts(til_stream_t *stream) { - unsigned freed; + unsigned freed, skipped; assert(stream); @@ -668,6 +669,7 @@ void til_stream_gc_module_contexts(til_stream_t *stream) */ do { freed = 0; + skipped = 0; for (size_t b = 0; b < TIL_STREAM_CTXT_BUCKETS_COUNT; b++) { til_stream_module_context_t *c, *c_prev, *c_next; @@ -684,6 +686,7 @@ void til_stream_gc_module_contexts(til_stream_t *stream) if (i < c->n_module_contexts) { c_prev = c; + skipped++; continue; } @@ -697,13 +700,17 @@ void til_stream_gc_module_contexts(til_stream_t *stream) freed = 1; } - if (c_prev) + + if (c_prev) { c_prev->next = c_next; - else + } else { stream->module_context_buckets[b] = c_next; + } } } } while (freed); + + return skipped; } diff --git a/src/til_stream.h b/src/til_stream.h index 5473aec..eab078c 100644 --- a/src/til_stream.h +++ b/src/til_stream.h @@ -74,7 +74,7 @@ int til_stream_for_each_module_context(til_stream_t *stream, til_stream_module_c int til_stream_register_module_contexts(til_stream_t *stream, size_t n_contexts, til_module_context_t **contexts); int til_stream_find_module_contexts(til_stream_t *stream, const char *path, size_t n_contexts, til_module_context_t **res_contexts); -void til_stream_gc_module_contexts(til_stream_t *stream); +unsigned til_stream_gc_module_contexts(til_stream_t *stream); void til_stream_fprint_module_contexts(til_stream_t *stream, FILE *out); #endif |