authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2019-11-13 00:45:37+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2019-11-13 00:52:15+02:00
logf0c94d95dde320ba5e7509dc1499b33e54a1c951
tree0a2d9acdfa2a066c0fcee6d893747ee731a5083b
parent110ef2e52825656fc048cba020f0fc36a1e58d13
signaturelock-open Commit is signed but in an unrecognized format.

use @atomicStore in std lib


10 files changed, 25 insertions(+), 26 deletions(-)

lib/std/atomic/queue.zig+1-1
......@@ -199,7 +199,7 @@ test "std.atomic.Queue" {
199199
200200 for (putters) |t|
201201 t.wait();
202 _ = @atomicRmw(u8, &context.puts_done, builtin.AtomicRmwOp.Xchg, 1, AtomicOrder.SeqCst);
202 @atomicStore(u8, &context.puts_done, 1, AtomicOrder.SeqCst);
203203 for (getters) |t|
204204 t.wait();
205205
lib/std/atomic/stack.zig+1-1
......@@ -128,7 +128,7 @@ test "std.atomic.stack" {
128128
129129 for (putters) |t|
130130 t.wait();
131 _ = @atomicRmw(u8, &context.puts_done, builtin.AtomicRmwOp.Xchg, 1, AtomicOrder.SeqCst);
131 @atomicStore(u8, &context.puts_done, 1, AtomicOrder.SeqCst);
132132 for (getters) |t|
133133 t.wait();
134134 }
lib/std/event/channel.zig+2-2
......@@ -161,7 +161,7 @@ pub fn Channel(comptime T: type) type {
161161
162162 fn dispatch(self: *SelfChannel) void {
163163 // set the "need dispatch" flag
164 _ = @atomicRmw(u8, &self.need_dispatch, .Xchg, 1, .SeqCst);
164 @atomicStore(u8, &self.need_dispatch, 1, .SeqCst);
165165
166166 lock: while (true) {
167167 // set the lock flag
......@@ -169,7 +169,7 @@ pub fn Channel(comptime T: type) type {
169169 if (prev_lock != 0) return;
170170
171171 // clear the need_dispatch flag since we're about to do it
172 _ = @atomicRmw(u8, &self.need_dispatch, .Xchg, 0, .SeqCst);
172 @atomicStore(u8, &self.need_dispatch, 0, .SeqCst);
173173
174174 while (true) {
175175 one_dispatch: {
lib/std/event/future.zig+2-2
......@@ -62,12 +62,12 @@ pub fn Future(comptime T: type) type {
6262 pub async fn start(self: *Self) ?*T {
6363 const state = @cmpxchgStrong(Available, &self.available, .NotStarted, .Started, .SeqCst, .SeqCst) orelse return null;
6464 switch (state) {
65 1 => {
65 .Started => {
6666 const held = self.lock.acquire();
6767 held.release();
6868 return &self.data;
6969 },
70 2 => return &self.data,
70 .Finished => return &self.data,
7171 else => unreachable,
7272 }
7373 }
lib/std/event/lock.zig+5-5
......@@ -31,8 +31,8 @@ pub const Lock = struct {
3131 }
3232
3333 // We need to release the lock.
34 _ = @atomicRmw(u8, &self.lock.queue_empty_bit, .Xchg, 1, .SeqCst);
35 _ = @atomicRmw(u8, &self.lock.shared_bit, .Xchg, 0, .SeqCst);
34 @atomicStore(u8, &self.lock.queue_empty_bit, 1, .SeqCst);
35 @atomicStore(u8, &self.lock.shared_bit, 0, .SeqCst);
3636
3737 // There might be a queue item. If we know the queue is empty, we can be done,
3838 // because the other actor will try to obtain the lock.
......@@ -56,8 +56,8 @@ pub const Lock = struct {
5656 }
5757
5858 // Release the lock again.
59 _ = @atomicRmw(u8, &self.lock.queue_empty_bit, .Xchg, 1, .SeqCst);
60 _ = @atomicRmw(u8, &self.lock.shared_bit, .Xchg, 0, .SeqCst);
59 @atomicStore(u8, &self.lock.queue_empty_bit, 1, .SeqCst);
60 @atomicStore(u8, &self.lock.shared_bit, 0, .SeqCst);
6161
6262 // Find out if we can be done.
6363 if (@atomicLoad(u8, &self.lock.queue_empty_bit, .SeqCst) == 1) {
......@@ -101,7 +101,7 @@ pub const Lock = struct {
101101
102102 // We set this bit so that later we can rely on the fact, that if queue_empty_bit is 1, some actor
103103 // will attempt to grab the lock.
104 _ = @atomicRmw(u8, &self.queue_empty_bit, .Xchg, 0, .SeqCst);
104 @atomicStore(u8, &self.queue_empty_bit, 0, .SeqCst);
105105
106106 const old_bit = @atomicRmw(u8, &self.shared_bit, .Xchg, 1, .SeqCst);
107107 if (old_bit == 0) {
lib/std/event/loop.zig+2-2
......@@ -820,7 +820,7 @@ pub const Loop = struct {
820820 _ = os.kevent(self.os_data.fs_kqfd, fs_kevs, empty_kevs, null) catch unreachable;
821821 },
822822 .linux => {
823 _ = @atomicRmw(i32, &self.os_data.fs_queue_item, AtomicRmwOp.Xchg, 1, AtomicOrder.SeqCst);
823 @atomicStore(i32, &self.os_data.fs_queue_item, 1, AtomicOrder.SeqCst);
824824 const rc = os.linux.futex_wake(&self.os_data.fs_queue_item, os.linux.FUTEX_WAKE, 1);
825825 switch (os.linux.getErrno(rc)) {
826826 0 => {},
......@@ -843,7 +843,7 @@ pub const Loop = struct {
843843 fn posixFsRun(self: *Loop) void {
844844 while (true) {
845845 if (builtin.os == .linux) {
846 _ = @atomicRmw(i32, &self.os_data.fs_queue_item, .Xchg, 0, .SeqCst);
846 @atomicStore(i32, &self.os_data.fs_queue_item, 0, .SeqCst);
847847 }
848848 while (self.os_data.fs_queue.get()) |node| {
849849 switch (node.data.msg) {
lib/std/event/rwlock.zig+9-9
......@@ -40,7 +40,7 @@ pub const RwLock = struct {
4040 return;
4141 }
4242
43 _ = @atomicRmw(u8, &self.lock.reader_queue_empty_bit, .Xchg, 1, .SeqCst);
43 @atomicStore(u8, &self.lock.reader_queue_empty_bit, 1, .SeqCst);
4444 if (@cmpxchgStrong(State, &self.lock.shared_state, .ReadLock, .Unlocked, .SeqCst, .SeqCst) != null) {
4545 // Didn't unlock. Someone else's problem.
4646 return;
......@@ -64,15 +64,15 @@ pub const RwLock = struct {
6464 // We need to release the write lock. Check if any readers are waiting to grab the lock.
6565 if (@atomicLoad(u8, &self.lock.reader_queue_empty_bit, .SeqCst) == 0) {
6666 // Switch to a read lock.
67 _ = @atomicRmw(State, &self.lock.shared_state, .Xchg, .ReadLock, .SeqCst);
67 @atomicStore(State, &self.lock.shared_state, .ReadLock, .SeqCst);
6868 while (self.lock.reader_queue.get()) |node| {
6969 global_event_loop.onNextTick(node);
7070 }
7171 return;
7272 }
7373
74 _ = @atomicRmw(u8, &self.lock.writer_queue_empty_bit, .Xchg, 1, .SeqCst);
75 _ = @atomicRmw(State, &self.lock.shared_state, .Xchg, State.Unlocked, .SeqCst);
74 @atomicStore(u8, &self.lock.writer_queue_empty_bit, 1, .SeqCst);
75 @atomicStore(State, &self.lock.shared_state, .Unlocked, .SeqCst);
7676
7777 self.lock.commonPostUnlock();
7878 }
......@@ -113,7 +113,7 @@ pub const RwLock = struct {
113113
114114 // We set this bit so that later we can rely on the fact, that if reader_queue_empty_bit is 1,
115115 // some actor will attempt to grab the lock.
116 _ = @atomicRmw(u8, &self.reader_queue_empty_bit, .Xchg, 0, .SeqCst);
116 @atomicStore(u8, &self.reader_queue_empty_bit, 0, .SeqCst);
117117
118118 // Here we don't care if we are the one to do the locking or if it was already locked for reading.
119119 const have_read_lock = if (@cmpxchgStrong(State, &self.shared_state, .Unlocked, .ReadLock, .SeqCst, .SeqCst)) |old_state| old_state == .ReadLock else true;
......@@ -144,7 +144,7 @@ pub const RwLock = struct {
144144
145145 // We set this bit so that later we can rely on the fact, that if writer_queue_empty_bit is 1,
146146 // some actor will attempt to grab the lock.
147 _ = @atomicRmw(u8, &self.writer_queue_empty_bit, .Xchg, 0, .SeqCst);
147 @atomicStore(u8, &self.writer_queue_empty_bit, 0, .SeqCst);
148148
149149 // Here we must be the one to acquire the write lock. It cannot already be locked.
150150 if (@cmpxchgStrong(State, &self.shared_state, .Unlocked, .WriteLock, .SeqCst, .SeqCst) == null) {
......@@ -176,8 +176,8 @@ pub const RwLock = struct {
176176 return;
177177 }
178178 // Release the lock again.
179 _ = @atomicRmw(u8, &self.writer_queue_empty_bit, .Xchg, 1, .SeqCst);
180 _ = @atomicRmw(State, &self.shared_state, .Xchg, .Unlocked, .SeqCst);
179 @atomicStore(u8, &self.writer_queue_empty_bit, 1, .SeqCst);
180 @atomicStore(State, &self.shared_state, .Unlocked, .SeqCst);
181181 continue;
182182 }
183183
......@@ -195,7 +195,7 @@ pub const RwLock = struct {
195195 return;
196196 }
197197 // Release the lock again.
198 _ = @atomicRmw(u8, &self.reader_queue_empty_bit, .Xchg, 1, .SeqCst);
198 @atomicStore(u8, &self.reader_queue_empty_bit, 1, .SeqCst);
199199 if (@cmpxchgStrong(State, &self.shared_state, .ReadLock, .Unlocked, .SeqCst, .SeqCst) != null) {
200200 // Didn't unlock. Someone else's problem.
201201 return;
lib/std/os/linux.zig+1-1
......@@ -531,7 +531,7 @@ extern fn init_vdso_clock_gettime(clk: i32, ts: *timespec) usize {
531531 const ptr = @intToPtr(?*const c_void, vdso.lookup(VDSO_CGT_VER, VDSO_CGT_SYM));
532532 // Note that we may not have a VDSO at all, update the stub address anyway
533533 // so that clock_gettime will fall back on the good old (and slow) syscall
534 _ = @cmpxchgStrong(?*const c_void, &vdso_clock_gettime, &init_vdso_clock_gettime, ptr, .Monotonic, .Monotonic);
534 @atomicStore(?*const c_void, &vdso_clock_gettime, ptr, .Monotonic);
535535 // Call into the VDSO if available
536536 if (ptr) |fn_ptr| {
537537 const f = @ptrCast(vdso_clock_gettime_ty, fn_ptr);
lib/std/spinlock.zig+1-2
......@@ -11,8 +11,7 @@ pub const SpinLock = struct {
1111 spinlock: *SpinLock,
1212
1313 pub fn release(self: Held) void {
14 // TODO: @atomicStore() https://github.com/ziglang/zig/issues/2995
15 assert(@atomicRmw(u8, &self.spinlock.lock, .Xchg, 0, .Release) == 1);
14 @atomicStore(u8, &self.spinlock.lock, 0, .Release);
1615 }
1716 };
1817
test/stage1/behavior/atomics.zig+1-1
......@@ -130,4 +130,4 @@ test "atomic store" {
130130 expect(@atomicLoad(u32, &x, .SeqCst) == 1);
131131 @atomicStore(u32, &x, 12345678, .SeqCst);
132132 expect(@atomicLoad(u32, &x, .SeqCst) == 12345678);
133}
\ No newline at end of file
133}