qemu-block
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [RFC PATCH v2 01/14] job.c: make job_lock/unlock public


From: Stefan Hajnoczi
Subject: Re: [RFC PATCH v2 01/14] job.c: make job_lock/unlock public
Date: Thu, 16 Dec 2021 16:18:39 +0000

On Thu, Nov 04, 2021 at 10:53:21AM -0400, Emanuele Giuseppe Esposito wrote:
> job mutex will be used to protect the job struct elements and list,
> replacing AioContext locks.
> 
> Right now use a shared lock for all jobs, in order to keep things
> simple. Once the AioContext lock is gone, we can introduce per-job
> locks.
> 
> To simplify the switch from aiocontext to job lock, introduce
> *nop* lock/unlock functions and macros. Once everything is protected
> by jobs, we can add the mutex and remove the aiocontext.
> Since job_mutex is already being used, add static
> _job_{lock/unlock}.
> 
> Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
> ---
>  include/qemu/job.h | 18 ++++++++++++++++++
>  job.c              | 39 +++++++++++++++++++++++++++------------
>  2 files changed, 45 insertions(+), 12 deletions(-)
> 
> diff --git a/include/qemu/job.h b/include/qemu/job.h
> index 7e9e59f4b8..ccf7826426 100644
> --- a/include/qemu/job.h
> +++ b/include/qemu/job.h
> @@ -297,6 +297,24 @@ typedef enum JobCreateFlags {
>      JOB_MANUAL_DISMISS = 0x04,
>  } JobCreateFlags;
>  
> +/**
> + * job_lock:
> + *
> + * Take the mutex protecting the list of jobs and their status.
> + * Most functions called by the monitor need to call job_lock
> + * and job_unlock manually.  On the other hand, function called
> + * by the block jobs themselves and by the block layer will take the
> + * lock for you.
> + */
> +void job_lock(void);
> +
> +/**
> + * job_unlock:
> + *
> + * Release the mutex protecting the list of jobs and their status.
> + */
> +void job_unlock(void);
> +
>  /**
>   * Allocate and return a new job transaction. Jobs can be added to the
>   * transaction using job_txn_add_job().
> diff --git a/job.c b/job.c
> index 94b142684f..0e4dacf028 100644
> --- a/job.c
> +++ b/job.c
> @@ -32,6 +32,12 @@
>  #include "trace/trace-root.h"
>  #include "qapi/qapi-events-job.h"
>  
> +/*
> + * job_mutex protects the jobs list, but also makes the
> + * struct job fields thread-safe.
> + */
> +static QemuMutex job_mutex;
> +
>  static QLIST_HEAD(, Job) jobs = QLIST_HEAD_INITIALIZER(jobs);
>  
>  /* Job State Transition Table */
> @@ -74,17 +80,26 @@ struct JobTxn {
>      int refcnt;
>  };
>  
> -/* Right now, this mutex is only needed to synchronize accesses to job->busy
> - * and job->sleep_timer, such as concurrent calls to job_do_yield and
> - * job_enter. */
> -static QemuMutex job_mutex;
> +#define JOB_LOCK_GUARD() /* QEMU_LOCK_GUARD(&job_mutex) */
> +
> +#define WITH_JOB_LOCK_GUARD() /* WITH_QEMU_LOCK_GUARD(&job_mutex) */
> +
> +void job_lock(void)
> +{
> +    /* nop */
> +}
> +
> +void job_unlock(void)
> +{
> +    /* nop */
> +}
>  
> -static void job_lock(void)
> +static void _job_lock(void)

QEMU code does not use leading underscores because the C standard
reserves them. real_job_lock()?

See "7.1.3 Reserved identifiers" in C99.

Attachment: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]