Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use portable-atomic when AtomicU64 is not available. #233

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ libc = "0.2.39"
serde = { version = "1.0.27", optional = true }
serde_derive = { version = "1.0.27", optional = true }

[target.'cfg(not(target_has_atomic = "u64"))'.dependencies]
portable-atomic = "1"

[target.'cfg(any(target_os = "linux", target_os = "android"))'.dependencies]
bitflags = "1.0"

Expand Down
2 changes: 1 addition & 1 deletion src/fam.rs
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ mod tests {
fn test_invalid_type_conversion() {
let mut adapter = MockFamStructWrapperU8::new(10).unwrap();
assert!(matches!(
adapter.set_len(0xffff_ffff_ffff_ff00),
adapter.set_len(usize::MAX & !0xff),
Err(Error::SizeLimitExceeded)
));
}
Expand Down
6 changes: 3 additions & 3 deletions src/linux/sock_ctrl_msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -479,15 +479,15 @@ mod tests {
if size_of::<RawFd>() == 4 {
assert_eq!(
CMSG_SPACE!(2 * size_of::<RawFd>()),
size_of::<cmsghdr>() + size_of::<c_long>()
size_of::<cmsghdr>() + size_of::<c_long>() * 2
);
assert_eq!(
CMSG_SPACE!(3 * size_of::<RawFd>()),
size_of::<cmsghdr>() + size_of::<c_long>() * 2
size_of::<cmsghdr>() + size_of::<c_long>() * 3
);
assert_eq!(
CMSG_SPACE!(4 * size_of::<RawFd>()),
size_of::<cmsghdr>() + size_of::<c_long>() * 2
size_of::<cmsghdr>() + size_of::<c_long>() * 4
);
} else if size_of::<RawFd>() == 8 {
assert_eq!(
Expand Down
11 changes: 10 additions & 1 deletion src/metric.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@
//! of these components can choose what metrics they’re interested in and also
//! can add their own custom metrics without the need to maintain forks.

use std::sync::atomic::{AtomicU64, Ordering};
#[cfg(target_has_atomic = "64")]
use std::sync::atomic::AtomicU64;
use std::sync::atomic::Ordering;

#[cfg(not(target_has_atomic = "64"))]
use portable_atomic::AtomicU64;

/// Abstraction over the common metric operations.
///
Expand Down Expand Up @@ -63,9 +68,13 @@ impl Metric for AtomicU64 {
mod tests {
use crate::metric::Metric;

#[cfg(target_has_atomic = "64")]
use std::sync::atomic::AtomicU64;
use std::sync::Arc;

#[cfg(not(target_has_atomic = "64"))]
use portable_atomic::AtomicU64;

struct Dog<T: DogEvents> {
metrics: T,
}
Expand Down