+/* Must be called we sure nobody else is using the info.
+ * It implies that the trace should have been previously stopped
+ * and that every writer has finished.
+ *
+ * Writers should always check if the trace must be destroyed when they
+ * finish writing and the nesting level is 0.
+ */
+void lttng_free_trace_info(struct lttng_trace_info *info)
+{
+ int ret;
+
+ if(info->active) {
+ printf(
+ "LTTng ERROR : lttng_free_trace_info should be called on inactive trace\n");
+ exit(1);
+ }
+ if(!info->destroy) {
+ printf(
+ "LTTng ERROR : lttng_free_trace_info should be called on destroyed trace\n");
+ exit(1);
+ }
+ if(atomic_read(&info->nesting) > 0) {
+ printf(
+ "LTTng ERROR : lttng_free_trace_info should not be nested on tracing\n");
+ exit(1);
+ }
+
+ /* Remove the maps */
+ ret = munmap(info->channel.cpu.start, info->channel.cpu.length);
+ if(ret) {
+ perror("LTTNG : error in munmap");
+ }
+ ret = munmap(info->channel.facilities.start, info->channel.facilities.length);
+ if(ret) {
+ perror("LTTNG : error in munmap");
+ }
+
+ /* Zero the structure */
+ memset(info, 0, sizeof(struct lttng_trace_info));
+}
+
+
+static struct lttng_trace_info* find_info(unsigned long cpu_addr,
+ unsigned long fac_addr, unsigned int *first_empty)
+{
+ struct lttng_trace_info *found = NULL;
+ unsigned int i;
+
+ *first_empty = MAX_TRACES;
+
+ /* Try to find the trace */
+ for(i=0;i<MAX_TRACES;i++) {
+ if(i<*first_empty && !lttng_trace_info[i].channel.cpu.start)
+ *first_empty = i;
+ if(cpu_addr ==
+ (unsigned long)lttng_trace_info[i].channel.cpu.start &&
+ fac_addr ==
+ (unsigned long)lttng_trace_info[i].channel.facilities.start) {
+ /* Found */
+ found = <tng_trace_info[i];
+ break;
+ }
+ }
+ return found;
+}
+
+