fix(win32): detect CreateThread failure and pass correct handle to SetThreadPriority

Previously, osal_thread_create checked the wrong handle value, so thread
creation failures were reported as success.

Also, osal_thread_create_rt passed the handle pointer instead of the thread
HANDLE to SetThreadPriority, so real-time priority was never applied.

Fixes #977
This commit is contained in:
Eksan0325
2026-06-12 13:51:04 +02:00
committed by Hans-Erik Floryd
parent 7a8011bb28
commit 2f73eaa803
2 changed files with 8 additions and 3 deletions
+1
View File
@@ -5,3 +5,4 @@ install
/doc/html
tags
.vscode
.vs
+7 -3
View File
@@ -132,8 +132,10 @@ void osal_free(void *ptr)
int osal_thread_create(void *thandle, int stacksize, void *func, void *param)
{
*(OSAL_THREAD_HANDLE *)thandle = CreateThread(NULL, stacksize, func, param, 0, NULL);
if (!thandle)
HANDLE thread;
thread = CreateThread(NULL, (SIZE_T)stacksize, (LPTHREAD_START_ROUTINE)func, param, 0, NULL);
*(OSAL_THREAD_HANDLE*)thandle = thread;
if (thread == NULL)
{
return 0;
}
@@ -142,11 +144,13 @@ int osal_thread_create(void *thandle, int stacksize, void *func, void *param)
int osal_thread_create_rt(void *thandle, int stacksize, void *func, void *param)
{
HANDLE thread;
int ret;
ret = osal_thread_create(thandle, stacksize, func, param);
if (ret)
{
ret = SetThreadPriority(thandle, THREAD_PRIORITY_TIME_CRITICAL);
thread = *(OSAL_THREAD_HANDLE*)thandle;
ret = SetThreadPriority(thread, THREAD_PRIORITY_TIME_CRITICAL);
}
return ret;
}