From 0d699208d37edc8b29cebcf9ce779f897b371c06 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Tue, 9 Oct 2018 03:55:34 +0200 Subject: [PATCH] Update rthreads --- libretro-common/rthreads/rthreads.c | 17 ++++++++++++-- libretro-common/rthreads/switch_pthread.h | 27 +++++++++++------------ 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/libretro-common/rthreads/rthreads.c b/libretro-common/rthreads/rthreads.c index ec3ff012bd..5d651dd003 100644 --- a/libretro-common/rthreads/rthreads.c +++ b/libretro-common/rthreads/rthreads.c @@ -27,6 +27,7 @@ #endif #include +#include #include #include @@ -164,6 +165,11 @@ sthread_t *sthread_create(void (*thread_func)(void*), void *userdata) return sthread_create_with_priority(thread_func, userdata, 0); } +/* TODO/FIXME - this needs to be implemented for Switch */ +#if !defined(SWITCH) && !defined(USE_WIN32_THREADS) +#define HAVE_THREAD_ATTR +#endif + /** * sthread_create_with_priority: * @start_routine : thread entry callback function @@ -181,11 +187,11 @@ sthread_t *sthread_create(void (*thread_func)(void*), void *userdata) */ sthread_t *sthread_create_with_priority(void (*thread_func)(void*), void *userdata, int thread_priority) { -#ifndef USE_WIN32_THREADS +#ifdef HAVE_THREAD_ATTR pthread_attr_t thread_attr; + bool thread_attr_needed = false; #endif bool thread_created = false; - bool thread_attr_needed = false; struct thread_data *data = NULL; sthread_t *thread = (sthread_t*)calloc(1, sizeof(*thread)); @@ -203,6 +209,8 @@ sthread_t *sthread_create_with_priority(void (*thread_func)(void*), void *userda thread->thread = CreateThread(NULL, 0, thread_wrap, data, 0, &thread->id); thread_created = !!thread->thread; #else + +#ifdef HAVE_THREAD_ATTR pthread_attr_init(&thread_attr); if ( (thread_priority >= 1) && (thread_priority <= 100) ) @@ -215,18 +223,23 @@ sthread_t *sthread_create_with_priority(void (*thread_func)(void*), void *userda thread_attr_needed = true; } +#endif #if defined(VITA) pthread_attr_setstacksize(&thread_attr , 0x10000 ); thread_attr_needed = true; #endif +#ifdef HAVE_THREAD_ATTR if (thread_attr_needed) thread_created = pthread_create(&thread->id, &thread_attr, thread_wrap, data) == 0; else +#endif thread_created = pthread_create(&thread->id, NULL, thread_wrap, data) == 0; +#ifdef HAVE_THREAD_ATTR pthread_attr_destroy(&thread_attr); +#endif #endif if (thread_created) diff --git a/libretro-common/rthreads/switch_pthread.h b/libretro-common/rthreads/switch_pthread.h index a9ea9be1a3..0fa582b299 100644 --- a/libretro-common/rthreads/switch_pthread.h +++ b/libretro-common/rthreads/switch_pthread.h @@ -28,30 +28,29 @@ #include #include -#include "../include/retro_inline.h" -#include "../../verbosity.h" +#include -#define THREADVARS_MAGIC 0x21545624 // !TV$ +#define THREADVARS_MAGIC 0x21545624 /* !TV$ */ int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg); void pthread_exit(void *retval); -// This structure is exactly 0x20 bytes, if more is needed modify getThreadVars() below +/* This structure is exactly 0x20 bytes, if more is needed modify getThreadVars() below */ typedef struct { - // Magic value used to check if the struct is initialized + /* Magic value used to check if the struct is initialized */ u32 magic; - // Thread handle, for mutexes + /* Thread handle, for mutexes */ Handle handle; - // Pointer to the current thread (if exists) + /* Pointer to the current thread (if exists) */ Thread *thread_ptr; - // Pointer to this thread's newlib state + /* Pointer to this thread's newlib state */ struct _reent *reent; - // Pointer to this thread's thread-local segment - void *tls_tp; // !! Offset needs to be TLS+0x1F8 for __aarch64_read_tp !! + /* Pointer to this thread's thread-local segment */ + void *tls_tp; /* !! Offset needs to be TLS+0x1F8 for __aarch64_read_tp !! */ } ThreadVars; static INLINE ThreadVars *getThreadVars(void) @@ -77,9 +76,9 @@ static INLINE int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutex return 0; } -INLINE int pthread_mutex_destroy(pthread_mutex_t *mutex) +static INLINE int pthread_mutex_destroy(pthread_mutex_t *mutex) { - // Nothing + /* Nothing */ *mutex = 0; return 0; @@ -101,7 +100,7 @@ static INLINE int pthread_mutex_unlock(pthread_mutex_t *mutex) INLINE int pthread_detach(pthread_t thread) { (void)thread; - // Nothing for now + /* Nothing for now */ return 0; } @@ -154,7 +153,7 @@ static INLINE int pthread_cond_broadcast(pthread_cond_t *cond) INLINE int pthread_cond_destroy(pthread_cond_t *cond) { - // Nothing + /* Nothing */ return 0; }