Skip to content

Commit 96aa32e

Browse files
committed
Use portable-atomic on platforms without u64 atomics
This has been tested on powerpc-unknown-linux-gnu, which supports atomics only up to u32. Without this commit, building kira would fail with: error[E0432]: unresolved import `std::sync::atomic::AtomicU64` --> crates/kira/src/backend/cpal/desktop/stream_manager.rs:6:24 | 6 | atomic::{AtomicBool, AtomicU64, Ordering}, | ^^^^^^^^^ | | | no `AtomicU64` in `sync::atomic` | help: a similar name exists in the module: `AtomicU32`
1 parent e8f5341 commit 96aa32e

6 files changed

Lines changed: 28 additions & 5 deletions

File tree

crates/kira/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ features = ["wasm-bindgen"]
3333
[target.'cfg(target_arch = "wasm32")'.dependencies]
3434
send_wrapper = "0.6.0"
3535

36+
[target.'cfg(not(target_has_atomic = "64"))'.dependencies]
37+
portable-atomic = "1"
38+
3639
[features]
3740
default = ["cpal", "mp3", "ogg", "flac", "wav"]
3841
mp3 = ["symphonia", "symphonia/mp3"]

crates/kira/src/backend/cpal/desktop.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ impl Backend for CpalBackend {
118118
} else {
119119
device.default_output_config()?.config()
120120
};
121-
121+
122122
let sample_rate = config.sample_rate.0;
123123
let buffer_size = config.buffer_size;
124124

crates/kira/src/backend/cpal/desktop/stream_manager.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,16 @@ mod send_on_drop;
33
use std::{
44
sync::{
55
Arc, Mutex,
6-
atomic::{AtomicBool, AtomicU64, Ordering},
6+
atomic::{AtomicBool, Ordering},
77
},
88
time::Duration,
99
};
1010

11+
#[cfg(not(target_has_atomic = "64"))]
12+
use portable_atomic::AtomicU64;
13+
#[cfg(target_has_atomic = "64")]
14+
use std::sync::atomic::AtomicU64;
15+
1116
use super::renderer_with_cpu_usage::RendererWithCpuUsage;
1217
use cpal::{
1318
BufferSize, Device, Stream, StreamConfig, StreamError,

crates/kira/src/clock.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,14 @@ pub use time::*;
149149

150150
use std::sync::{
151151
Arc,
152-
atomic::{AtomicBool, AtomicU64, Ordering},
152+
atomic::{AtomicBool, Ordering},
153153
};
154154

155+
#[cfg(not(target_has_atomic = "64"))]
156+
use portable_atomic::AtomicU64;
157+
#[cfg(target_has_atomic = "64")]
158+
use std::sync::atomic::AtomicU64;
159+
155160
use crate::{
156161
Parameter, Value,
157162
command::{ValueChangeCommand, read_commands_into_parameters},

crates/kira/src/sound/static_sound/sound.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,14 @@ mod test;
55

66
use std::sync::{
77
Arc,
8-
atomic::{AtomicU8, AtomicU64, Ordering},
8+
atomic::{AtomicU8, Ordering},
99
};
1010

11+
#[cfg(not(target_has_atomic = "64"))]
12+
use portable_atomic::AtomicU64;
13+
#[cfg(target_has_atomic = "64")]
14+
use std::sync::atomic::AtomicU64;
15+
1116
use crate::{
1217
Decibels, Panning, Parameter, PlaybackRate, StartTime, Tween,
1318
command::read_commands_into_parameters,

crates/kira/src/sound/streaming/sound.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,14 @@ mod test;
55

66
use std::sync::{
77
Arc,
8-
atomic::{AtomicBool, AtomicU8, AtomicU64, Ordering},
8+
atomic::{AtomicBool, AtomicU8, Ordering},
99
};
1010

11+
#[cfg(not(target_has_atomic = "64"))]
12+
use portable_atomic::AtomicU64;
13+
#[cfg(target_has_atomic = "64")]
14+
use std::sync::atomic::AtomicU64;
15+
1116
use crate::{
1217
Decibels, Panning, Parameter, PlaybackRate, StartTime, Tween,
1318
command::read_commands_into_parameters,

0 commit comments

Comments
 (0)