+/**
+ * Lock a trace so no other instance can use it.
+ *
+ * @param trace The trace to lock.
+ * @return 0 on success, -1 if cannot get lock.
+ */
+gint lttvwindowtraces_lock(LttvTrace *trace)
+{
+ LttvAttribute *attribute = lttv_trace_attribute(trace);
+ LttvAttributeValue value;
+ LttvAttributeType type;
+
+ type = lttv_iattribute_get_by_name(LTTV_IATTRIBUTE(attribute),
+ LTTV_LOCK,
+ &value);
+ /* Verify the absence of the lock. */
+ if(type != LTTV_NONE) {
+ g_critical("Cannot take trace lock");
+ return -1;
+ }
+
+ value = lttv_iattribute_add(LTTV_IATTRIBUTE(attribute),
+ LTTV_LOCK,
+ LTTV_INT);
+ /* the value is left unset. The only presence of the attribute is necessary.
+ */
+
+ return 0;
+}
+
+/**
+ * Unlock a trace.
+ *
+ * @param trace The trace to unlock.
+ * @return 0 on success, -1 if cannot unlock (not locked ?).
+ */
+gint lttvwindowtraces_unlock(LttvTrace *trace)
+{
+ LttvAttribute *attribute = lttv_trace_attribute(trace);
+ LttvAttributeType type;
+ LttvAttributeValue value;
+
+ type = lttv_iattribute_get_by_name(LTTV_IATTRIBUTE(attribute),
+ LTTV_LOCK,
+ &value);
+ /* Verify the presence of the lock. */
+ if(type == LTTV_NONE) {
+ g_critical("Cannot release trace lock");
+ return -1;
+ }
+
+ lttv_iattribute_remove_by_name(LTTV_IATTRIBUTE(attribute),
+ LTTV_LOCK);
+
+ return 0;
+}
+
+/**
+ * Verify if a trace is locked.
+ *
+ * @param trace The trace to verify.
+ * @return TRUE if locked, FALSE is unlocked.
+ */
+gint lttvwindowtraces_get_lock_state(LttvTrace *trace)
+{
+ LttvAttribute *attribute = lttv_trace_attribute(trace);
+ LttvAttributeType type;
+ LttvAttributeValue value;
+
+ type = lttv_iattribute_get_by_name(LTTV_IATTRIBUTE(attribute),
+ LTTV_LOCK,
+ &value);
+ /* The only presence of the attribute is necessary. */
+ if(type == LTTV_NONE)
+ return FALSE;
+ else
+ return TRUE;
+}