Skip to content

Instantly share code, notes, and snippets.

View lithdew's full-sized avatar

Kenta Iwasaki lithdew

View GitHub Profile
@lithdew
lithdew / main.zig
Created October 13, 2020 08:50
zig (windows): afd poll w/ WaitForSingleObjectEx
const std = @import("std");
const os = std.os;
const windows = os.windows;
const assert = std.debug.assert;
pub const AFD_POLL_HANDLE_INFO = extern struct {
Handle: windows.HANDLE,
Events: windows.ULONG,
@lithdew
lithdew / list.zig
Last active November 6, 2020 08:31
zig: Waker / List
const std = @import("std");
const meta = std.meta;
const math = std.math;
const testing = std.testing;
const assert = std.debug.assert;
pub const Waker = packed struct {
const Address = meta.Int(.unsigned, meta.bitCount(usize) - 1);
const Self = @This();
@lithdew
lithdew / main.zig
Created November 14, 2020 15:14
zig: using pike for X25519 ECDH -> Blake2b 512-bit KDF -> AEAD
const std = @import("std");
const pike = @import("pike/pike.zig");
const os = std.os;
const net = std.net;
const mem = std.mem;
const log = std.log;
const crypto = std.crypto;
const aead = crypto.aead;
@lithdew
lithdew / buffer.zig
Last active November 21, 2020 15:02
atomic write buffer (zig)
pub fn Buffer(comptime T: type, comptime capacity: comptime_int) type {
return struct {
items: [capacity]T = undefined,
reader: Event = .{},
writer: Event = .{},
dead: bool = false,
head: usize = 0,
tail: usize = 0,
const Self = @This();
@lithdew
lithdew / sync.zig
Created December 11, 2020 15:08
sync.Counter
pub const Counter = struct {
const Self = @This();
state: isize = 0,
event: Event = .{},
pub fn add(self: *Self, delta: isize) void {
var state = @atomicLoad(isize, &self.state, .Monotonic);
var new_state: isize = undefined;
@lithdew
lithdew / main.zig
Last active December 15, 2020 13:29
Assertion failed at stage1/codegen.cpp:4670 in ir_render_union_field_ptr
pub const Empty = struct {
pub inline fn decode(buf: []const u8) !Empty {
return Empty{};
}
};
pub const Type = packed enum(u8) {
no_op
};
@lithdew
lithdew / sync.zig
Created December 17, 2020 19:25
queue
pub fn Queue(comptime T: type, comptime capacity: comptime_int) type {
return struct {
const Self = @This();
const Reader = struct {
task: pike.Task,
dead: bool = false,
};
const Writer = struct {
@lithdew
lithdew / timeout.zig
Last active December 20, 2020 15:36
pike: timeout wheel integration
const std = @import("std");
const mem = std.mem;
const meta = std.meta;
const math = std.math;
const debug = std.debug;
const testing = std.testing;
const assert = debug.assert;
const std = @import("std");
const pike = @import("pike");
const snow = @import("snow");
const timeout = @import("timeout.zig");
const time = std.time;
const Self = @This();
pub const Handle = struct {
const std = @import("std");
const mem = std.mem;
const testing = std.testing;
const Pool = @import("Pool.zig");
const Counter = @import("Counter.zig");
const List = @import("DoublyLinkedList.zig");
const Mutex = std.Thread.Mutex;