Skip to content

Instantly share code, notes, and snippets.


Thom Chiovoloni thomcc

View GitHub Profile
thomcc /
Last active Apr 2, 2021
spsc queue
extern crate alloc;
extern crate std;
use alloc::sync::Arc;
use core::{
ptr::{self, NonNull},
//! 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 {
pub const fn new() -> Self {
//! See
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) {
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_rules! eager_static {
#![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,
struct Semaphore {
raw: RawSemaphore,
count: AtomicIsize,
impl Semaphore {
pub fn new(n: usize) -> Self {
Self {
raw: RawSemaphore::new(),
static A: AtomicU8 = AtomicU8::new(0);
static B: AtomicU8 = AtomicU8::new(0);
const ORDER: Ordering = ???;
let writer_0 = thread::spawn(|| {, ORDER);
let writer_1 = thread::spawn(|| {, ORDER);
thomcc / gist:d23fbed230f5e06d91409f31a2fc9985
Created Nov 5, 2020 — forked from rygorous/gist:2203834
float->sRGB8 using SSE2 (and a table)
View gist:d23fbed230f5e06d91409f31a2fc9985
// float->sRGB8 conversions - two variants.
// by Fabian "ryg" Giesen
// I hereby place this code in the public domain.
// Both variants come with absolute error bounds and a reversibility and monotonicity
// guarantee (see test driver code below). They should pass D3D10 conformance testing
// (not that you can verify this, but still). They are verified against a clean reference
// implementation provided below, and the test driver checks all floats exhaustively.
use std::string::String;
use std::str::Chars;
use std::iter::{Enumerate, Peekable};
// an xml parser that's decent enough if you don't care about parsing perf
// and you completely control the input.
#[derive(Clone, Debug)]
pub struct XmlNode {
pub tag: String,
pub attributes: Vec<(String, String)>,