const ThreadOps = struct run: RunSwitches between two values for each time a run starts.
running: u32While this can be calculated as n_threads - (i -| ops.items.len), this also serves as .release synchronization for each thread.
instance: SafeAllocatori: usizeitems: []Op1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869 const ThreadOps = struct {
/// Switches between two values for each time a run starts.
run: Run,
/// While this can be calculated as `n_threads - (i -| ops.items.len)`,
/// this also serves as `.release` synchronization for each thread.
running: u32,
instance: SafeAllocator,
i: usize,
items: []Op,
const Run = packed struct(u32) {
n: bool,
pad: u31 = 0,
fn wait(ptr: *Run, val: Run, io: std.Io) error{Canceled}!void {
assert(val.pad == 0);
while (true) {
// This cannot load a previous value since this thread previously loaded the
// latest value.
const prev = @atomicLoad(Run, ptr, .acquire);
assert(prev.pad == 0);
if (prev == val) break;
try io.futexWait(Run, ptr, prev);
}
}
fn next(r: Run) Run {
assert(r.pad == 0);
return .{ .n = !r.n };
}
};
const Op = union(fuzz_probs.Op) {
alloc: struct {
len: usize,
alignment: Alignment,
splat: ?u8,
/// Not embeded directly in the struct as a workaround for tsan since a
/// switch directly on `Op` loads the entire value non-atomically.
result: *MemoryDependency,
},
free: struct {
memory: *MemoryDependency,
alignment: Alignment,
splat: ?u8,
},
resize: Realloc,
remap: Realloc,
const Realloc = struct {
memory: *MemoryDependency,
alignment: Alignment,
new_len: usize,
splat: ?u8,
/// Not embeded directly in the struct as a workaround for tsan since a
/// switch directly on `Op` loads the entire value non-atomically.
result: *MemoryDependency,
};
const MemoryDependency = struct {
ready: std.Io.Event,
/// Null if the memory failed to be allocated
memory: ?[]u8,
const init: MemoryDependency = .{
.ready = .unset,
.memory = undefined,
};
fn get(dep: *MemoryDependency, io: std.Io) ?[]u8 {
dep.ready.waitUncancelable(io);
return dep.memory;
}
};
};
}