Will be used in another wrapper module soon. Signed-off-by: Jan Kiszka <jan.kis...@siemens.com> --- 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 <sys/time.h> #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 <assert.h> #include <limits.h> -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 -- 1.7.3.4