-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
timer: use our own AtomicU64 on targets with target_has_atomic less than 64 #1538
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,41 @@ | ||
jobs: | ||
- job: ${{ parameters.name }} | ||
displayName: ${{ parameters.displayName }} | ||
strategy: | ||
matrix: | ||
i686: | ||
vmImage: ubuntu-16.04 | ||
target: i686-unknown-linux-gnu | ||
powerpc: | ||
vmImage: ubuntu-16.04 | ||
target: powerpc-unknown-linux-gnu | ||
powerpc64: | ||
vmImage: ubuntu-16.04 | ||
target: powerpc64-unknown-linux-gnu | ||
mips: | ||
vmImage: ubuntu-16.04 | ||
target: mips-unknown-linux-gnu | ||
pool: | ||
vmImage: ubuntu-16.04 | ||
vmImage: $(vmImage) | ||
steps: | ||
- template: azure-install-rust.yml | ||
parameters: | ||
rust_version: stable | ||
rust_version: ${{ parameters.rust }} | ||
|
||
- script: sudo apt-get update | ||
displayName: "apt-get update" | ||
displayName: apt-get update | ||
|
||
- script: sudo apt-get install gcc-multilib | ||
displayName: "Install gcc-multilib" | ||
displayName: Install gcc-multilib | ||
|
||
- script: rustup target add ${{ parameters.target }} | ||
displayName: "Add target" | ||
- script: cargo install cross | ||
displayName: Install cross | ||
|
||
# Always patch | ||
- template: azure-patch-crates.yml | ||
|
||
- script: cargo check --all --exclude tokio-tls --target ${{ parameters.target }} | ||
- script: cross check --all --exclude tokio-tls --target $(target) | ||
displayName: Check source | ||
|
||
- script: cargo check --tests --all --exclude tokio-tls --target ${{ parameters.target }} | ||
displayName: Check tests | ||
# - script: cross check --tests --all --exclude tokio-tls --target $(target) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This cannot be enabled because at least one dev-dependency does not support architectures other than |
||
# displayName: Check tests |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
//! Implementation of an atomic u64 cell. On 64 bit platforms, this is a | ||
//! re-export of `AtomicU64`. On 32 bit platforms, this is implemented using a | ||
//! `Mutex`. | ||
|
||
pub(crate) use self::imp::AtomicU64; | ||
|
||
// `AtomicU64` can only be used on targets with `target_has_atomic` is 64 or greater. | ||
// Once `cfg_target_has_atomic` feature is stable, we can replace it with | ||
// `#[cfg(target_has_atomic = "64")]`. | ||
#[cfg(not(any(target_arch = "mips", target_arch = "powerpc")))] | ||
mod imp { | ||
pub(crate) use std::sync::atomic::AtomicU64; | ||
} | ||
|
||
#[cfg(any(target_arch = "mips", target_arch = "powerpc"))] | ||
mod imp { | ||
use std::sync::atomic::Ordering; | ||
use std::sync::Mutex; | ||
|
||
#[derive(Debug)] | ||
pub(crate) struct AtomicU64 { | ||
inner: Mutex<u64>, | ||
} | ||
|
||
impl AtomicU64 { | ||
pub(crate) fn new(val: u64) -> AtomicU64 { | ||
AtomicU64 { | ||
inner: Mutex::new(val), | ||
} | ||
} | ||
|
||
pub(crate) fn load(&self, _: Ordering) -> u64 { | ||
*self.inner.lock().unwrap() | ||
} | ||
|
||
pub(crate) fn store(&self, val: u64, _: Ordering) { | ||
*self.inner.lock().unwrap() = val; | ||
} | ||
|
||
pub(crate) fn fetch_or(&self, val: u64, _: Ordering) -> u64 { | ||
let mut lock = self.inner.lock().unwrap(); | ||
let prev = *lock; | ||
*lock = prev | val; | ||
prev | ||
} | ||
|
||
pub(crate) fn compare_and_swap(&self, old: u64, new: u64, _: Ordering) -> u64 { | ||
let mut lock = self.inner.lock().unwrap(); | ||
let prev = *lock; | ||
|
||
if prev != old { | ||
return prev; | ||
} | ||
|
||
*lock = new; | ||
prev | ||
} | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,7 @@ pub mod throttle; | |
pub mod timeout; | ||
pub mod timer; | ||
|
||
mod atomic; | ||
mod delay; | ||
mod error; | ||
mod interval; | ||
|
This file contains 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
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This matrix is roughly the same as what we use in bytes.