Fix: get rid of consumed flag
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 24 Jul 2012 17:54:19 +0000 (13:54 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 24 Jul 2012 17:54:19 +0000 (13:54 -0400)
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 <mathieu.desnoyers@efficios.com>
Signed-off-by: Julien Desfossez <jdesfossez@efficios.com>
formats/ctf-text/ctf-text.c
formats/ctf/ctf.c
include/babeltrace/ctf-ir/metadata.h
include/babeltrace/ctf/types.h
lib/iterator.c

index 4f5ba73e97b22cf045bbba3294ca43a5ce953bce..4cb4297e1363bc32afc29231cd47685be39eab83 100644 (file)
@@ -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;
 
index b3f7699afc925bca91b6fbf0dce5c38aca091ce5..cf9554739c6647701ecfd44132b7eacd80fdaa38 100644 (file)
@@ -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;
index a24dafabd41dbbcc497b43e84080c9df9b9e8b4d..124eb7daefe4ede4e03d3f1de2b106cbc640277e 100644 (file)
@@ -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;
index 3b9039e037c13009aad1cb01d6d68327d35c4408..3e30b14919f9bd6f5602eb55d0784af9f6f75dad 100644 (file)
@@ -31,6 +31,8 @@
 #include <stdio.h>
 #include <babeltrace/mmap-align.h>
 
+#define LAST_OFFSET_POISON     ((ssize_t) -1L)
+
 struct bt_stream_callbacks;
 
 struct packet_index {
index 6b1a6d2ad1668a42d7a6f1e268d71f0b3d8e1193..b4c5a697fa7023d9bf4aa35d7186e38fecb6b8f9 100644 (file)
@@ -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(
This page took 0.039366 seconds and 4 git commands to generate.