|
|
@@ -482,7 +482,7 @@ HANDLE CreateThread(LPSECURITY_ATTRIBUTES lpThreadAttributes, SIZE_T dwStackSize
|
|
|
|
|
|
WINPR_HANDLE_SET_TYPE_AND_MODE(thread, HANDLE_TYPE_THREAD, WINPR_FD_READ);
|
|
|
handle = (HANDLE)thread;
|
|
|
-
|
|
|
+ assert(handle != THREAD_CUR_ONE_HANDLE);
|
|
|
if (!thread_list)
|
|
|
{
|
|
|
thread_list = ListDictionary_New(TRUE);
|
|
|
@@ -624,10 +624,9 @@ VOID ExitThread(DWORD dwExitCode)
|
|
|
{
|
|
|
DWORD rc;
|
|
|
pthread_t tid = pthread_self();
|
|
|
-
|
|
|
if (!thread_list)
|
|
|
{
|
|
|
- WLog_ERR(TAG, "function called without existing thread list!");
|
|
|
+ WLog_ERR(TAG, "%s called without existing thread list!", __FUNCTION__);
|
|
|
#if defined(WITH_DEBUG_THREADS)
|
|
|
DumpThreadHandles();
|
|
|
#endif
|
|
|
@@ -679,12 +678,11 @@ BOOL GetExitCodeThread(HANDLE hThread, LPDWORD lpExitCode)
|
|
|
|
|
|
HANDLE _GetCurrentThread(VOID)
|
|
|
{
|
|
|
- HANDLE hdl = NULL;
|
|
|
+ HANDLE hdl = THREAD_CUR_ONE_HANDLE;
|
|
|
pthread_t tid = pthread_self();
|
|
|
-
|
|
|
if (!thread_list)
|
|
|
{
|
|
|
- WLog_ERR(TAG, "function called without existing thread list!");
|
|
|
+ WLog_ERR(TAG, "%s called without existing thread list!", __FUNCTION__);
|
|
|
#if defined(WITH_DEBUG_THREADS)
|
|
|
DumpThreadHandles();
|
|
|
#endif
|
|
|
@@ -700,7 +698,6 @@ HANDLE _GetCurrentThread(VOID)
|
|
|
{
|
|
|
hdl = ListDictionary_GetItemValue(thread_list, &tid);
|
|
|
}
|
|
|
-
|
|
|
return hdl;
|
|
|
}
|
|
|
|
|
|
@@ -804,7 +801,7 @@ HANDLE OpenThread(DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwThreadId)
|
|
|
}
|
|
|
if (!thread_list)
|
|
|
{
|
|
|
- WLog_ERR(TAG, "function called without existing thread list!");
|
|
|
+ WLog_ERR(TAG, "%s called without existing thread list!", __FUNCTION__);
|
|
|
#if defined(WITH_DEBUG_THREADS)
|
|
|
DumpThreadHandles();
|
|
|
#endif
|
|
|
@@ -830,19 +827,29 @@ BOOL SetThreadPriority(HANDLE hThread, int nPriority)
|
|
|
BOOL result = TRUE;
|
|
|
ULONG Type;
|
|
|
WINPR_HANDLE* Object;
|
|
|
- WINPR_THREAD* thread;
|
|
|
+ WINPR_THREAD* thread = NULL;
|
|
|
struct sched_param param;
|
|
|
pthread_attr_t attr;
|
|
|
+ pthread_t cur_thread;
|
|
|
int policy = 0;
|
|
|
int max_prio_for_policy = 0;
|
|
|
int min_prio_for_policy = 0;
|
|
|
int ret = 0;
|
|
|
if (!winpr_Handle_GetInfo(hThread, &Type, &Object))
|
|
|
{
|
|
|
- WLog_ERR(TAG, "get thread handle information failed!");
|
|
|
- return FALSE;
|
|
|
+ if (hThread == THREAD_CUR_ONE_HANDLE) {
|
|
|
+ WLog_DBG(TAG, "current thread flag.");
|
|
|
+ cur_thread = pthread_self();
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ WLog_ERR(TAG, "get thread handle information failed!");
|
|
|
+ return FALSE;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ thread = (WINPR_THREAD*)Object;
|
|
|
+ cur_thread = thread->thread;
|
|
|
}
|
|
|
- thread = (WINPR_THREAD*)Object;
|
|
|
|
|
|
#if 0
|
|
|
/*https://pubs.opengroup.org/onlinepubs/009695399/functions/pthread_setschedprio.html*/
|
|
|
@@ -853,14 +860,14 @@ BOOL SetThreadPriority(HANDLE hThread, int nPriority)
|
|
|
/*
|
|
|
* set the scheduling priority for the thread to prio
|
|
|
*/
|
|
|
- if(0 != pthread_setschedprio(thread->thread, max_prio_for_policy)) {
|
|
|
+ if(0 != pthread_setschedprio(cur_thread, max_prio_for_policy)) {
|
|
|
result = FALSE;
|
|
|
}
|
|
|
}
|
|
|
pthread_attr_destroy(&attr);
|
|
|
#else
|
|
|
/*it might be preferable conceptually to solve this problem.*/
|
|
|
- ret = pthread_getschedparam(thread->thread, &policy, ¶m);
|
|
|
+ ret = pthread_getschedparam(cur_thread, &policy, ¶m);
|
|
|
if(0 != ret)
|
|
|
{
|
|
|
WLog_ERR(TAG, "get thread schedule param failed, err: %d", ret);
|
|
|
@@ -894,7 +901,7 @@ BOOL SetThreadPriority(HANDLE hThread, int nPriority)
|
|
|
* the caller does not have appropriate permission to set either the scheduling
|
|
|
* parameters or the scheduling policy of the specified thread.
|
|
|
*/
|
|
|
- ret = pthread_setschedparam(thread->thread, policy, ¶m);
|
|
|
+ ret = pthread_setschedparam(cur_thread, policy, ¶m);
|
|
|
if (0 != ret) {
|
|
|
WLog_ERR(TAG, "set scheduled param failed! policy: %d, priority: %d, err: %d",
|
|
|
policy, param.sched_priority, ret);
|