On Thu, 7 Mar 2019 08:36:04 +0000 Julien Thierry <julien.thierry@xxxxxxx> wrote: > Build breaks when using KVM_BRLOCK_DEBUG because the header was seamingly > conceived to be included in a single .c file... > > Fix this by moving the definition of the read/write lock into the kvm > struct. > > Signed-off-by: Julien Thierry <julien.thierry@xxxxxxx> Reviewed-by: Andre Przywara <andre.przywara@xxxxxxx> Cheers, Andre. > --- > include/kvm/brlock.h | 10 ++++------ > include/kvm/kvm.h | 4 ++++ > kvm.c | 4 ++++ > 3 files changed, 12 insertions(+), 6 deletions(-) > > diff --git a/include/kvm/brlock.h b/include/kvm/brlock.h > index 29f72e0..1862210 100644 > --- a/include/kvm/brlock.h > +++ b/include/kvm/brlock.h > @@ -21,13 +21,11 @@ > > #include "kvm/rwsem.h" > > -DECLARE_RWSEM(brlock_sem); > +#define br_read_lock(kvm) down_read(&(kvm)->brlock_sem); > +#define br_read_unlock(kvm) up_read(&(kvm)->brlock_sem); > > -#define br_read_lock(kvm) down_read(&brlock_sem); > -#define br_read_unlock(kvm) up_read(&brlock_sem); > - > -#define br_write_lock(kvm) down_write(&brlock_sem); > -#define br_write_unlock(kvm) up_write(&brlock_sem); > +#define br_write_lock(kvm) down_write(&(kvm)->brlock_sem); > +#define br_write_unlock(kvm) up_write(&(kvm)->brlock_sem); > > #else > > diff --git a/include/kvm/kvm.h b/include/kvm/kvm.h > index 1edacfd..7a73818 100644 > --- a/include/kvm/kvm.h > +++ b/include/kvm/kvm.h > @@ -81,6 +81,10 @@ struct kvm { > int nr_disks; > > int vm_state; > + > +#ifdef KVM_BRLOCK_DEBUG > + pthread_rwlock_t brlock_sem; > +#endif > }; > > void kvm__set_dir(const char *fmt, ...); > diff --git a/kvm.c b/kvm.c > index d5249a0..57c4ff9 100644 > --- a/kvm.c > +++ b/kvm.c > @@ -160,6 +160,10 @@ struct kvm *kvm__new(void) > kvm->sys_fd = -1; > kvm->vm_fd = -1; > > +#ifdef KVM_BRLOCK_DEBUG > + kvm->brlock_sem = (pthread_rwlock_t) PTHREAD_RWLOCK_INITIALIZER; > +#endif > + > return kvm; > } >