* introduce std.atomic.Int * add src-self-hosted/test.zig which is tested by the main test suite - it fully utilizes the multithreaded async/await event loop so the tests should Go Fast * `stage2/bin/zig build-obj test.zig` is able to spit out an error if 2 exported functions collide * ability for `zig test` to accept `--object` and `--assembly` arguments * std.build: TestStep supports addLibPath and addObjectFile
20 lines
468 B
Zig
20 lines
468 B
Zig
const builtin = @import("builtin");
|
|
const AtomicOrder = builtin.AtomicOrder;
|
|
|
|
/// Thread-safe, lock-free integer
|
|
pub fn Int(comptime T: type) type {
|
|
return struct {
|
|
value: T,
|
|
|
|
pub const Self = this;
|
|
|
|
pub fn init(init_val: T) Self {
|
|
return Self{ .value = init_val };
|
|
}
|
|
|
|
pub fn next(self: *Self) T {
|
|
return @atomicRmw(T, &self.value, builtin.AtomicRmwOp.Add, 1, AtomicOrder.SeqCst);
|
|
}
|
|
};
|
|
}
|