From 265d4ba2b6876c1c939bbd5c017bfd780b485165 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Mon, 4 Dec 2023 21:51:03 +0000 Subject: [PATCH] src.ctf.fs: make ctf_fs_ds_file::stream a bt2::Stream::Shared Change-Id: I2df309d73c7a1b987e4d25c63251e13bf47a38a3 Signed-off-by: Simon Marchi Reviewed-on: https://review.lttng.org/c/babeltrace/+/8258 Reviewed-by: Philippe Proulx Reviewed-on: https://review.lttng.org/c/babeltrace/+/12296 --- src/plugins/ctf/fs-src/data-stream-file.cpp | 19 +++++++++---------- src/plugins/ctf/fs-src/data-stream-file.hpp | 5 ++--- src/plugins/ctf/fs-src/fs.cpp | 6 ++++-- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/plugins/ctf/fs-src/data-stream-file.cpp b/src/plugins/ctf/fs-src/data-stream-file.cpp index 97e688e4..bde54c7e 100644 --- a/src/plugins/ctf/fs-src/data-stream-file.cpp +++ b/src/plugins/ctf/fs-src/data-stream-file.cpp @@ -225,7 +225,7 @@ static bt_stream *medop_borrow_stream(bt_stream_class *stream_class, int64_t, vo bt_stream_class *ds_file_stream_class; bt_stream *stream = NULL; - ds_file_stream_class = bt_stream_borrow_class(ds_file->stream); + ds_file_stream_class = ds_file->stream->cls().libObjPtr(); if (stream_class != ds_file_stream_class) { /* @@ -235,7 +235,7 @@ static bt_stream *medop_borrow_stream(bt_stream_class *stream_class, int64_t, vo goto end; } - stream = ds_file->stream; + stream = ds_file->stream->libObjPtr(); end: return stream; @@ -327,9 +327,9 @@ ctf_fs_ds_group_medops_set_file(struct ctf_fs_ds_group_medops_data *data, ctf_fs_ds_file_destroy(data->file); /* Create the new file. */ - data->file = ctf_fs_ds_file_create(data->ds_file_group->ctf_fs_trace, - data->ds_file_group->stream->libObjPtr(), - index_entry->path, data->logger); + data->file = + ctf_fs_ds_file_create(data->ds_file_group->ctf_fs_trace, data->ds_file_group->stream, + index_entry->path, data->logger); if (!data->file) { BT_CPPLOGE_APPEND_CAUSE_SPEC(data->logger, "failed to create ctf_fs_ds_file."); status = CTF_MSG_ITER_MEDIUM_STATUS_ERROR; @@ -811,8 +811,9 @@ error: goto end; } -struct ctf_fs_ds_file *ctf_fs_ds_file_create(struct ctf_fs_trace *ctf_fs_trace, bt_stream *stream, - const char *path, const bt2c::Logger& parentLogger) +struct ctf_fs_ds_file *ctf_fs_ds_file_create(struct ctf_fs_trace *ctf_fs_trace, + bt2::Stream::Shared stream, const char *path, + const bt2c::Logger& parentLogger) { int ret; size_t offset_align; @@ -827,8 +828,7 @@ struct ctf_fs_ds_file *ctf_fs_ds_file_create(struct ctf_fs_trace *ctf_fs_trace, goto error; } - ds_file->stream = stream; - bt_stream_get_ref(ds_file->stream); + ds_file->stream = std::move(stream); ds_file->metadata = ctf_fs_trace->metadata; g_string_assign(ds_file->file->path, path); ret = ctf_fs_file_open(ds_file->file, "rb"); @@ -877,7 +877,6 @@ void ctf_fs_ds_file_destroy(struct ctf_fs_ds_file *ds_file) return; } - bt_stream_put_ref(ds_file->stream); (void) ds_file_munmap(ds_file); if (ds_file->file) { diff --git a/src/plugins/ctf/fs-src/data-stream-file.hpp b/src/plugins/ctf/fs-src/data-stream-file.hpp index fed80c61..bdbf477d 100644 --- a/src/plugins/ctf/fs-src/data-stream-file.hpp +++ b/src/plugins/ctf/fs-src/data-stream-file.hpp @@ -47,8 +47,7 @@ struct ctf_fs_ds_file /* Owned by this */ struct ctf_fs_file *file = nullptr; - /* Owned by this */ - bt_stream *stream = nullptr; + bt2::Stream::Shared stream; void *mmap_addr = nullptr; @@ -143,7 +142,7 @@ struct ctf_fs_ds_file_group ctf_fs_ds_index::UP index; }; -struct ctf_fs_ds_file *ctf_fs_ds_file_create(struct ctf_fs_trace *ctf_fs_trace, bt_stream *stream, +struct ctf_fs_ds_file *ctf_fs_ds_file_create(ctf_fs_trace *ctf_fs_trace, bt2::Stream::Shared stream, const char *path, const bt2c::Logger& logger); void ctf_fs_ds_file_destroy(struct ctf_fs_ds_file *stream); diff --git a/src/plugins/ctf/fs-src/fs.cpp b/src/plugins/ctf/fs-src/fs.cpp index 1db4fe65..ac4c720c 100644 --- a/src/plugins/ctf/fs-src/fs.cpp +++ b/src/plugins/ctf/fs-src/fs.cpp @@ -523,7 +523,8 @@ static int add_ds_file_to_ds_file_group(struct ctf_fs_trace *ctf_fs_trace, const * Create a temporary ds_file to read some properties about the data * stream file. */ - ds_file = ctf_fs_ds_file_create(ctf_fs_trace, NULL, path, ctf_fs_trace->logger); + ds_file = + ctf_fs_ds_file_create(ctf_fs_trace, bt2::Stream::Shared {}, path, ctf_fs_trace->logger); if (!ds_file) { goto error; } @@ -1135,7 +1136,8 @@ static int decode_clock_snapshot_after_event(struct ctf_fs_trace *ctf_fs_trace, BT_ASSERT(index_entry); BT_ASSERT(index_entry->path); - ds_file = ctf_fs_ds_file_create(ctf_fs_trace, NULL, index_entry->path, ctf_fs_trace->logger); + ds_file = ctf_fs_ds_file_create(ctf_fs_trace, bt2::Stream::Shared {}, index_entry->path, + ctf_fs_trace->logger); if (!ds_file) { BT_CPPLOGE_APPEND_CAUSE_SPEC(ctf_fs_trace->logger, "Failed to create a ctf_fs_ds_file"); ret = -1; -- 2.34.1