From: Thomas Huth Date: Fri, 12 May 2017 10:58:47 +0000 Subject: Re: [kvm-unit-tests PATCH v1 1/3] lib: provide generic spinlock Message-Id: <82efd373-4250-ff1b-c6f8-1e11cb5d566d@redhat.com> List-Id: References: <20170512102042.4956-1-david@redhat.com> <20170512102042.4956-2-david@redhat.com> In-Reply-To: <20170512102042.4956-2-david@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: David Hildenbrand , kvm@vger.kernel.org Cc: Paolo Bonzini , =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= , Laurent Vivier , kvm-ppc@vger.kernel.org On 12.05.2017 12:20, David Hildenbrand wrote: > Let's provide a basic lock implementation that should work on most > architectures. > > Signed-off-by: David Hildenbrand > --- > lib/asm-generic/spinlock.h | 16 +++++++++++++++- > 1 file changed, 15 insertions(+), 1 deletion(-) > > diff --git a/lib/asm-generic/spinlock.h b/lib/asm-generic/spinlock.h > index 3141744..e8c3a58 100644 > --- a/lib/asm-generic/spinlock.h > +++ b/lib/asm-generic/spinlock.h > @@ -1,4 +1,18 @@ > #ifndef _ASM_GENERIC_SPINLOCK_H_ > #define _ASM_GENERIC_SPINLOCK_H_ > -#error need architecture specific asm/spinlock.h > + > +struct spinlock { > + unsigned int v; > +}; > + > +static inline void spin_lock(struct spinlock *lock) > +{ > + while (!__sync_bool_compare_and_swap(&lock->v, 0, 1)); > +} > + > +static inline void spin_unlock(struct spinlock *lock) > +{ > + __sync_bool_compare_and_swap(&lock->v, 1, 0); > +} > + > #endif > Reviewed-by: Thomas Huth