Skip to content

Commit

Permalink
Ditch lazy_static use in favor of embassy_sync::once_lock
Browse files Browse the repository at this point in the history
  • Loading branch information
zeenix committed Jul 2, 2024
1 parent 0e7d9e6 commit d6b34b1
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 26 deletions.
10 changes: 0 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ heapless = { version = "0.7", default-features = false }
futures = { version = "0.3", default-features = false, features = [
"async-await",
] }
lazy_static = { version = "1.5.0", default-features = false, features = [
"spin_no_std",
] }
embassy-sync = { git = "https://github.com/jucr-io/embassy/" }
embassy-executor = { git = "https://github.com/jucr-io/embassy/", features = [
"task-arena-size-32768",
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ The `controller` macro will generated the following for you:
The `controller` macro assumes that you have the following dependencies in your `Cargo.toml`:

* `futures` with `async-await` feature enabled.
* `lazy_static` with either the default feature or `spin_no_std` feature enabled.
* `embassy-sync`

## Known limitations
Expand Down
26 changes: 14 additions & 12 deletions src/controller/item_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,17 +376,15 @@ impl Signal {
#max_publishers,
> = embassy_sync::pubsub::PubSubChannel::new();

lazy_static::lazy_static! {
static ref #args_publisher_name: embassy_sync::pubsub::publisher::Publisher<
'static,
embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex,
#args_struct_name,
#capacity,
#max_subscribers,
#max_publishers,
// Safety: The publisher is only initialized once.
> = embassy_sync::pubsub::PubSubChannel::publisher(&#args_channel_name).unwrap();
}
static #args_publisher_name: embassy_sync::once_lock::OnceLock<embassy_sync::pubsub::publisher::Publisher<
'static,
embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex,
#args_struct_name,
#capacity,
#max_subscribers,
#max_publishers,
// Safety: The publisher is only initialized once.
>> = embassy_sync::once_lock::OnceLock::new();

#[derive(Debug, Clone)]
pub struct #args_struct_name {
Expand Down Expand Up @@ -426,8 +424,12 @@ impl Signal {
};

method.block = parse_quote!({
embassy_sync::pubsub::publisher::Pub::publish(
let publisher = embassy_sync::once_lock::OnceLock::get_or_init(
&#args_publisher_name,
// Safety: The publisher is only initialized once.
|| embassy_sync::pubsub::PubSubChannel::publisher(&#args_channel_name).unwrap());
embassy_sync::pubsub::publisher::Pub::publish(
publisher,
#args_struct_name { #(#names),* },
).await;
});
Expand Down

0 comments on commit d6b34b1

Please sign in to comment.