authorgravatar for kappaloris@gmail.comLoris Cro <kappaloris@gmail.com> 2020-09-29 11:18:35+02:00
committergravatar for kappaloris@gmail.comLoris Cro <kappaloris@gmail.com> 2020-09-29 11:18:35+02:00
loga45a4230bc2ef67dca4bd3267863695d6b04adfa
tree9c4f714a633166bb0d9522cfc562268b779b4fd2
parenta0c0f9ead53dab4f558dbb51cc8a49961fc6984f

Fix std.event.Future

Signed-off-by: Loris Cro <kappaloris@gmail.com>

2 files changed, 12 insertions(+), 8 deletions(-)

lib/std/event/future.zig+1-1
......@@ -95,7 +95,7 @@ test "std.event.Future" {
9595 // TODO provide a way to run tests in evented I/O mode
9696 if (!std.io.is_async) return error.SkipZigTest;
9797
98 const handle = async testFuture();
98 testFuture();
9999}
100100
101101fn testFuture() void {
lib/std/event/lock.zig+11-7
......@@ -27,20 +27,24 @@ pub const Lock = struct {
2727
2828 const Waiter = struct {
2929 // forced Waiter alignment to ensure it doesn't clash with LOCKED
30 next: ?*Waiter align(2),
30 next: ?*Waiter align(2),
3131 tail: *Waiter,
3232 node: Loop.NextTickNode,
3333 };
3434
35 pub fn initLocked() Lock {
36 return Lock{ .head = LOCKED };
37 }
38
3539 pub fn acquire(self: *Lock) Held {
3640 const held = self.mutex.acquire();
3741
3842 // self.head transitions from multiple stages depending on the value:
39 // UNLOCKED -> LOCKED:
43 // UNLOCKED -> LOCKED:
4044 // acquire Lock ownership when theres no waiters
4145 // LOCKED -> <Waiter head ptr>:
4246 // Lock is already owned, enqueue first Waiter
43 // <head ptr> -> <head ptr>:
47 // <head ptr> -> <head ptr>:
4448 // Lock is owned with pending waiters. Push our waiter to the queue.
4549
4650 if (self.head == UNLOCKED) {
......@@ -51,7 +55,7 @@ pub const Lock = struct {
5155
5256 var waiter: Waiter = undefined;
5357 waiter.next = null;
54 waiter.tail = &waiter;
58 waiter.tail = &waiter;
5559
5660 const head = switch (self.head) {
5761 UNLOCKED => unreachable,
......@@ -79,15 +83,15 @@ pub const Lock = struct {
7983 }
8084
8185 pub const Held = struct {
82 lock: *Lock,
83
86 lock: *Lock,
87
8488 pub fn release(self: Held) void {
8589 const waiter = blk: {
8690 const held = self.lock.mutex.acquire();
8791 defer held.release();
8892
8993 // self.head goes through the reverse transition from acquire():
90 // <head ptr> -> <new head ptr>:
94 // <head ptr> -> <new head ptr>:
9195 // pop a waiter from the queue to give Lock ownership when theres still others pending
9296 // <head ptr> -> LOCKED:
9397 // pop the laster waiter from the queue, while also giving it lock ownership when awaken