Skip to content

Implement Exclusive use of SharedCrazyradio and add WeakSharedCrazyradio#5

Merged
ataffanel merged 4 commits intomasterfrom
ataffanel/exclusive-shared-radio
Feb 5, 2026
Merged

Implement Exclusive use of SharedCrazyradio and add WeakSharedCrazyradio#5
ataffanel merged 4 commits intomasterfrom
ataffanel/exclusive-shared-radio

Conversation

@ataffanel
Copy link
Member

In order to handle multiple connection to radios and to be able to close the USB radio once all connections are dropped, the LinkContext was using Arc and Weak.

This was not how the SharedCrazyradio was intended to be used, it was internded to be cloned to share the radio, not access by multiple unmutable references.

This PR makes the SharedCrazyradio type encode this requirement by taking &mut self to most methods. It also adds a WeakSharedCrazyradio object to handle the USB device management.

The Crate version is bumped up since this is a breaking change.

In order to handle multiple connection to radios and to be able to close the USB radio
once all connections are dropped,  the LinkContext was using Arc<SharedCrazyradio> and Weak<SharedCrazyradio>.

This was not how the SharedCrazyradio was intended to be used, it was internded to be cloned to share the radio,
not access by multiple unmutable references.

This commit makes the SharedCrazyradio type encode this requirement by taking &mut self to most methods.
It also adds a WeakSharedCrazyradio to handle the USB device management.

The Crate version is bumped up since this is a breaking change.
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors the SharedCrazyradio API to enforce exclusive access semantics by changing most method signatures from &self to &mut self. This change addresses a design issue where the type was being used through multiple immutable references rather than being cloned as intended. The PR also introduces a WeakSharedCrazyradio type for managing weak references to the radio, enabling proper USB device lifecycle management.

Changes:

  • Modified method signatures for send_packet, send_packet_no_ack, scan_async, send_packet_async, and send_packet_no_ack_async to take &mut self instead of &self
  • Added WeakSharedCrazyradio struct with upgrade() method for creating SharedCrazyradio instances from weak references
  • Added downgrade() method to SharedCrazyradio for creating weak references
  • Added #![deny(missing_docs)] directive and documented previously undocumented public APIs
  • Updated examples to use mutable bindings for SharedCrazyradio instances
  • Bumped crate version from 0.3.1 to 0.4.0

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
src/shared_radio.rs Changed method signatures to &mut self, added WeakSharedCrazyradio type and related methods
src/lib.rs Added missing documentation for public APIs, exported WeakSharedCrazyradio, added #![deny(missing_docs)] directive
examples/async_scan.rs Updated to use mutable binding for SharedCrazyradio
examples/async_broadcast.rs Updated to use mutable binding for SharedCrazyradio
Cargo.toml Bumped version from 0.3.1 to 0.4.0 for breaking API change

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

ataffanel and others added 2 commits February 5, 2026 11:32
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@ataffanel ataffanel merged commit 38920e3 into master Feb 5, 2026
1 check passed
@ataffanel ataffanel deleted the ataffanel/exclusive-shared-radio branch February 5, 2026 10:36
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.

3 participants