Skip to content

thread cross platform#366

Merged
yixy-only merged 4 commits into
x-ege:masterfrom
pointertobios:feature/thread-cross-platform
Jun 29, 2026
Merged

thread cross platform#366
yixy-only merged 4 commits into
x-ege:masterfrom
pointertobios:feature/thread-cross-platform

Conversation

@pointertobios

@pointertobios pointertobios commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • Bug Fixes
    • 改善图形初始化过程的等待机制:不再采用忙等轮询,改为在就绪信号到达后唤醒继续执行,降低卡顿与资源占用。
    • 提升界面线程启动与初始化同步的可靠性,减少偶发等待异常或时序不稳定导致的问题。

@coderabbitai

coderabbitai Bot commented Jun 29, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@yixy-only, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 59 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2ea6347c-8f1b-41b8-8a67-cf7f5cc5f02c

📥 Commits

Reviewing files that changed from the base of the PR and between c511139 and 5da803c.

📒 Files selected for processing (7)
  • CMakeLists.txt
  • src/ege_head.h
  • src/egegapi.cpp
  • src/graphics.cpp
  • src/sync/semaphore.cpp
  • src/sync/semaphore.h
  • src/window.cpp

Walkthrough

_graph_setting 的 UI 线程成员改为 std::thread,并新增条件变量与互斥锁用于 has_init 同步。initgraph 改为用 std::thread 启动消息循环并等待条件变量;messageloopthread 在加锁后设置初始化完成状态并唤醒等待方。

Changes

线程启动与初始化同步改造

Layer / File(s) Summary
_graph_setting 成员与头文件依赖更新
src/ege_head.h
新增并发头文件引用;在 _graph_setting 中加入 has_init_cvhas_init_mut,并将 threadui_handle 替换为 std::thread threadui
_graph_setting 构造收尾逻辑
src/ege_head.h
_graph_setting() 现在在 threadui 可 join 时执行 join()
initgraph 与消息循环初始化同步
src/graphics.cpp
initgraph 使用 std::thread 启动消息循环并等待条件变量;messageloopthread 通过互斥锁保护 has_init,随后调用 notify_one()

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 小兔轻跳换新线,
条件一响不再等圈圈,
线程相会在春光里,
一声唤醒就向前。 🌷

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题与改动相关,准确指向了将线程实现改为跨平台方案的主要变化。
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai 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.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/ege_head.h`:
- Line 218: `graph_setting` contains a `std::thread threadui` that is started by
`initgraph()` but has no visible shutdown path, so it can still be joinable when
the object is destroyed and trigger termination. Update the `graph_setting`
lifecycle to stop the UI/message loop before exit, then explicitly `join()`
`threadui` (or otherwise safely handle its ownership) in the teardown path so
the thread is always cleaned up before destruction.

In `@src/graphics.cpp`:
- Around line 893-897: `initgraph()` currently waits only for `has_init ==
true`, so if `messageloopthread()` exits early from `init_instance()` failure
the wait can block forever. Update the initialization handshake in
`messageloopthread()` to always set a protected failure/ready state and call
`has_init_cv.notify_one()` on failure, preferably via a dedicated `init_failed`
or `init_status` field rather than reusing `exit_window`. Then change the wait
in `initgraph()` to detect that failure state, abort initialization, and skip
any follow-up work such as `UpdateWindow(pg->hwnd)`.
- Around line 979-983: `has_init` is currently written under `pg->has_init_mut`
in `graphics.cpp` but read without the same synchronization in `egegapi.cpp` and
`window.cpp`, creating an inconsistent concurrency contract. Update the
`has_init` access pattern so every read and write goes through the same
synchronization mechanism, either by making `has_init` atomic or by
encapsulating it behind the existing lock/state helpers used in
`isinitialized()`, `getbkcolor()`, `setbkcolor_f()`, `setcaption()`, and
`seticon()`.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6ad5b57d-8ba7-4fb9-8137-75f533a8197a

📥 Commits

Reviewing files that changed from the base of the PR and between 9df93f6 and 451ac45.

📒 Files selected for processing (2)
  • src/ege_head.h
  • src/graphics.cpp

Comment thread src/ege_head.h
Comment thread src/graphics.cpp Outdated
Comment thread src/graphics.cpp Outdated
@yixy-only yixy-only force-pushed the feature/thread-cross-platform branch from f1ee67f to 5da803c Compare June 29, 2026 16:43
@yixy-only yixy-only merged commit 79e9c53 into x-ege:master Jun 29, 2026
15 of 19 checks passed
@pointertobios pointertobios deleted the feature/thread-cross-platform branch June 30, 2026 06:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants