From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:32828) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZTfZ2-0006uT-Rf for qemu-devel@nongnu.org; Sun, 23 Aug 2015 20:24:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZTfYz-0000en-MI for qemu-devel@nongnu.org; Sun, 23 Aug 2015 20:24:40 -0400 Received: from out4-smtp.messagingengine.com ([66.111.4.28]:36522) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZTfYz-0000eE-IX for qemu-devel@nongnu.org; Sun, 23 Aug 2015 20:24:37 -0400 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id E5FF020869 for ; Sun, 23 Aug 2015 20:24:36 -0400 (EDT) From: "Emilio G. Cota" Date: Sun, 23 Aug 2015 20:23:34 -0400 Message-Id: <1440375847-17603-6-git-send-email-cota@braap.org> In-Reply-To: <1440375847-17603-1-git-send-email-cota@braap.org> References: <1440375847-17603-1-git-send-email-cota@braap.org> Subject: [Qemu-devel] [RFC 05/38] thread-posix: inline qemu_spin functions List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org, mttcg@listserver.greensocs.com Cc: mark.burton@greensocs.com, a.rigo@virtualopensystems.com, guillaume.delbergue@greensocs.com, pbonzini@redhat.com, alex.bennee@linaro.org, Frederic Konrad On some parallel workloads this gives up to a 15% speed improvement. Signed-off-by: Emilio G. Cota --- include/qemu/thread-posix.h | 47 ++++++++++++++++++++++++++++++++++++++++++ include/qemu/thread.h | 6 ------ util/qemu-thread-posix.c | 50 +++++---------------------------------------- 3 files changed, 52 insertions(+), 51 deletions(-) diff --git a/include/qemu/thread-posix.h b/include/qemu/thread-posix.h index 8ce8f01..7d3a9f1 100644 --- a/include/qemu/thread-posix.h +++ b/include/qemu/thread-posix.h @@ -37,4 +37,51 @@ struct QemuThread { pthread_t thread; }; +void qemu_spin_error_exit(int err, const char *msg); + +static inline void qemu_spin_init(QemuSpin *spin) +{ + int err; + + err = pthread_spin_init(&spin->lock, 0); + if (err) { + qemu_spin_error_exit(err, __func__); + } +} + +static inline void qemu_spin_destroy(QemuSpin *spin) +{ + int err; + + err = pthread_spin_destroy(&spin->lock); + if (err) { + qemu_spin_error_exit(err, __func__); + } +} + +static inline void qemu_spin_lock(QemuSpin *spin) +{ + int err; + + err = pthread_spin_lock(&spin->lock); + if (err) { + qemu_spin_error_exit(err, __func__); + } +} + +static inline int qemu_spin_trylock(QemuSpin *spin) +{ + return pthread_spin_trylock(&spin->lock); +} + +static inline void qemu_spin_unlock(QemuSpin *spin) +{ + int err; + + err = pthread_spin_unlock(&spin->lock); + if (err) { + qemu_spin_error_exit(err, __func__); + } +} + #endif diff --git a/include/qemu/thread.h b/include/qemu/thread.h index f5d1259..003daab 100644 --- a/include/qemu/thread.h +++ b/include/qemu/thread.h @@ -26,12 +26,6 @@ void qemu_mutex_lock(QemuMutex *mutex); int qemu_mutex_trylock(QemuMutex *mutex); void qemu_mutex_unlock(QemuMutex *mutex); -void qemu_spin_init(QemuSpin *spin); -void qemu_spin_destroy(QemuSpin *spin); -void qemu_spin_lock(QemuSpin *spin); -int qemu_spin_trylock(QemuSpin *spin); -void qemu_spin_unlock(QemuSpin *spin); - void qemu_cond_init(QemuCond *cond); void qemu_cond_destroy(QemuCond *cond); diff --git a/util/qemu-thread-posix.c b/util/qemu-thread-posix.c index 224bacc..04dae0f 100644 --- a/util/qemu-thread-posix.c +++ b/util/qemu-thread-posix.c @@ -48,6 +48,11 @@ static void error_exit(int err, const char *msg) abort(); } +void qemu_spin_error_exit(int err, const char *msg) +{ + error_exit(err, msg); +} + void qemu_mutex_init(QemuMutex *mutex) { int err; @@ -89,51 +94,6 @@ void qemu_mutex_unlock(QemuMutex *mutex) error_exit(err, __func__); } -void qemu_spin_init(QemuSpin *spin) -{ - int err; - - err = pthread_spin_init(&spin->lock, 0); - if (err) { - error_exit(err, __func__); - } -} - -void qemu_spin_destroy(QemuSpin *spin) -{ - int err; - - err = pthread_spin_destroy(&spin->lock); - if (err) { - error_exit(err, __func__); - } -} - -void qemu_spin_lock(QemuSpin *spin) -{ - int err; - - err = pthread_spin_lock(&spin->lock); - if (err) { - error_exit(err, __func__); - } -} - -int qemu_spin_trylock(QemuSpin *spin) -{ - return pthread_spin_trylock(&spin->lock); -} - -void qemu_spin_unlock(QemuSpin *spin) -{ - int err; - - err = pthread_spin_unlock(&spin->lock); - if (err) { - error_exit(err, __func__); - } -} - void qemu_cond_init(QemuCond *cond) { int err; -- 1.9.1