This got reposted in a better form here: https://shift.click/codelet/codelet-atomic-perf-notes. Or look at the history.
This file contains hidden or 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
# helper fn that returns version number given $crate or $crate/$semver. | |
# both must be url-encoded but the / must be a / if provided. | |
# doesn't handle cases where the version/crate/whatever doesn't exist. | |
resolve_version() { | |
# Perform `HEAD` request to `docs.rs/$1` and dump the redirected URL. | |
# We expect this to go to `docs.rs/crate/$crate/$version` | |
# or `docs.rs/$crate/$version/$crate/` depending on if the crate has | |
# docs or idrk. Maybe a couple other urls are possible, it | |
# took a bit of testing for the `sed` script to handle all cases I found. | |
# |
This file contains hidden or 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
// type Int = i128; | |
type Int = i64; | |
type Rat = (Int, Int); | |
/// Quick and dirty (no overflow handling) continued fraction-based | |
/// rational approximation. | |
/// | |
/// Returns `(p/q, was_exact)` where p/q is an approximation of `n/d`, | |
/// where neither `p` nor `q` are above `limit`. `was_exact` is true if |
This file contains hidden or 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 is a (hopefully) correct implementation of a lockfree stack. | |
//! | |
//! Doing this without a memory reclamation implementation requires pointer | |
//! tagging, which is slightly architecture specific. This supports aarch64 and | |
//! x86_64 so long as 5-level page tables aren't in use (rare to the point of | |
//! nonexistence), and arm64e (or other hardware pointer authentication) is not | |
//! enabled, which is not currently supported by Rust. On x86_64/aarch64 where | |
//! this doesn't hold, it will panic. | |
//! | |
//! That said, while this implementation is believed to be correct, it could |
This file contains hidden or 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
#![no_std] | |
extern crate alloc; | |
#[cfg(test)] | |
extern crate std; | |
use alloc::sync::Arc; | |
use core::{ | |
cell::UnsafeCell, | |
mem::MaybeUninit, | |
ptr::{self, NonNull}, |
This file contains hidden or 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
//! Note: don't use spin locks unless you're doing something | |
//! really strange. They only perform well on microbenchmarks. | |
use core::sync::atomic::{*, Ordering::*}; | |
pub struct SpinLock(AtomicBool); | |
impl SpinLock { | |
#[inline] | |
pub const fn new() -> Self { | |
Self(AtomicBool::new(false)) |
This file contains hidden or 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
//! See https://github.com/ocornut/imgui/issues/3606 | |
use imgui::*; | |
mod support; | |
fn main() { | |
let system = support::init(file!()); | |
system.main_loop(move |_, ui| { | |
fx_window(ui, 0, |d, a, _b, sz, _mouse, t| { | |
for n in 0..(((1.0 + (t * 5.7).sin()) * 40.0) as isize).max(0) { |
This file contains hidden or 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
use core::sync::atomic::{*, Ordering::*}; | |
use core::mem::MaybeUninit; | |
use core::cell::UnsafeCell; | |
/// A macro similar to `lazy_static::lazy_static!`, but that will attempt to | |
/// eagerly initialize the static value using [`on_startup!`](crate::on_startup). | |
#[macro_export] | |
macro_rules! eager_static { | |
($( | |
$(#[$attr:meta])* |
This file contains hidden or 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
#![cfg_attr(all(feature = "std", not(feature = "getrandom")), no_std)] | |
mod get_random; | |
#[repr(C, align(16))] | |
pub struct ChaCha8 { | |
state: [u32; 16], | |
seed: [u32; 8], | |
ctr: u64, | |
stream_id: u64, |
This file contains hidden or 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
struct Semaphore { | |
raw: RawSemaphore, | |
count: AtomicIsize, | |
} | |
impl Semaphore { | |
#[inline] | |
pub fn new(n: usize) -> Self { | |
Self { | |
raw: RawSemaphore::new(), |