From 50ef5c26912effb004e379712690172779812e62 Mon Sep 17 00:00:00 2001 From: "Herman S." <429230+has207@users.noreply.github.com> Date: Mon, 9 Mar 2026 16:14:22 +0900 Subject: [PATCH] [Kernel] Fix data race on XFile position --- src/xenia/kernel/xfile.cc | 10 ++++++++++ src/xenia/kernel/xfile.h | 6 +++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/xenia/kernel/xfile.cc b/src/xenia/kernel/xfile.cc index 1c722b874..442750cfe 100644 --- a/src/xenia/kernel/xfile.cc +++ b/src/xenia/kernel/xfile.cc @@ -35,6 +35,16 @@ XFile::~XFile() { file_->Destroy(); } +uint64_t XFile::position() const { + std::lock_guard lock(file_lock_); + return position_; +} + +void XFile::set_position(uint64_t value) { + std::lock_guard lock(file_lock_); + position_ = value; +} + X_STATUS XFile::QueryDirectory(X_FILE_DIRECTORY_INFORMATION* out_info, size_t length, const std::string_view file_name, bool restart) { diff --git a/src/xenia/kernel/xfile.h b/src/xenia/kernel/xfile.h index 1414b9c6b..566315503 100644 --- a/src/xenia/kernel/xfile.h +++ b/src/xenia/kernel/xfile.h @@ -143,8 +143,8 @@ class XFile : public XObject { const std::string& path() const { return file_->entry()->path(); } const std::string& name() const { return file_->entry()->name(); } - uint64_t position() const { return position_; } - void set_position(uint64_t value) { position_ = value; } + uint64_t position() const; + void set_position(uint64_t value); X_STATUS QueryDirectory(X_FILE_DIRECTORY_INFORMATION* out_info, size_t length, const std::string_view file_name, bool restart); @@ -193,7 +193,7 @@ class XFile : public XObject { vfs::File* file_ = nullptr; std::unique_ptr async_event_ = nullptr; - std::mutex file_lock_; + mutable std::mutex file_lock_; std::mutex completion_port_lock_; std::vector>> completion_ports_;