Implement sthread_get_thread_id (functional equivalent for

SDL_GetThreadId) and sthread_get_current_thread_id (functional
equivalent
for SDL_ThreadID)
This commit is contained in:
twinaphex 2019-10-20 23:55:19 +02:00
parent d51b32f662
commit e968dd85e2
2 changed files with 31 additions and 1 deletions

View File

@ -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

View File

@ -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
}