Repository navigation
Conversation
…mBLE host task Summary * Adds a public utility, bool NimBLEUtils::runOnHostTask(std::function<void()> func). It lets library users run code on the NimBLE host task. Callers capture whatever context they need in the callable instead of passing a void* plus a lifetime contract. Behavior * Already on the host task: func runs immediately and the call returns true. * Any other task: func is moved into a heap-owned context and queued on the default NimBLE event queue. The host task runs it asynchronously, then frees the context. * Host task not running (before NimBLEDevice::init() or after deinit): the call returns false and the callable is dropped. * Empty std::function: returns false. Design notes * Ownership: the callable and its ble_npl_event live in one heap-allocated HostTaskContext. This replaces a stack-local event and a pointer to the caller's std::function, which were both dangling hazards. * Captured state: values captured by the callable are copied or moved into the context. Anything captured by reference or raw pointer must stay valid until the callable runs. Use values or a shared_ptr when lifetime is uncertain. * Pending-task tracking: queued contexts are kept in a spinlock-protected intrusive list and unlinked in executeHostTask. * Shutdown: NimBLEUtils::deinit() calls the new drainHostTasks(). It clears the host-task handle and removes queued events with ble_npl_eventq_remove. It then frees the contexts without running them. Queueing and the handle check share one lock, so a call racing with deinit is either rejected or drained, never leaked. API contract * The callable runs asynchronously unless the caller is already on the host task. This is not a completion or wait mechanism. * The callable must not throw. It runs inside NimBLE's C event loop. * Work queued but not yet run when the stack is deinitialized is discarded. * A false return means the work was not run or queued.
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
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. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
…mBLE host task
Summary
Behavior
Design notes
API contract