]> git.ipfire.org Git - thirdparty/qemu.git/commit
lockable: add lock guards
authorStefan Hajnoczi <stefanha@redhat.com>
Mon, 16 Mar 2020 11:09:56 +0000 (11:09 +0000)
committerPaolo Bonzini <pbonzini@redhat.com>
Tue, 17 Mar 2020 14:18:45 +0000 (15:18 +0100)
commit3284c3ddc48ba8fc853858c95d87dcc2ab160b29
tree40c7c87cb3f7f0c3a8cb95d45ce3ee26f06dd1e0
parent8834dcf47e8543b92e072706d3a5621762bfa106
lockable: add lock guards

This patch introduces two lock guard macros that automatically unlock a
lock object (QemuMutex and others):

  void f(void) {
      QEMU_LOCK_GUARD(&mutex);
      if (!may_fail()) {
          return; /* automatically unlocks mutex */
      }
      ...
  }

and:

  WITH_QEMU_LOCK_GUARD(&mutex) {
      if (!may_fail()) {
          return; /* automatically unlocks mutex */
      }
  }
  /* automatically unlocks mutex here */
  ...

Convert qemu-timer.c functions that benefit from these macros as an
example.  Manual qemu_mutex_lock/unlock() callers are left unmodified in
cases where clarity would not improve by switching to the macros.

Many other QemuMutex users remain in the codebase that might benefit
from lock guards.  Over time they can be converted, if that is
desirable.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
[Use QEMU_MAKE_LOCKABLE_NONNULL. - Paolo]
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
include/qemu/lockable.h
util/qemu-timer.c