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
mod futex { | |
use std::{sync::atomic::AtomicU32, time::Duration}; | |
pub fn wait(_ptr: &AtomicU32, _cmp: u32, _timeout: Option<Duration>) -> bool { | |
unimplemented!("TODO") | |
} | |
pub fn wake(_ptr: *const AtomicU32, _max_wake: u32) { | |
unimplemented!("TODO") | |
} |
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
package main | |
import ( | |
"sync/atomic" | |
"unsafe" | |
) | |
type mutex struct { | |
key uintptr | |
} |
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
unlocked = 0 | |
readers_parked = 1 << 0 | |
writers_parked = 1 << 1 | |
value = 1 << 2 | |
mask = ~(value - 1) | |
reader = value | |
writer = mask |
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
const std = @import("std"); | |
pub fn main() !void { | |
var gpa = std.heap.GeneralPurposeAllocator(.{}){}; | |
defer std.debug.assert(gpa.deinit()); | |
const allocator = &gpa.allocator; | |
const num_threads = std.math.max(1, (std.Thread.getCpuCount() catch 1) / 2); | |
const epolls = try allocator.alloc(std.os.fd_t, num_threads); | |
defer allocator.free(epolls); |
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 std::{ | |
cell::{Cell, UnsafeCell}, | |
pin::Pin, | |
time::Instant, | |
}; | |
pub(crate) struct Lock<T> { | |
os_lock: os::OsLock, | |
value: UnsafeCell<T>, | |
} |
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
const std = @import("std"); | |
const Allocator = std.mem.Allocator; | |
pub const Loop = struct { | |
io_poller: IoPoller, | |
allocator: *Allocator, | |
is_running: bool = true, | |
is_notifying: bool = false, | |
run_queue: RunQueue = .{}, | |
spawned_threads: usize = 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
const std = @import("std"); | |
const Loop = @This(); | |
counter: usize = 0, | |
stack_size: usize, | |
max_workers: usize, | |
idle_lock: Lock = .{}, | |
idle_workers: ?*Worker = null, | |
spawned_workers: ?*Worker = null, | |
run_queues: [Priority.ARRAY_SIZE]GlobalQueue = [_]GlobalQueue{.{}} ** Priority.ARRAY_SIZE, |
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
INIT Init | |
NEXT Next | |
CONSTANT Setters = 3 | |
INVARIANTS | |
IsEventuallySet | |
NoWaiterDeadlock |
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 std::{ | |
pin::Pin, | |
future::Future, | |
cell::UnsafeCell, | |
task::{Waker, RawWaker, RawWakerVTable, Poll, Context}, | |
sync::atomic::{AtomicUsize, Ordering}, | |
}; | |
struct VTable { | |
resume: unsafe fn(*const Task), |
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
const std = @import("std"); | |
const system = std.os.system; | |
pub const Scheduler = struct { | |
pub const InitConfig = struct { | |
max_threads: ?u16 = null, | |
}; | |
pub fn init(self: *Scheduler, config: InitConfig) !void { |