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:
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;
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;
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;
{
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;
}
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);
}
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.