ir: disable clock value accessors in non-writer mode
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Fri, 19 Feb 2016 02:00:31 +0000 (21:00 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Mon, 22 Feb 2016 19:46:57 +0000 (14:46 -0500)
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
formats/ctf/ir/clock.c
formats/ctf/ir/trace.c
include/babeltrace/ctf-ir/clock-internal.h

index 0bf7f3518cd5026450703001190699bd031be717..2e765430f66d8ad590e8dfbff01777fc62a3963f 100644 (file)
@@ -99,6 +99,13 @@ struct bt_ctf_clock *bt_ctf_clock_create(const char *name)
                goto error;
        }
 
+       /*
+        * For backward compatibility reasons, a fresh clock can have
+        * a value because it could be added to a trace created by a
+        * CTF writer. As soon as this clock is added to a non-writer
+        * trace, then its value/time functions will be disabled.
+        */
+       clock->has_value = 1;
        clock->uuid_set = 1;
        return clock;
 error:
@@ -327,6 +334,15 @@ int bt_ctf_clock_get_time(struct bt_ctf_clock *clock, int64_t *time)
                goto end;
        }
 
+
+       if (!clock->has_value) {
+               /*
+                * Clock belongs to a non-writer mode trace and thus
+                * this function is disabled.
+                */
+               goto end;
+       }
+
        /* Common case where cycles are actually nanoseconds */
        if (clock->frequency == 1000000000) {
                *time = (int64_t) clock->value;
@@ -349,6 +365,16 @@ int bt_ctf_clock_set_time(struct bt_ctf_clock *clock, int64_t time)
                goto end;
        }
 
+
+       if (!clock->has_value) {
+               /*
+                * Clock belongs to a non-writer mode trace and thus
+                * this function is disabled.
+                */
+               ret = -1;
+               goto end;
+       }
+
        /* Common case where cycles are actually nanoseconds */
        if (clock->frequency == 1000000000) {
                clock->value = time;
@@ -370,6 +396,14 @@ uint64_t bt_ctf_clock_get_value(struct bt_ctf_clock *clock)
                goto end;
        }
 
+       if (!clock->has_value) {
+               /*
+                * Clock belongs to a non-writer mode trace and thus
+                * this function is disabled.
+                */
+               goto end;
+       }
+
        ret = clock->value;
 end:
        return ret;
@@ -379,8 +413,22 @@ int bt_ctf_clock_set_value(struct bt_ctf_clock *clock, uint64_t value)
 {
        int ret = 0;
 
+       if (!clock) {
+               ret = -1;
+               goto end;
+       }
+
+       if (!clock->has_value) {
+               /*
+                * Clock belongs to a non-writer mode trace and thus
+                * this function is disabled.
+                */
+               ret = -1;
+               goto end;
+       }
+
        /* Timestamps are strictly monotonic */
-       if (!clock || value < clock->value) {
+       if (value < clock->value) {
                ret = -1;
                goto end;
        }
index 686ba798c4a9c1428f6dcc110208433086c16d92..9cce8b6f95c91eaa49af9384075416bf0d80609f 100644 (file)
@@ -351,6 +351,15 @@ int bt_ctf_trace_add_clock(struct bt_ctf_trace *trace,
        bt_get(clock);
        g_ptr_array_add(trace->clocks, clock);
 
+       if (!trace->is_created_by_writer) {
+               /*
+                * Non-writer mode trace: disable clock value functions
+                * because clock values are per-stream in that
+                * situation.
+                */
+               clock->has_value = 0;
+       }
+
        if (trace->frozen) {
                bt_ctf_clock_freeze(clock);
        }
index 07e37f9895678f050e0743c711b398cabd2ae1b6..8f7b5f07e31f9d9b77dfe8ab800e4143bb2be51a 100644 (file)
@@ -46,6 +46,16 @@ struct bt_ctf_clock {
        uuid_t uuid;
        int uuid_set;
        int absolute;
+
+       /*
+        * This field is set once a clock is added to a trace. If the
+        * trace was created by a CTF writer, then the clock's value
+        * can be set and returned. Otherwise both functions fail
+        * because, in non-writer mode, clocks do not have global
+        * values: values are per-stream.
+        */
+       int has_value;
+
        /*
         * A clock's properties can't be modified once it is added to a stream
         * class.
This page took 0.026715 seconds and 4 git commands to generate.