aboutsummaryrefslogtreecommitdiff
path: root/job.c
diff options
context:
space:
mode:
authorKevin Wolf <kwolf@redhat.com>2018-04-24 16:55:04 +0200
committerKevin Wolf <kwolf@redhat.com>2018-05-23 14:30:51 +0200
commit198c49cc8d81e8eb0df3749d395599895c3a3a76 (patch)
treede592e39154d0bbe94b9fafaf95af99c3ed2d14d /job.c
parentb3b5299d58bce4366c647af40374e6b063f371eb (diff)
downloadqemu-198c49cc8d81e8eb0df3749d395599895c3a3a76.zip
qemu-198c49cc8d81e8eb0df3749d395599895c3a3a76.tar.gz
qemu-198c49cc8d81e8eb0df3749d395599895c3a3a76.tar.bz2
job: Add job_yield()
This moves block_job_yield() to the Job layer. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Max Reitz <mreitz@redhat.com>
Diffstat (limited to 'job.c')
-rw-r--r--job.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/job.c b/job.c
index 2e453f6..eede680 100644
--- a/job.c
+++ b/job.c
@@ -226,7 +226,7 @@ static bool job_started(Job *job)
return job->co;
}
-bool job_should_pause(Job *job)
+static bool job_should_pause(Job *job)
{
return job->pause_count > 0;
}
@@ -396,7 +396,7 @@ void job_enter(Job *job)
*
* If @ns is (uint64_t) -1, no timer is scheduled and job_enter() must be
* called explicitly. */
-void coroutine_fn job_do_yield(Job *job, uint64_t ns)
+static void coroutine_fn job_do_yield(Job *job, uint64_t ns)
{
job_lock();
if (ns != -1) {
@@ -441,6 +441,22 @@ void coroutine_fn job_pause_point(Job *job)
}
}
+void job_yield(Job *job)
+{
+ assert(job->busy);
+
+ /* Check cancellation *before* setting busy = false, too! */
+ if (job_is_cancelled(job)) {
+ return;
+ }
+
+ if (!job_should_pause(job)) {
+ job_do_yield(job, -1);
+ }
+
+ job_pause_point(job);
+}
+
void coroutine_fn job_sleep_ns(Job *job, int64_t ns)
{
assert(job->busy);