From e003e87103a3fd72d543ec3191c20df56599b0f5 Mon Sep 17 00:00:00 2001 From: Julien Desfossez Date: Tue, 13 Mar 2012 15:50:34 -0400 Subject: [PATCH 1/1] Fix : only one iterator per context As of now, the API let the user create multiple iterators on the same context but the underlying code was not ready. This patch restrict to only one iterator per context. Supporting multiple iterators is targetted for the next release. Fixes #166 [ Edit by Mathieu Desnoyers: update API comment ] Signed-off-by: Julien Desfossez Signed-off-by: Mathieu Desnoyers --- include/babeltrace/context-internal.h | 1 + include/babeltrace/ctf/iterator.h | 7 +++++++ lib/context.c | 1 + lib/iterator.c | 8 ++++++++ 4 files changed, 17 insertions(+) diff --git a/include/babeltrace/context-internal.h b/include/babeltrace/context-internal.h index 80ca42c8..95d629b8 100644 --- a/include/babeltrace/context-internal.h +++ b/include/babeltrace/context-internal.h @@ -42,6 +42,7 @@ struct bt_context { GHashTable *trace_handles; int refcount; int last_trace_handle_id; + struct bt_iter *current_iterator; }; #endif /* _BABELTRACE_CONTEXT_INTERNAL_H */ diff --git a/include/babeltrace/ctf/iterator.h b/include/babeltrace/ctf/iterator.h index 71f935a0..1071def8 100644 --- a/include/babeltrace/ctf/iterator.h +++ b/include/babeltrace/ctf/iterator.h @@ -39,6 +39,13 @@ struct bt_ctf_event; * By default, if begin_pos is NULL, a BT_SEEK_CUR is performed at * creation. By default, if end_pos is NULL, a BT_SEEK_END (end of * trace) is the EOF criterion. + * + * Return a pointer to the newly allocated iterator. + * + * Only one iterator can be created against a context. If more than one + * iterator is being created for the same context, the second creation + * will return NULL. The previous iterator must be destroyed before + * creation of the new iterator for this function to succeed. */ struct bt_ctf_iter *bt_ctf_iter_create(struct bt_context *ctx, const struct bt_iter_pos *begin_pos, diff --git a/lib/context.c b/lib/context.c index 0c20ed53..e9a35c1d 100644 --- a/lib/context.c +++ b/lib/context.c @@ -50,6 +50,7 @@ struct bt_context *bt_context_create(void) g_direct_equal, NULL, (GDestroyNotify) bt_trace_handle_destroy); + ctx->current_iterator = NULL; ctx->tc = g_new0(struct trace_collection, 1); init_trace_collection(ctx->tc); diff --git a/lib/iterator.c b/lib/iterator.c index e50846f4..ca6e5917 100644 --- a/lib/iterator.c +++ b/lib/iterator.c @@ -436,6 +436,11 @@ int bt_iter_init(struct bt_iter *iter, int i, stream_id; int ret = 0; + if (ctx->current_iterator) { + ret = -1; + goto error_ctx; + } + iter->stream_heap = g_new(struct ptr_heap, 1); iter->end_pos = end_pos; bt_context_get(ctx); @@ -486,12 +491,14 @@ int bt_iter_init(struct bt_iter *iter, } } + ctx->current_iterator = iter; return 0; error: heap_free(iter->stream_heap); error_heap_init: g_free(iter->stream_heap); +error_ctx: return ret; } @@ -517,6 +524,7 @@ void bt_iter_fini(struct bt_iter *iter) heap_free(iter->stream_heap); g_free(iter->stream_heap); } + iter->ctx->current_iterator = NULL; bt_context_put(iter->ctx); } -- 2.34.1