authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-10-29 14:41:18-04:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2020-10-29 14:41:18-04:00
log844eb932f4a253863d36e01a713724141c1f6361
treeebd29ee35dd4219a642fb7e8a0a23cf03ce96957
parente59dd7eecfe9ff3a2eb82c630d5021fbd280011d
parent504f259c24f202d9160da3f13d7091086162d2d3
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #6841 from ifreund/fix-event-loop

std/event: fix poll error set handling

1 files changed, 7 insertions(+), 6 deletions(-)

lib/std/event/loop.zig+7-6
......@@ -467,6 +467,7 @@ pub const Loop = struct {
467467 }};
468468 _ = os.poll(&pfd, -1) catch |poll_err| switch (poll_err) {
469469 error.SystemResources,
470 error.NetworkSubsystemFailed,
470471 error.Unexpected,
471472 => {
472473 // Even poll() didn't work. The best we can do now is sleep for a
......@@ -772,7 +773,7 @@ pub const Loop = struct {
772773 self.delay_queue.waiters.insert(&entry);
773774
774775 // Speculatively wake up the timer thread when we add a new entry.
775 // If the timer thread is sleeping on a longer entry, we need to
776 // If the timer thread is sleeping on a longer entry, we need to
776777 // interrupt it so that our entry can be expired in time.
777778 self.delay_queue.event.set();
778779 }
......@@ -784,7 +785,7 @@ pub const Loop = struct {
784785 thread: *std.Thread,
785786 event: std.AutoResetEvent,
786787 is_running: bool,
787
788
788789 /// Initialize the delay queue by spawning the timer thread
789790 /// and starting any timer resources.
790791 fn init(self: *DelayQueue) !void {
......@@ -799,7 +800,7 @@ pub const Loop = struct {
799800 };
800801 }
801802
802 /// Entry point for the timer thread
803 /// Entry point for the timer thread
803804 /// which waits for timer entries to expire and reschedules them.
804805 fn run(self: *DelayQueue) void {
805806 const loop = @fieldParentPtr(Loop, "delay_queue", self);
......@@ -847,12 +848,12 @@ pub const Loop = struct {
847848 const entry = self.peekExpiringEntry() orelse return null;
848849 if (entry.expires > now)
849850 return null;
850
851
851852 assert(self.entries.remove(&entry.node));
852853 return entry;
853854 }
854
855 /// Returns an estimate for the amount of time
855
856 /// Returns an estimate for the amount of time
856857 /// to wait until the next waiting entry expires.
857858 fn nextExpire(self: *Waiters) ?u64 {
858859 const entry = self.peekExpiringEntry() orelse return null;