feat(host)!: Add thread setup support to advanced options#56
Conversation
- Introduce `thread_setup` in `agent::AdvancedOptions` so callers can configure the transport event thread before it starts handling USB I/O. - Add `bind_advanced_options()` to bind stateful nothrow callables without introducing `std::function` into the binary interface. The transport now waits until `thread_setup` returns before continuing construction, so any bound temporary state remains alive during the callback. - Also document the lifetime and slicing constraints of bound advanced options, and clarify that `thread_setup` is only for per-thread OS-level setup such as priority or CPU affinity. BREAKING CHANGE: `agent::AdvancedOptions` is now non-copyable and non-movable, and no longer preserves the previous aggregate-style usage. The USB transport connection options alias now reuses `agent::AdvancedOptions`.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
Walkthrough将 ChangesAdvancedOptions 线程回调扩展
Sequence Diagram(s)sequenceDiagram
participant 调用方
participant AdvancedOptions
participant Usb构造函数
participant event_thread_
调用方->>AdvancedOptions: bind_advanced_options(functor) 返回 OptionsImpl
调用方->>Usb构造函数: create_transport(..., options)
Usb构造函数->>event_thread_: 创建线程
event_thread_->>AdvancedOptions: options.thread_setup(options)(调用 OptionsImpl::invoke)
event_thread_->>Usb构造函数: thread_setup_done.store(true) + notify_one()
Usb构造函数->>Usb构造函数: wait 解除阻塞,继续初始化
event_thread_->>event_thread_: handle_events()
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
|
新版本的 clang-tidy 会崩掉,旧版本是正常的,先合并。 |
thread_setupinagent::AdvancedOptionsso callers can configure the transport event thread before it starts handling USB I/O.bind_advanced_options()to bind stateful nothrow callables without introducingstd::functioninto the binary interface. The transport now waits untilthread_setupreturns before continuing construction, so any bound temporary state remains alive during the callback.thread_setupis only for per-thread OS-level setup such as priority or CPU affinity.BREAKING CHANGE:
agent::AdvancedOptionsis now non-copyable and non-movable, and no longer preserves the previous aggregate-style usage. The USB transport connection options alias now reusesagent::AdvancedOptions.拉取请求摘要
概述
本PR为
agent::AdvancedOptions配置添加了线程设置支持,允许调用者在USB I/O操作开始前配置传输事件线程。这是一个破坏性变更,涉及多个组件的API调整。核心变更
1. agent::AdvancedOptions 结构升级(host/include/librmcs/agent/common.hpp)
AdvancedOptions从简单的struct转换为class,现在不支持拷贝和移动thread_setup回调函数指针:void (*)(const AdvancedOptions&) noexceptset_dangerously_skip_version_checks(bool)set_thread_setup(void (*)(const AdvancedOptions&) noexcept)2. 绑定高级选项函数(host/include/librmcs/agent/common.hpp)
bind_advanced_options(FunctorT&& thread_setup_impl)OptionsImpl来保存传入的实现,使用std::invoke适配std::function,保持API的轻量性3. 传输层选项统一(host/src/transport/transport.hpp)
transport::usb::ConnectionOptions从独立的struct变更为agent::AdvancedOptions的类型别名transport.hpp包含了librmcs/agent/common.hpp头文件4. Handler构造函数更新(host/src/protocol/handler.cpp)
options对象传递给transport::usb::create_transport(),而非仅映射dangerously_skip_version_checks字段5. USB事件线程启动同步(host/src/transport/usb/usb.cpp)
thread_setup回调的条件化处理thread_setup时,在新线程内先执行该回调,使用std::atomic<bool>和等待/通知机制同步thread_setup完成后主线程才继续构造,防止绑定回调所依赖的临时状态失效使用指导
thread_setup回调仅用于每线程操作系统级别的配置(如线程优先级、CPU亲和度设置)bind_advanced_options()返回的对象生命周期约束,确保绑定的可调用对象在回调执行期间保持有效thread_setup中访问正在构造的agent对象或传输/协议API破坏性变更
由于
AdvancedOptions不再支持拷贝和移动,现有代码使用聚合初始化模式(如AdvancedOptions{...}或赋值)需要改为使用setter方法或bind_advanced_options()函数。