diff --git a/libretro-common/include/rthreads/rthreads.h b/libretro-common/include/rthreads/rthreads.h index 946c3492b5..d0bafe53e8 100644 --- a/libretro-common/include/rthreads/rthreads.h +++ b/libretro-common/include/rthreads/rthreads.h @@ -245,11 +245,25 @@ void *sthread_tls_get(sthread_tls_t *tls); /** * @brief Binds thread specific data to a key * @param tls - * @return whether the operation suceeded or not + * @return Whether the operation suceeded or not */ bool sthread_tls_set(sthread_tls_t *tls, const void *data); #endif +/* + * @brief Get thread ID of specified thread + * @param thread + * @return The ID of the specified thread + */ +uintptr_t sthread_get_thread_id(sthread_t *thread); + +/* + * @brief Get thread ID of the current thread + * @param thread + * @return The ID of the current thread + */ +uintptr_t sthread_get_current_thread_id(sthread_t *thread); + RETRO_END_DECLS #endif diff --git a/libretro-common/rthreads/rthreads.c b/libretro-common/rthreads/rthreads.c index bfeb5a5dff..8d164adaa3 100644 --- a/libretro-common/rthreads/rthreads.c +++ b/libretro-common/rthreads/rthreads.c @@ -940,3 +940,19 @@ bool sthread_tls_set(sthread_tls_t *tls, const void *data) #endif } #endif + +uintptr_t sthread_get_thread_id(sthread_t *thread) +{ + if (!thread) + return 0; + return (uintptr_t)thread->id; +} + +uintptr_t sthread_get_current_thread_id(sthread_t *thread) +{ +#ifdef USE_WIN32_THREADS + return (uintptr_t)GetCurrentThreadId(); +#else + return (uintptr_t)pthread_self(); +#endif +}