src: fix thread-safety issues @ ContinuousProfiler#309
src: fix thread-safety issues @ ContinuousProfiler#309santigimeno wants to merge 1 commit intonode-v22.x-nsolid-v5.xfrom
Conversation
WalkthroughThe changes refactor the Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant ContinuousProfiler
participant Thread
User->>ContinuousProfiler: Enable(interval_ms)
ContinuousProfiler->>ContinuousProfiler: Acquire lock, set enabled_
ContinuousProfiler->>ContinuousProfiler: Check should_start()
alt should_start() true
ContinuousProfiler->>ContinuousProfiler: start_cpu_profiling()
end
User->>ContinuousProfiler: register_hook_impl(callback)
ContinuousProfiler->>ContinuousProfiler: Acquire lock, add callback
ContinuousProfiler->>ContinuousProfiler: Check should_start()
alt should_start() true
ContinuousProfiler->>ContinuousProfiler: start_cpu_profiling()
end
User->>ContinuousProfiler: Disable()
ContinuousProfiler->>ContinuousProfiler: Acquire lock, set enabled_ = false
User->>ContinuousProfiler: UnregisterHook(hook_id)
ContinuousProfiler->>ContinuousProfiler: Acquire lock, remove callback
Poem
Tip ⚡️ Faster reviews with caching
Enjoy the performance boost—your workflow just got faster. 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
⏰ Context from checks skipped due to timeout of 90000ms (9)
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Other comments: 0 Blocking, 0 Optional, 0 Nit, 2 FYI
- FYI: src/nsolid/continuous_profiler.cc (71-71) FYI: The code uses `should_start()` method in several places (lines 61, 71, 90) but this method isn't defined in the visible code. Make sure this method is properly implemented.
- FYI: src/nsolid/continuous_profiler.cc (171-171) FYI: The `pending_threads_.erase(thread_id)` call is already protected by the `thread_mutex_` lock at the beginning of the `on_thread_removed()` method. No need for additional locking here.
| uv_loop_t* loop_ = nullptr; | ||
| uint64_t interval_ = 60000; // Default: 1 minute per configuration | ||
| std::atomic<uint64_t> interval_ = 60000; // 1 min | ||
| bool enabled_ = false; // Disabled by default per config |
There was a problem hiding this comment.
The enabled_ member variable should be declared as std::atomic<bool> for thread safety, similar to how interval_ was changed to std::atomic<uint64_t>.
7da3c8c to
adce98e
Compare
adce98e to
e43a523
Compare
Fixes: nodesource/nsolid-roadmap#31 PR-URL: #309 Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
|
Landed in 63ce33e |
Fixes: nodesource/nsolid-roadmap#31 PR-URL: #309 Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Fixes: nodesource/nsolid-roadmap#31 PR-URL: #309 Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> PR-URL: #359 Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
Summary by CodeRabbit