From: Mathieu Desnoyers Date: Tue, 24 Jul 2012 17:54:19 +0000 (-0400) Subject: Fix: get rid of consumed flag X-Git-Tag: v1.0.0-rc5~47 X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=3a25e036c64003c5778538d7cfef8beccc65d640 Fix: get rid of consumed flag This flag is not appropriately used in the context of the library and is not required. We now introduce a "poison" value to know when the last_offset value is bogus. Signed-off-by: Mathieu Desnoyers Signed-off-by: Julien Desfossez --- diff --git a/formats/ctf-text/ctf-text.c b/formats/ctf-text/ctf-text.c index 4f5ba73e..4cb4297e 100644 --- a/formats/ctf-text/ctf-text.c +++ b/formats/ctf-text/ctf-text.c @@ -448,7 +448,6 @@ int ctf_text_write_event(struct stream_pos *ppos, struct ctf_stream_definition * /* newline */ fprintf(pos->fp, "\n"); pos->field_nr = 0; - stream->consumed = 1; return 0; diff --git a/formats/ctf/ctf.c b/formats/ctf/ctf.c index b3f7699a..cf955473 100644 --- a/formats/ctf/ctf.c +++ b/formats/ctf/ctf.c @@ -337,8 +337,6 @@ int ctf_read_event(struct stream_pos *ppos, struct ctf_stream_definition *stream /* save the current position as a restore point */ pos->last_offset = pos->offset; - /* we just read the event, it is consumed when used by the caller */ - stream->consumed = 0; /* * This is the EOF check after we've advanced the position in @@ -908,6 +906,7 @@ int ctf_open_trace_metadata_read(struct ctf_trace *td, int ret = 0; metadata_stream = g_new0(struct ctf_file_stream, 1); + metadata_stream->pos.last_offset = LAST_OFFSET_POISON; if (packet_seek) { metadata_stream->pos.packet_seek = packet_seek; @@ -1402,6 +1401,7 @@ int ctf_open_file_stream_read(struct ctf_trace *td, const char *path, int flags, } file_stream = g_new0(struct ctf_file_stream, 1); + file_stream->pos.last_offset = LAST_OFFSET_POISON; if (packet_seek) { file_stream->pos.packet_seek = packet_seek; @@ -1624,6 +1624,7 @@ int ctf_open_mmap_stream_read(struct ctf_trace *td, struct ctf_file_stream *file_stream; file_stream = g_new0(struct ctf_file_stream, 1); + file_stream->pos.last_offset = LAST_OFFSET_POISON; ctf_init_mmap_pos(&file_stream->pos, mmap_info); file_stream->pos.packet_seek = packet_seek; diff --git a/include/babeltrace/ctf-ir/metadata.h b/include/babeltrace/ctf-ir/metadata.h index a24dafab..124eb7da 100644 --- a/include/babeltrace/ctf-ir/metadata.h +++ b/include/babeltrace/ctf-ir/metadata.h @@ -39,7 +39,6 @@ struct ctf_stream_definition { uint64_t event_id; /* Current event ID */ int has_timestamp; uint64_t stream_id; - int consumed; /* Last packet used by caller */ struct definition_struct *trace_packet_header; struct definition_struct *stream_packet_context; diff --git a/include/babeltrace/ctf/types.h b/include/babeltrace/ctf/types.h index 3b9039e0..3e30b149 100644 --- a/include/babeltrace/ctf/types.h +++ b/include/babeltrace/ctf/types.h @@ -31,6 +31,8 @@ #include #include +#define LAST_OFFSET_POISON ((ssize_t) -1L) + struct bt_stream_callbacks; struct packet_index { diff --git a/lib/iterator.c b/lib/iterator.c index 6b1a6d2a..b4c5a697 100644 --- a/lib/iterator.c +++ b/lib/iterator.c @@ -223,11 +223,10 @@ int bt_iter_set_pos(struct bt_iter *iter, const struct bt_iter_pos *iter_pos) */ stream->timestamp = saved_pos->current_timestamp; stream_pos->offset = saved_pos->offset; - stream_pos->last_offset = saved_pos->offset; + stream_pos->last_offset = LAST_OFFSET_POISON; stream->prev_timestamp = 0; stream->prev_timestamp_end = 0; - stream->consumed = 0; printf_debug("restored to cur_index = %zd and " "offset = %zd, timestamp = %" PRIu64 "\n", @@ -383,19 +382,7 @@ struct bt_iter_pos *bt_iter_get_pos(struct bt_iter *iter) saved_pos.file_stream = cfs; saved_pos.cur_index = cfs->pos.cur_index; - - /* - * It is possible that an event was read during - * the last restore, never consumed and its - * position saved again. For this case, we - * need to check if the event really was - * consumed by the caller otherwise it is lost. - */ - if (stream->consumed) - saved_pos.offset = cfs->pos.offset; - else - saved_pos.offset = cfs->pos.last_offset; - + saved_pos.offset = cfs->pos.last_offset; saved_pos.current_timestamp = stream->timestamp; g_array_append_val(