Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug in Dispatch executor preventing long sleeps #64304

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,15 @@ static void swift_task_enqueueGlobalWithDelayImpl(JobDelay delay,
job->SchedulerPrivate[Job::DispatchQueueIndex] =
DISPATCH_QUEUE_GLOBAL_EXECUTOR;

// dispatch_time(3): Overflow causes DISPATCH_TIME_FOREVER to be returned.
dispatch_time_t when = dispatch_time(DISPATCH_TIME_NOW, delay);
dispatch_after_f(when, queue, dispatchContext, dispatchFunction);
// dispatch_after(3): The result of passing DISPATCH_TIME_FOREVER as the when
// parameter to `dispatch_after_f` is undefined.
if (when != DISPATCH_TIME_FOREVER) {
dispatch_after_f(when, queue, dispatchContext, dispatchFunction);
} else {
// Leak the job, this is isomorphic to the job getting delayed "forever".
}
}

SWIFT_CC(swift)
Expand Down
9 changes: 8 additions & 1 deletion stdlib/public/Concurrency/DispatchGlobalExecutor.inc
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,15 @@ static void swift_task_enqueueGlobalWithDelayImpl(JobDelay delay,
job->SchedulerPrivate[Job::DispatchQueueIndex] =
DISPATCH_QUEUE_GLOBAL_EXECUTOR;

// dispatch_time(3): Overflow causes DISPATCH_TIME_FOREVER to be returned.
dispatch_time_t when = dispatch_time(DISPATCH_TIME_NOW, delay);
dispatch_after_f(when, queue, dispatchContext, dispatchFunction);
// dispatch_after(3): The result of passing DISPATCH_TIME_FOREVER as the when
// parameter to `dispatch_after_f` is undefined.
if (when != DISPATCH_TIME_FOREVER) {
dispatch_after_f(when, queue, dispatchContext, dispatchFunction);
} else {
// Leak the job, this is isomorphic to the job getting delayed "forever".
}
}

#define DISPATCH_UP_OR_MONOTONIC_TIME_MASK (1ULL << 63)
Expand Down