qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: Joe Slater <joe.slater@windriver.com>, qemu-devel@nongnu.org
Cc: qemu-trivial@nongnu.org, qemu-stable@nongnu.org
Subject: Re: [PATCH 2/2] lockable: do not rely on optimization for null lockables
Date: Thu, 4 Jun 2020 11:31:41 -0500	[thread overview]
Message-ID: <7db61e38-b9f1-80f4-15c1-fed43f0a939f@redhat.com> (raw)
In-Reply-To: <20200603224903.26268-3-joe.slater@windriver.com>

On 6/3/20 5:49 PM, Joe Slater wrote:
> If we use QLNULL for null lockables, we can always
> use referencing unknown_lock_type as a link time
> error indicator.
> 
> Signed-off-by: Joe Slater <joe.slater@windriver.com>
> ---
>   include/qemu/lockable.h | 19 ++++++-------------
>   1 file changed, 6 insertions(+), 13 deletions(-)
> 
> diff --git a/include/qemu/lockable.h b/include/qemu/lockable.h
> index 7f7aebb..7fc5750 100644
> --- a/include/qemu/lockable.h
> +++ b/include/qemu/lockable.h
> @@ -24,21 +24,14 @@ struct QemuLockable {
>       QemuLockUnlockFunc *unlock;
>   };
>   
> -#define QLNULL ((QemuLockable *)0)
> -
> -
> -/* This function gives an error if an invalid, non-NULL pointer type is passed
> - * to QEMU_MAKE_LOCKABLE.  For optimized builds, we can rely on dead-code elimination
> - * from the compiler, and give the errors already at link time.
> +/*
> + *  If unknown_lock_type() is referenced, it means we have tried to passed something
> + *  not recognized as lockable to the macros below.  Use QLNULL to intentionally pass
> + *  a null lockable.
>    */
> -#if defined(__OPTIMIZE__) && !defined(__SANITIZE_ADDRESS__)
> +#define QLNULL ((QemuLockable *)0)

Looks like a bit of churn (especially if you take my comment on 1/2 to 
spell it NULL instead of 0).  Should these be combined into a single patch?

>   void unknown_lock_type(void *);
> -#else
> -static inline void unknown_lock_type(void *unused)
> -{
> -    abort();
> -}
> -#endif
> +
>   
>   static inline __attribute__((__always_inline__)) QemuLockable *
>   qemu_make_lockable(void *x, QemuLockable *lockable)


Reading further in the file:

/* Auxiliary macros to simplify QEMU_MAKE_LOCABLE.  */

We should fix that typo while improving things.

/* QEMU_MAKE_LOCKABLE - Make a polymorphic QemuLockable
  *
  * @x: a lock object (currently one of QemuMutex, QemuRecMutex, 
CoMutex, QemuSpin).
  *
  * Returns a QemuLockable object that can be passed around
  * to a function that can operate with locks of any kind, or
  * NULL if @x is %NULL.

Should this comment be tweaked to call out %QLNULL?

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org



      reply	other threads:[~2020-06-04 16:32 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-03 22:49 [PATCH 0/2] Use QLNULL for null lockable Joe Slater
2020-06-03 22:49 ` [PATCH 1/2] lockable: use QLNULL for a " Joe Slater
2020-06-04 16:22   ` Eric Blake
2020-06-03 22:49 ` [PATCH 2/2] lockable: do not rely on optimization for null lockables Joe Slater
2020-06-04 16:31   ` Eric Blake [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7db61e38-b9f1-80f4-15c1-fed43f0a939f@redhat.com \
    --to=eblake@redhat.com \
    --cc=joe.slater@windriver.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-stable@nongnu.org \
    --cc=qemu-trivial@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).