Skip to content

fix: improve Windows settings backend and thread safety - #576

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
kt286:fix/windows-settings-thread-safety
Jul 28, 2026
Merged

fix: improve Windows settings backend and thread safety#576
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
kt286:fix/windows-settings-thread-safety

Conversation

@kt286

@kt286 kt286 commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

fix: 改进 Windows 设置后端和线程安全性

  • Use QSettings::IniFormat on Windows instead of NativeFormat (registry), ensuring settings are stored as INI files consistent with Linux behavior

  • Move loadValue() call before backend is moved to worker thread to prevent cross-thread race conditions when keys() and getOption() access the backend

  • Use BlockingQueuedConnection for doSync() to ensure sync operations execute in the backend's worker thread while the caller waits for completion

  • Update copyright years to 2026

  • 在 Windows 上使用 QSettings::IniFormat 替代 NativeFormat(注册表格式), 确保设置以 INI 文件形式存储,与 Linux 行为保持一致

  • 将 loadValue() 调用移到 backend 移动到工作线程之前,防止 keys() 和 getOption() 跨线程访问 backend 导致竞态条件

  • 使用 BlockingQueuedConnection 执行 doSync(),确保同步操作在 backend 的 工作线程中执行,同时调用者等待完成

  • 更新版权年份至 2026

Summary by Sourcery

Improve Windows settings backend behavior and thread safety for configuration loading and syncing.

Bug Fixes:

  • Prevent cross-thread race conditions by loading settings before moving the backend to its worker thread.
  • Ensure settings synchronization runs in the backend worker thread while the caller blocks until completion.

Enhancements:

  • Use INI-based QSettings storage on Windows to align configuration persistence with Linux behavior.

Documentation:

  • Update SPDX copyright years to 2026 in settings-related source files.

fix: 改进 Windows 设置后端和线程安全性

- Use QSettings::IniFormat on Windows instead of NativeFormat (registry),
  ensuring settings are stored as INI files consistent with Linux behavior
- Move loadValue() call before backend is moved to worker thread to prevent
  cross-thread race conditions when keys() and getOption() access the backend
- Use BlockingQueuedConnection for doSync() to ensure sync operations execute
  in the backend's worker thread while the caller waits for completion
- Update copyright years to 2026

- 在 Windows 上使用 QSettings::IniFormat 替代 NativeFormat(注册表格式),
  确保设置以 INI 文件形式存储,与 Linux 行为保持一致
- 将 loadValue() 调用移到 backend 移动到工作线程之前,防止 keys() 和
  getOption() 跨线程访问 backend 导致竞态条件
- 使用 BlockingQueuedConnection 执行 doSync(),确保同步操作在 backend 的
  工作线程中执行,同时调用者等待完成
- 更新版权年份至 2026
@deepin-ci-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: kt286

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@deepin-ci-robot

Copy link
Copy Markdown
Contributor

Hi @kt286. Thanks for your PR.

I'm waiting for a linuxdeepin member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@sourcery-ai

sourcery-ai Bot commented Jul 25, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adjusts the Windows settings backend to use INI files instead of the registry and fixes threading issues by loading settings before moving the backend to a worker thread and ensuring sync runs on the backend thread, plus copyright year updates.

Sequence diagram for DSettings::setBackend threading and load order

sequenceDiagram
    participant DSettings
    participant DSettingsBackend
    participant QThread as backendWriteThread

    DSettings->>DSettingsBackend: setBackend(backend)
    DSettings->>DSettingsBackend: loadValue()
    DSettings->>QThread: new QThread
    DSettings->>DSettingsBackend: moveToThread(backendWriteThread)
    DSettings->>QThread: start()
    QThread->>DSettingsBackend: [runs backend in worker thread]
Loading

Sequence diagram for DSettings::sync using BlockingQueuedConnection

sequenceDiagram
    participant Caller
    participant DSettings
    participant DSettingsBackend
    participant QThread as backendWriteThread

    Caller->>DSettings: sync()
    DSettings->>DSettings: [backend is null?]
    alt backend not null
        DSettings->>DSettingsBackend: invokeMethod(doSync, BlockingQueuedConnection)
        QThread->>DSettingsBackend: doSync()
        DSettingsBackend-->>DSettings: [doSync finished]
        DSettings-->>Caller: sync() return
    else backend is null
        DSettings-->>Caller: sync() return
    end
Loading

File-Level Changes

Change Details Files
Make QSettings backend use INI files on Windows for consistent cross-platform behavior.
  • Instantiate QSettings with QSettings::IniFormat when building on Windows.
  • Retain QSettings::NativeFormat for non-Windows builds.
  • Log the resulting configuration file path via qDebug().
src/settings/backend/qsettingbackend.cpp
Fix DSettings backend threading by loading values on the main thread and invoking sync on the backend worker thread.
  • Call loadValue() immediately after assigning the backend, before moving it to the worker thread, to avoid cross-thread reads in keys() and getOption().
  • Move the worker-thread setup (QThread creation, moveToThread, connections, start) to occur after loadValue().
  • Replace direct d->backend->doSync() calls with QMetaObject::invokeMethod using Qt::BlockingQueuedConnection so doSync() runs in the backend's worker thread while the caller blocks.
src/settings/dsettings.cpp
Update copyright years to 2026.
  • Extend SPDX-FileCopyrightText year range from 2016-2022 to 2016-2026 in settings-related source files.
src/settings/dsettings.cpp
src/settings/backend/qsettingbackend.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@18202781743

Copy link
Copy Markdown
Contributor

/forcemerge

@deepin-bot

deepin-bot Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

This pr force merged! (status: blocked)

@deepin-bot
deepin-bot Bot merged commit fd0d758 into linuxdeepin:master Jul 28, 2026
20 checks passed
@kt286
kt286 deleted the fix/windows-settings-thread-safety branch July 28, 2026 06:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants