From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Hildenbrand Date: Mon, 15 May 2017 11:03:46 +0000 Subject: [kvm-unit-tests PATCH v2 1/3] lib: provide generic spinlock Message-Id: <20170515110348.30449-2-david@redhat.com> List-Id: References: <20170515110348.30449-1-david@redhat.com> In-Reply-To: <20170515110348.30449-1-david@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: kvm@vger.kernel.org Cc: Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Thomas Huth , david@redhat.com, Laurent Vivier , kvm-ppc@vger.kernel.org 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..31fa510 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_lock_test_and_set(&lock->v, 1)); +} + +static inline void spin_unlock(struct spinlock *lock) +{ + __sync_lock_release(&lock->v); +} + #endif -- 2.9.3 From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Hildenbrand Subject: [kvm-unit-tests PATCH v2 1/3] lib: provide generic spinlock Date: Mon, 15 May 2017 13:03:46 +0200 Message-ID: <20170515110348.30449-2-david@redhat.com> References: <20170515110348.30449-1-david@redhat.com> Cc: Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Thomas Huth , david@redhat.com, Laurent Vivier , kvm-ppc@vger.kernel.org To: kvm@vger.kernel.org Return-path: Received: from mx1.redhat.com ([209.132.183.28]:42312 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932732AbdEOLD5 (ORCPT ); Mon, 15 May 2017 07:03:57 -0400 In-Reply-To: <20170515110348.30449-1-david@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: 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..31fa510 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_lock_test_and_set(&lock->v, 1)); +} + +static inline void spin_unlock(struct spinlock *lock) +{ + __sync_lock_release(&lock->v); +} + #endif -- 2.9.3