From patchwork Thu Apr 5 10:59:11 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kiszka X-Patchwork-Id: 150910 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id B4BA8B7055 for ; Thu, 5 Apr 2012 21:03:13 +1000 (EST) Received: from localhost ([::1]:41212 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SFkT9-0008UF-Jo for incoming@patchwork.ozlabs.org; Thu, 05 Apr 2012 07:03:11 -0400 Received: from eggs.gnu.org ([208.118.235.92]:45189) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SFkQf-0007jJ-PG for qemu-devel@nongnu.org; Thu, 05 Apr 2012 07:02:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SFkPR-00074e-En for qemu-devel@nongnu.org; Thu, 05 Apr 2012 07:00:37 -0400 Received: from david.siemens.de ([192.35.17.14]:29887) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SFkPR-00073s-4s for qemu-devel@nongnu.org; Thu, 05 Apr 2012 06:59:21 -0400 Received: from mail1.siemens.de (localhost [127.0.0.1]) by david.siemens.de (8.13.6/8.13.6) with ESMTP id q35AxIKd000351; Thu, 5 Apr 2012 12:59:18 +0200 Received: from mchn199C.mchp.siemens.de ([139.25.109.49]) by mail1.siemens.de (8.13.6/8.13.6) with ESMTP id q35AxIcA027596; Thu, 5 Apr 2012 12:59:18 +0200 From: Jan Kiszka To: Anthony Liguori , qemu-devel@nongnu.org Date: Thu, 5 Apr 2012 12:59:11 +0200 Message-Id: <18c36facfe6cb1eb9ff18f2d37946190f1563357.1333623555.git.jan.kiszka@siemens.com> X-Mailer: git-send-email 1.7.3.4 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-Received-From: 192.35.17.14 Cc: Kevin Wolf , Paolo Bonzini Subject: [Qemu-devel] [PATCH v3 04/10] qemu-thread: Factor out qemu_error_exit X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Will be used in another wrapper module soon. Signed-off-by: Jan Kiszka --- qemu-thread-posix.c | 30 +++++++++++++++--------------- qemu-thread-win32.c | 18 +++++++++--------- qemu-thread.h | 2 ++ 3 files changed, 26 insertions(+), 24 deletions(-) diff --git a/qemu-thread-posix.c b/qemu-thread-posix.c index cd65df2..6b687f0 100644 --- a/qemu-thread-posix.c +++ b/qemu-thread-posix.c @@ -20,7 +20,7 @@ #include #include "qemu-thread.h" -static void error_exit(int err, const char *msg) +void qemu_error_exit(int err, const char *msg) { fprintf(stderr, "qemu: %s: %s\n", msg, strerror(err)); abort(); @@ -36,7 +36,7 @@ void qemu_mutex_init(QemuMutex *mutex) err = pthread_mutex_init(&mutex->lock, &mutexattr); pthread_mutexattr_destroy(&mutexattr); if (err) - error_exit(err, __func__); + qemu_error_exit(err, __func__); } void qemu_mutex_destroy(QemuMutex *mutex) @@ -45,7 +45,7 @@ void qemu_mutex_destroy(QemuMutex *mutex) err = pthread_mutex_destroy(&mutex->lock); if (err) - error_exit(err, __func__); + qemu_error_exit(err, __func__); } void qemu_mutex_lock(QemuMutex *mutex) @@ -54,7 +54,7 @@ void qemu_mutex_lock(QemuMutex *mutex) err = pthread_mutex_lock(&mutex->lock); if (err) - error_exit(err, __func__); + qemu_error_exit(err, __func__); } int qemu_mutex_trylock(QemuMutex *mutex) @@ -68,7 +68,7 @@ void qemu_mutex_unlock(QemuMutex *mutex) err = pthread_mutex_unlock(&mutex->lock); if (err) - error_exit(err, __func__); + qemu_error_exit(err, __func__); } void qemu_cond_init(QemuCond *cond) @@ -77,7 +77,7 @@ void qemu_cond_init(QemuCond *cond) err = pthread_cond_init(&cond->cond, NULL); if (err) - error_exit(err, __func__); + qemu_error_exit(err, __func__); } void qemu_cond_destroy(QemuCond *cond) @@ -86,7 +86,7 @@ void qemu_cond_destroy(QemuCond *cond) err = pthread_cond_destroy(&cond->cond); if (err) - error_exit(err, __func__); + qemu_error_exit(err, __func__); } void qemu_cond_signal(QemuCond *cond) @@ -95,7 +95,7 @@ void qemu_cond_signal(QemuCond *cond) err = pthread_cond_signal(&cond->cond); if (err) - error_exit(err, __func__); + qemu_error_exit(err, __func__); } void qemu_cond_broadcast(QemuCond *cond) @@ -104,7 +104,7 @@ void qemu_cond_broadcast(QemuCond *cond) err = pthread_cond_broadcast(&cond->cond); if (err) - error_exit(err, __func__); + qemu_error_exit(err, __func__); } void qemu_cond_wait(QemuCond *cond, QemuMutex *mutex) @@ -113,7 +113,7 @@ void qemu_cond_wait(QemuCond *cond, QemuMutex *mutex) err = pthread_cond_wait(&cond->cond, &mutex->lock); if (err) - error_exit(err, __func__); + qemu_error_exit(err, __func__); } /* Returns true if condition was signals, false if timed out. */ @@ -133,7 +133,7 @@ bool qemu_cond_timedwait(QemuCond *cond, QemuMutex *mutex, } err = pthread_cond_timedwait(&cond->cond, &mutex->lock, &ts); if (err && err != ETIMEDOUT) { - error_exit(err, __func__); + qemu_error_exit(err, __func__); } return err == 0; } @@ -148,12 +148,12 @@ void qemu_thread_create(QemuThread *thread, err = pthread_attr_init(&attr); if (err) { - error_exit(err, __func__); + qemu_error_exit(err, __func__); } if (mode == QEMU_THREAD_DETACHED) { err = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); if (err) { - error_exit(err, __func__); + qemu_error_exit(err, __func__); } } @@ -162,7 +162,7 @@ void qemu_thread_create(QemuThread *thread, pthread_sigmask(SIG_SETMASK, &set, &oldset); err = pthread_create(&thread->thread, &attr, start_routine, arg); if (err) - error_exit(err, __func__); + qemu_error_exit(err, __func__); pthread_sigmask(SIG_SETMASK, &oldset, NULL); @@ -191,7 +191,7 @@ void *qemu_thread_join(QemuThread *thread) err = pthread_join(thread->thread, &ret); if (err) { - error_exit(err, __func__); + qemu_error_exit(err, __func__); } return ret; } diff --git a/qemu-thread-win32.c b/qemu-thread-win32.c index 3524c8b..01664fb 100644 --- a/qemu-thread-win32.c +++ b/qemu-thread-win32.c @@ -16,7 +16,7 @@ #include #include -static void error_exit(int err, const char *msg) +void qemu_error_exit(int err, const char *msg) { char *pstr; @@ -75,14 +75,14 @@ void qemu_cond_init(QemuCond *cond) cond->sema = CreateSemaphore(NULL, 0, LONG_MAX, NULL); if (!cond->sema) { - error_exit(GetLastError(), __func__); + qemu_error_exit(GetLastError(), __func__); } cond->continue_event = CreateEvent(NULL, /* security */ FALSE, /* auto-reset */ FALSE, /* not signaled */ NULL); /* name */ if (!cond->continue_event) { - error_exit(GetLastError(), __func__); + qemu_error_exit(GetLastError(), __func__); } } @@ -91,12 +91,12 @@ void qemu_cond_destroy(QemuCond *cond) BOOL result; result = CloseHandle(cond->continue_event); if (!result) { - error_exit(GetLastError(), __func__); + qemu_error_exit(GetLastError(), __func__); } cond->continue_event = 0; result = CloseHandle(cond->sema); if (!result) { - error_exit(GetLastError(), __func__); + qemu_error_exit(GetLastError(), __func__); } cond->sema = 0; } @@ -124,7 +124,7 @@ void qemu_cond_signal(QemuCond *cond) result = SignalObjectAndWait(cond->sema, cond->continue_event, INFINITE, FALSE); if (result == WAIT_ABANDONED || result == WAIT_FAILED) { - error_exit(GetLastError(), __func__); + qemu_error_exit(GetLastError(), __func__); } } @@ -142,7 +142,7 @@ void qemu_cond_broadcast(QemuCond *cond) cond->target = 0; result = ReleaseSemaphore(cond->sema, cond->waiters, NULL); if (!result) { - error_exit(GetLastError(), __func__); + qemu_error_exit(GetLastError(), __func__); } /* @@ -268,7 +268,7 @@ static inline void qemu_thread_init(void) if (qemu_thread_tls_index == TLS_OUT_OF_INDEXES) { qemu_thread_tls_index = TlsAlloc(); if (qemu_thread_tls_index == TLS_OUT_OF_INDEXES) { - error_exit(ERROR_NO_SYSTEM_RESOURCES, __func__); + qemu_error_exit(ERROR_NO_SYSTEM_RESOURCES, __func__); } } } @@ -295,7 +295,7 @@ void qemu_thread_create(QemuThread *thread, hThread = (HANDLE) _beginthreadex(NULL, 0, win32_start_routine, data, 0, &thread->tid); if (!hThread) { - error_exit(GetLastError(), __func__); + qemu_error_exit(GetLastError(), __func__); } CloseHandle(hThread); thread->data = (mode == QEMU_THREAD_DETACHED) ? NULL : data; diff --git a/qemu-thread.h b/qemu-thread.h index a78a8f2..10f2c51 100644 --- a/qemu-thread.h +++ b/qemu-thread.h @@ -45,4 +45,6 @@ void qemu_thread_get_self(QemuThread *thread); int qemu_thread_is_self(QemuThread *thread); void qemu_thread_exit(void *retval); +/* internal helper */ +void qemu_error_exit(int err, const char *msg); #endif