aboutsummaryrefslogtreecommitdiff
path: root/lib/std/atomic/queue.zig
diff options
context:
space:
mode:
authorVexu <git@vexu.eu>2020-03-10 22:46:19 +0200
committerVexu <git@vexu.eu>2020-03-10 22:54:47 +0200
commitee5b00a8b90ef375d0cd4432d31e3a4ed0b6f632 (patch)
treec775663438485092fca336a68a5bcbbc047de818 /lib/std/atomic/queue.zig
parent8dc188ebe06b5b78dcead521561858fc27e25204 (diff)
downloadzig-ee5b00a8b90ef375d0cd4432d31e3a4ed0b6f632.tar.gz
zig-ee5b00a8b90ef375d0cd4432d31e3a4ed0b6f632.zip
use atomic bools in std lib
Diffstat (limited to 'lib/std/atomic/queue.zig')
-rw-r--r--lib/std/atomic/queue.zig20
1 files changed, 9 insertions, 11 deletions
diff --git a/lib/std/atomic/queue.zig b/lib/std/atomic/queue.zig
index 1969587f30..5c40acc3cb 100644
--- a/lib/std/atomic/queue.zig
+++ b/lib/std/atomic/queue.zig
@@ -1,7 +1,5 @@
const std = @import("../std.zig");
const builtin = @import("builtin");
-const AtomicOrder = builtin.AtomicOrder;
-const AtomicRmwOp = builtin.AtomicRmwOp;
const assert = std.debug.assert;
const expect = std.testing.expect;
@@ -149,7 +147,7 @@ const Context = struct {
put_sum: isize,
get_sum: isize,
get_count: usize,
- puts_done: u8, // TODO make this a bool
+ puts_done: bool,
};
// TODO add lazy evaluated build options and then put puts_per_thread behind
@@ -173,7 +171,7 @@ test "std.atomic.Queue" {
.queue = &queue,
.put_sum = 0,
.get_sum = 0,
- .puts_done = 0,
+ .puts_done = false,
.get_count = 0,
};
@@ -186,7 +184,7 @@ test "std.atomic.Queue" {
}
}
expect(!context.queue.isEmpty());
- context.puts_done = 1;
+ context.puts_done = true;
{
var i: usize = 0;
while (i < put_thread_count) : (i += 1) {
@@ -208,7 +206,7 @@ test "std.atomic.Queue" {
for (putters) |t|
t.wait();
- @atomicStore(u8, &context.puts_done, 1, AtomicOrder.SeqCst);
+ @atomicStore(bool, &context.puts_done, true, .SeqCst);
for (getters) |t|
t.wait();
@@ -235,25 +233,25 @@ fn startPuts(ctx: *Context) u8 {
std.time.sleep(1); // let the os scheduler be our fuzz
const x = @bitCast(i32, r.random.scalar(u32));
const node = ctx.allocator.create(Queue(i32).Node) catch unreachable;
- node.* = Queue(i32).Node{
+ node.* = .{
.prev = undefined,
.next = undefined,
.data = x,
};
ctx.queue.put(node);
- _ = @atomicRmw(isize, &ctx.put_sum, builtin.AtomicRmwOp.Add, x, AtomicOrder.SeqCst);
+ _ = @atomicRmw(isize, &ctx.put_sum, .Add, x, .SeqCst);
}
return 0;
}
fn startGets(ctx: *Context) u8 {
while (true) {
- const last = @atomicLoad(u8, &ctx.puts_done, builtin.AtomicOrder.SeqCst) == 1;
+ const last = @atomicLoad(bool, &ctx.puts_done, .SeqCst);
while (ctx.queue.get()) |node| {
std.time.sleep(1); // let the os scheduler be our fuzz
- _ = @atomicRmw(isize, &ctx.get_sum, builtin.AtomicRmwOp.Add, node.data, builtin.AtomicOrder.SeqCst);
- _ = @atomicRmw(usize, &ctx.get_count, builtin.AtomicRmwOp.Add, 1, builtin.AtomicOrder.SeqCst);
+ _ = @atomicRmw(isize, &ctx.get_sum, .Add, node.data, .SeqCst);
+ _ = @atomicRmw(usize, &ctx.get_count, .Add, 1, .SeqCst);
}
if (last) return 0;