2012-09-18 03:17:19 +04:00
|
|
|
/**
|
|
|
|
* WinPR: Windows Portable Runtime
|
|
|
|
* Process Thread Functions
|
|
|
|
*
|
|
|
|
* Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
2015-05-27 19:24:56 +03:00
|
|
|
* Copyright 2015 Hewlett-Packard Development Company, L.P.
|
2012-09-18 03:17:19 +04:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2014-07-14 21:36:31 +04:00
|
|
|
#include <assert.h>
|
|
|
|
|
2012-09-18 20:57:19 +04:00
|
|
|
#include <winpr/handle.h>
|
|
|
|
|
2012-09-18 03:17:19 +04:00
|
|
|
#include <winpr/thread.h>
|
|
|
|
|
|
|
|
/**
|
|
|
|
* api-ms-win-core-processthreads-l1-1-1.dll
|
2014-07-15 13:11:59 +04:00
|
|
|
*
|
2012-09-18 03:17:19 +04:00
|
|
|
* CreateRemoteThread
|
|
|
|
* CreateRemoteThreadEx
|
|
|
|
* CreateThread
|
|
|
|
* DeleteProcThreadAttributeList
|
|
|
|
* ExitThread
|
|
|
|
* FlushInstructionCache
|
|
|
|
* FlushProcessWriteBuffers
|
|
|
|
* GetCurrentThread
|
|
|
|
* GetCurrentThreadId
|
|
|
|
* GetCurrentThreadStackLimits
|
|
|
|
* GetExitCodeThread
|
|
|
|
* GetPriorityClass
|
|
|
|
* GetStartupInfoW
|
|
|
|
* GetThreadContext
|
|
|
|
* GetThreadId
|
|
|
|
* GetThreadIdealProcessorEx
|
|
|
|
* GetThreadPriority
|
|
|
|
* GetThreadPriorityBoost
|
|
|
|
* GetThreadTimes
|
|
|
|
* InitializeProcThreadAttributeList
|
|
|
|
* OpenThread
|
|
|
|
* OpenThreadToken
|
|
|
|
* QueryProcessAffinityUpdateMode
|
|
|
|
* QueueUserAPC
|
|
|
|
* ResumeThread
|
|
|
|
* SetPriorityClass
|
|
|
|
* SetThreadContext
|
|
|
|
* SetThreadPriority
|
|
|
|
* SetThreadPriorityBoost
|
|
|
|
* SetThreadStackGuarantee
|
|
|
|
* SetThreadToken
|
|
|
|
* SuspendThread
|
|
|
|
* SwitchToThread
|
|
|
|
* TerminateThread
|
|
|
|
* UpdateProcThreadAttribute
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _WIN32
|
|
|
|
|
2012-09-23 21:54:14 +04:00
|
|
|
#include <winpr/crt.h>
|
2014-05-11 13:23:30 +04:00
|
|
|
#include <winpr/platform.h>
|
|
|
|
|
2014-07-14 21:36:31 +04:00
|
|
|
#ifdef HAVE_UNISTD_H
|
2014-05-11 13:23:30 +04:00
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
2012-09-23 21:54:14 +04:00
|
|
|
|
2014-07-14 21:36:31 +04:00
|
|
|
#ifdef HAVE_EVENTFD_H
|
|
|
|
#include <sys/eventfd.h>
|
|
|
|
#endif
|
|
|
|
|
2014-10-27 13:39:02 +03:00
|
|
|
#include <winpr/debug.h>
|
2014-07-14 21:36:31 +04:00
|
|
|
|
|
|
|
#include <errno.h>
|
2014-11-20 19:48:02 +03:00
|
|
|
#include <fcntl.h>
|
2014-07-14 21:36:31 +04:00
|
|
|
|
|
|
|
#include <winpr/collections.h>
|
|
|
|
|
2012-12-13 07:03:40 +04:00
|
|
|
#include "thread.h"
|
2012-09-18 03:17:19 +04:00
|
|
|
|
2013-05-17 01:32:58 +04:00
|
|
|
#include "../handle/handle.h"
|
2014-10-27 13:45:39 +03:00
|
|
|
#include "../log.h"
|
|
|
|
#define TAG WINPR_TAG("thread")
|
2013-05-17 01:32:58 +04:00
|
|
|
|
2014-11-20 19:48:02 +03:00
|
|
|
static wListDictionary* thread_list = NULL;
|
2014-07-14 21:36:31 +04:00
|
|
|
|
|
|
|
static BOOL ThreadCloseHandle(HANDLE handle);
|
2014-11-20 19:48:02 +03:00
|
|
|
static void cleanup_handle(void* obj);
|
2014-07-14 21:36:31 +04:00
|
|
|
|
|
|
|
static BOOL ThreadIsHandled(HANDLE handle)
|
|
|
|
{
|
2014-11-20 19:48:02 +03:00
|
|
|
WINPR_THREAD* pThread = (WINPR_THREAD*) handle;
|
2014-07-14 21:36:31 +04:00
|
|
|
|
2015-03-24 11:18:06 +03:00
|
|
|
if (!pThread || (pThread->Type != HANDLE_TYPE_THREAD))
|
2014-07-14 21:36:31 +04:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_HANDLE);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-03-11 19:57:01 +03:00
|
|
|
static int ThreadGetFd(HANDLE handle)
|
2014-07-14 21:36:31 +04:00
|
|
|
{
|
2015-03-11 19:57:01 +03:00
|
|
|
WINPR_THREAD* pThread = (WINPR_THREAD*) handle;
|
|
|
|
|
|
|
|
if (!ThreadIsHandled(handle))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return pThread->pipe_fd[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
static DWORD ThreadCleanupHandle(HANDLE handle)
|
|
|
|
{
|
|
|
|
WINPR_THREAD* thread = (WINPR_THREAD*) handle;
|
|
|
|
|
|
|
|
if (!ThreadIsHandled(handle))
|
|
|
|
return WAIT_FAILED;
|
|
|
|
|
2015-07-16 14:48:14 +03:00
|
|
|
if (pthread_mutex_lock(&thread->mutex))
|
|
|
|
return WAIT_FAILED;
|
2015-03-11 19:57:01 +03:00
|
|
|
|
|
|
|
if (!thread->joined)
|
|
|
|
{
|
|
|
|
int status;
|
|
|
|
status = pthread_join(thread->thread, NULL);
|
|
|
|
|
|
|
|
if (status != 0)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "pthread_join failure: [%d] %s",
|
|
|
|
status, strerror(status));
|
|
|
|
pthread_mutex_unlock(&thread->mutex);
|
|
|
|
return WAIT_FAILED;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
thread->joined = TRUE;
|
|
|
|
}
|
|
|
|
|
2015-07-16 14:48:14 +03:00
|
|
|
if (pthread_mutex_unlock(&thread->mutex))
|
|
|
|
return WAIT_FAILED;
|
2015-03-11 19:57:01 +03:00
|
|
|
|
|
|
|
return WAIT_OBJECT_0;
|
2014-07-14 21:36:31 +04:00
|
|
|
}
|
|
|
|
|
2015-03-16 02:29:37 +03:00
|
|
|
static HANDLE_OPS ops = {
|
|
|
|
ThreadIsHandled,
|
|
|
|
ThreadCloseHandle,
|
|
|
|
ThreadGetFd,
|
|
|
|
ThreadCleanupHandle
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-10-27 13:39:02 +03:00
|
|
|
static void dump_thread(WINPR_THREAD* thread)
|
2014-07-14 21:36:31 +04:00
|
|
|
{
|
2014-10-27 13:39:02 +03:00
|
|
|
#if defined(WITH_DEBUG_THREADS)
|
|
|
|
void* stack = winpr_backtrace(20);
|
|
|
|
char** msg;
|
|
|
|
size_t used, i;
|
|
|
|
WLog_DBG(TAG, "Called from:");
|
|
|
|
msg = winpr_backtrace_symbols(stack, &used);
|
|
|
|
|
2014-11-20 19:48:02 +03:00
|
|
|
for (i = 0; i < used; i++)
|
2014-10-27 13:39:02 +03:00
|
|
|
WLog_DBG(TAG, "[%d]: %s", i, msg[i]);
|
|
|
|
|
|
|
|
free(msg);
|
|
|
|
winpr_backtrace_free(stack);
|
|
|
|
WLog_DBG(TAG, "Thread handle created still not closed!");
|
|
|
|
msg = winpr_backtrace_symbols(thread->create_stack, &used);
|
|
|
|
|
2014-11-20 19:48:02 +03:00
|
|
|
for (i = 0; i < used; i++)
|
2014-10-27 13:39:02 +03:00
|
|
|
WLog_DBG(TAG, "[%d]: %s", i, msg[i]);
|
|
|
|
|
|
|
|
free(msg);
|
2014-07-14 21:36:31 +04:00
|
|
|
|
|
|
|
if (thread->started)
|
2014-11-20 19:48:02 +03:00
|
|
|
{
|
2014-10-27 13:39:02 +03:00
|
|
|
WLog_DBG(TAG, "Thread still running!");
|
2014-11-20 19:48:02 +03:00
|
|
|
}
|
2014-07-14 21:36:31 +04:00
|
|
|
else if (!thread->exit_stack)
|
2014-11-20 19:48:02 +03:00
|
|
|
{
|
2014-10-27 13:39:02 +03:00
|
|
|
WLog_DBG(TAG, "Thread suspended.");
|
2014-11-20 19:48:02 +03:00
|
|
|
}
|
2014-07-14 21:36:31 +04:00
|
|
|
else
|
|
|
|
{
|
2014-10-27 13:39:02 +03:00
|
|
|
WLog_DBG(TAG, "Thread exited at:");
|
|
|
|
msg = winpr_backtrace_symbols(thread->exit_stack, &used);
|
|
|
|
|
2014-11-20 19:48:02 +03:00
|
|
|
for (i = 0; i < used; i++)
|
2014-10-27 13:39:02 +03:00
|
|
|
WLog_DBG(TAG, "[%d]: %s", i, msg[i]);
|
|
|
|
|
|
|
|
free(msg);
|
2014-07-14 21:36:31 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-09-20 05:42:46 +04:00
|
|
|
/**
|
|
|
|
* TODO: implement thread suspend/resume using pthreads
|
|
|
|
* http://stackoverflow.com/questions/3140867/suspend-pthreads-without-using-condition
|
|
|
|
*/
|
2014-07-14 21:36:31 +04:00
|
|
|
static BOOL set_event(WINPR_THREAD *thread)
|
|
|
|
{
|
|
|
|
int length;
|
|
|
|
BOOL status = FALSE;
|
|
|
|
#ifdef HAVE_EVENTFD_H
|
|
|
|
eventfd_t val = 1;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
length = eventfd_write(thread->pipe_fd[0], val);
|
|
|
|
}
|
|
|
|
while ((length < 0) && (errno == EINTR));
|
|
|
|
|
|
|
|
status = (length == 0) ? TRUE : FALSE;
|
|
|
|
#else
|
|
|
|
if (WaitForSingleObject(thread, 0) != WAIT_OBJECT_0)
|
|
|
|
{
|
|
|
|
length = write(thread->pipe_fd[1], "-", 1);
|
|
|
|
|
|
|
|
if (length == 1)
|
|
|
|
status = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
status = TRUE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL reset_event(WINPR_THREAD *thread)
|
|
|
|
{
|
|
|
|
int length;
|
|
|
|
BOOL status = FALSE;
|
|
|
|
#ifdef HAVE_EVENTFD_H
|
2014-07-16 11:56:30 +04:00
|
|
|
eventfd_t value;
|
2014-07-14 21:36:31 +04:00
|
|
|
|
2014-07-16 11:56:30 +04:00
|
|
|
do
|
|
|
|
{
|
|
|
|
length = eventfd_read(thread->pipe_fd[0], &value);
|
|
|
|
}
|
|
|
|
while ((length < 0) && (errno == EINTR));
|
2014-07-14 21:36:31 +04:00
|
|
|
|
2014-07-16 11:56:30 +04:00
|
|
|
if ((length > 0) && (!status))
|
|
|
|
status = TRUE;
|
2014-07-14 21:36:31 +04:00
|
|
|
|
|
|
|
#else
|
2014-07-16 11:56:30 +04:00
|
|
|
length = read(thread->pipe_fd[0], &length, 1);
|
2014-07-14 21:36:31 +04:00
|
|
|
|
2014-07-16 11:56:30 +04:00
|
|
|
if ((length == 1) && (!status))
|
|
|
|
status = TRUE;
|
2014-07-14 21:36:31 +04:00
|
|
|
|
|
|
|
#endif
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2014-11-20 19:48:02 +03:00
|
|
|
static BOOL thread_compare(void* a, void* b)
|
2014-07-14 21:36:31 +04:00
|
|
|
{
|
2014-11-20 19:48:02 +03:00
|
|
|
pthread_t* p1 = a;
|
|
|
|
pthread_t* p2 = b;
|
|
|
|
BOOL rc = pthread_equal(*p1, *p2);
|
2014-07-14 21:36:31 +04:00
|
|
|
return rc;
|
|
|
|
}
|
2012-09-20 05:42:46 +04:00
|
|
|
|
2014-07-15 13:11:59 +04:00
|
|
|
/* Thread launcher function responsible for registering
|
|
|
|
* cleanup handlers and calling pthread_exit, if not done
|
|
|
|
* in thread function. */
|
2014-11-20 19:48:02 +03:00
|
|
|
static void* thread_launcher(void* arg)
|
2012-09-23 21:54:14 +04:00
|
|
|
{
|
2014-11-16 18:51:04 +03:00
|
|
|
DWORD res = -1;
|
2014-11-20 19:48:02 +03:00
|
|
|
void* rc = NULL;
|
|
|
|
WINPR_THREAD* thread = (WINPR_THREAD*) arg;
|
2015-07-23 12:52:24 +03:00
|
|
|
void *(*fkt)(void*);
|
2014-07-15 13:11:59 +04:00
|
|
|
|
|
|
|
if (!thread)
|
|
|
|
{
|
2014-10-27 13:39:02 +03:00
|
|
|
WLog_ERR(TAG, "Called with invalid argument %p", arg);
|
2014-07-15 13:11:59 +04:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
2015-07-23 12:52:24 +03:00
|
|
|
if (!(fkt = (void*) thread->lpStartAddress))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Thread function argument is %p", fkt);
|
|
|
|
goto exit;
|
|
|
|
}
|
2014-07-15 13:11:59 +04:00
|
|
|
|
2015-07-23 12:52:24 +03:00
|
|
|
if (pthread_mutex_lock(&thread->threadIsReadyMutex))
|
|
|
|
goto exit;
|
2015-07-16 14:48:14 +03:00
|
|
|
|
2015-07-23 12:52:24 +03:00
|
|
|
if (!ListDictionary_Contains(thread_list, &thread->thread))
|
|
|
|
{
|
|
|
|
if (pthread_cond_wait(&thread->threadIsReady, &thread->threadIsReadyMutex) != 0)
|
2015-05-27 19:15:17 +03:00
|
|
|
{
|
2015-07-23 12:52:24 +03:00
|
|
|
WLog_ERR(TAG, "The thread could not be made ready");
|
|
|
|
pthread_mutex_unlock(&thread->threadIsReadyMutex);
|
2015-07-16 14:48:14 +03:00
|
|
|
goto exit;
|
2015-07-23 12:52:24 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (pthread_mutex_unlock(&thread->threadIsReadyMutex))
|
|
|
|
goto exit;
|
2015-05-26 18:40:34 +03:00
|
|
|
|
2015-07-23 12:52:24 +03:00
|
|
|
assert(ListDictionary_Contains(thread_list, &thread->thread));
|
2015-05-26 18:40:34 +03:00
|
|
|
|
2015-07-23 12:52:24 +03:00
|
|
|
rc = fkt(thread->lpParameter);
|
2014-07-15 13:11:59 +04:00
|
|
|
|
|
|
|
exit:
|
2014-07-16 11:40:59 +04:00
|
|
|
|
2014-11-16 18:51:04 +03:00
|
|
|
if (thread)
|
|
|
|
{
|
|
|
|
if (!thread->exited)
|
|
|
|
thread->dwExitCode = (DWORD)(size_t)rc;
|
2014-07-16 11:40:59 +04:00
|
|
|
|
2014-11-16 18:51:04 +03:00
|
|
|
set_event(thread);
|
2014-07-15 13:11:59 +04:00
|
|
|
|
2014-11-16 18:51:04 +03:00
|
|
|
res = thread->dwExitCode;
|
|
|
|
if (thread->detached || !thread->started)
|
|
|
|
cleanup_handle(thread);
|
|
|
|
}
|
2014-07-15 13:11:59 +04:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2015-05-18 12:28:00 +03:00
|
|
|
static BOOL winpr_StartThread(WINPR_THREAD *thread)
|
2014-07-15 13:11:59 +04:00
|
|
|
{
|
|
|
|
pthread_attr_t attr;
|
2012-09-23 21:54:14 +04:00
|
|
|
pthread_attr_init(&attr);
|
2013-01-23 01:19:32 +04:00
|
|
|
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
|
2012-09-23 21:54:14 +04:00
|
|
|
|
|
|
|
if (thread->dwStackSize > 0)
|
|
|
|
pthread_attr_setstacksize(&attr, (size_t) thread->dwStackSize);
|
|
|
|
|
2015-01-16 13:26:31 +03:00
|
|
|
thread->started = TRUE;
|
2014-07-14 21:36:31 +04:00
|
|
|
reset_event(thread);
|
2015-01-16 13:26:31 +03:00
|
|
|
|
2015-05-18 12:28:00 +03:00
|
|
|
if (pthread_create(&thread->thread, &attr, thread_launcher, thread))
|
|
|
|
goto error;
|
2015-05-26 18:40:34 +03:00
|
|
|
|
2015-05-27 19:15:17 +03:00
|
|
|
|
2015-07-16 14:48:14 +03:00
|
|
|
if (pthread_mutex_lock(&thread->threadIsReadyMutex))
|
|
|
|
goto error;
|
|
|
|
|
2015-05-27 19:15:17 +03:00
|
|
|
if (!ListDictionary_Add(thread_list, &thread->thread, thread))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "failed to add the thread to the thread list");
|
2015-07-16 14:48:14 +03:00
|
|
|
pthread_mutex_unlock(&thread->threadIsReadyMutex);
|
2015-05-27 19:15:17 +03:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
if (pthread_cond_signal(&thread->threadIsReady) != 0)
|
2015-05-26 18:40:34 +03:00
|
|
|
{
|
2015-05-27 19:15:17 +03:00
|
|
|
WLog_ERR(TAG, "failed to signal the thread was ready");
|
|
|
|
pthread_mutex_unlock(&thread->threadIsReadyMutex);
|
2015-05-18 12:28:00 +03:00
|
|
|
goto error;
|
2015-05-26 18:40:34 +03:00
|
|
|
}
|
2015-07-16 14:48:14 +03:00
|
|
|
if (pthread_mutex_unlock(&thread->threadIsReadyMutex))
|
|
|
|
goto error;
|
2015-05-26 18:55:27 +03:00
|
|
|
|
2015-01-16 13:26:31 +03:00
|
|
|
pthread_attr_destroy(&attr);
|
2014-07-14 21:36:31 +04:00
|
|
|
dump_thread(thread);
|
2015-05-18 12:28:00 +03:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
error:
|
|
|
|
pthread_attr_destroy(&attr);
|
|
|
|
return FALSE;
|
2012-09-18 08:10:14 +04:00
|
|
|
}
|
|
|
|
|
2012-09-18 03:17:19 +04:00
|
|
|
HANDLE CreateThread(LPSECURITY_ATTRIBUTES lpThreadAttributes, SIZE_T dwStackSize,
|
2014-07-15 13:11:59 +04:00
|
|
|
LPTHREAD_START_ROUTINE lpStartAddress, LPVOID lpParameter, DWORD dwCreationFlags, LPDWORD lpThreadId)
|
2012-09-18 03:17:19 +04:00
|
|
|
{
|
2012-09-19 03:24:03 +04:00
|
|
|
HANDLE handle;
|
2014-11-20 19:48:02 +03:00
|
|
|
WINPR_THREAD* thread;
|
2014-11-21 23:12:49 +03:00
|
|
|
|
2014-11-20 19:48:02 +03:00
|
|
|
thread = (WINPR_THREAD*) calloc(1, sizeof(WINPR_THREAD));
|
2014-05-11 13:23:30 +04:00
|
|
|
|
2014-04-09 18:07:06 +04:00
|
|
|
if (!thread)
|
|
|
|
return NULL;
|
2012-09-20 05:42:46 +04:00
|
|
|
|
2012-09-23 21:54:14 +04:00
|
|
|
thread->dwStackSize = dwStackSize;
|
|
|
|
thread->lpParameter = lpParameter;
|
|
|
|
thread->lpStartAddress = lpStartAddress;
|
|
|
|
thread->lpThreadAttributes = lpThreadAttributes;
|
2015-03-16 02:29:37 +03:00
|
|
|
thread->ops = &ops;
|
2014-11-20 19:48:02 +03:00
|
|
|
|
2014-10-27 13:39:02 +03:00
|
|
|
#if defined(WITH_DEBUG_THREADS)
|
|
|
|
thread->create_stack = winpr_backtrace(20);
|
2014-07-14 21:36:31 +04:00
|
|
|
dump_thread(thread);
|
|
|
|
#endif
|
2015-05-18 12:28:00 +03:00
|
|
|
thread->pipe_fd[0] = -1;
|
|
|
|
thread->pipe_fd[1] = -1;
|
2014-11-20 19:48:02 +03:00
|
|
|
|
2014-07-14 21:36:31 +04:00
|
|
|
#ifdef HAVE_EVENTFD_H
|
|
|
|
thread->pipe_fd[0] = eventfd(0, EFD_NONBLOCK);
|
|
|
|
|
|
|
|
if (thread->pipe_fd[0] < 0)
|
|
|
|
{
|
2015-05-18 12:28:00 +03:00
|
|
|
WLog_ERR(TAG, "failed to create thread pipe fd 0");
|
|
|
|
goto error_pipefd0;
|
2014-07-14 21:36:31 +04:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
if (pipe(thread->pipe_fd) < 0)
|
|
|
|
{
|
2015-05-18 12:28:00 +03:00
|
|
|
WLog_ERR(TAG, "failed to create thread pipe");
|
|
|
|
goto error_pipefd0;
|
2014-07-14 21:36:31 +04:00
|
|
|
}
|
2014-11-20 19:48:02 +03:00
|
|
|
|
2014-11-21 23:12:49 +03:00
|
|
|
{
|
|
|
|
int flags = fcntl(thread->pipe_fd[0], F_GETFL);
|
|
|
|
fcntl(thread->pipe_fd[0], F_SETFL, flags | O_NONBLOCK);
|
|
|
|
}
|
2014-07-14 21:36:31 +04:00
|
|
|
#endif
|
2014-11-20 19:48:02 +03:00
|
|
|
|
2015-03-23 19:25:23 +03:00
|
|
|
if(pthread_mutex_init(&thread->mutex, 0) != 0)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "failed to initialize thread mutex");
|
2015-05-18 12:28:00 +03:00
|
|
|
goto error_mutex;
|
2015-03-23 19:25:23 +03:00
|
|
|
}
|
|
|
|
|
2015-05-27 19:15:17 +03:00
|
|
|
if (pthread_mutex_init(&thread->threadIsReadyMutex, NULL) != 0)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "failed to initialize a mutex for a condition variable");
|
|
|
|
goto error_thread_ready_mutex;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pthread_cond_init(&thread->threadIsReady, NULL) != 0)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "failed to initialize a condition variable");
|
|
|
|
goto error_thread_ready;
|
|
|
|
}
|
|
|
|
|
2015-07-14 12:39:41 +03:00
|
|
|
WINPR_HANDLE_SET_TYPE_AND_MODE(thread, HANDLE_TYPE_THREAD, WINPR_FD_READ);
|
2013-05-17 02:27:26 +04:00
|
|
|
handle = (HANDLE) thread;
|
2012-09-19 03:24:03 +04:00
|
|
|
|
2014-11-20 19:48:02 +03:00
|
|
|
if (!thread_list)
|
2014-07-14 21:36:31 +04:00
|
|
|
{
|
|
|
|
thread_list = ListDictionary_New(TRUE);
|
2015-03-23 19:25:23 +03:00
|
|
|
if (!thread_list)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Couldn't create global thread list");
|
2015-05-18 12:28:00 +03:00
|
|
|
goto error_thread_list;
|
2015-03-23 19:25:23 +03:00
|
|
|
}
|
2014-07-14 21:36:31 +04:00
|
|
|
thread_list->objectKey.fnObjectEquals = thread_compare;
|
|
|
|
}
|
|
|
|
|
2012-09-23 21:54:14 +04:00
|
|
|
if (!(dwCreationFlags & CREATE_SUSPENDED))
|
2015-05-18 12:28:00 +03:00
|
|
|
{
|
|
|
|
if (!winpr_StartThread(thread))
|
|
|
|
goto error_thread_list;
|
|
|
|
}
|
2014-07-14 21:36:31 +04:00
|
|
|
else
|
2015-05-18 12:28:00 +03:00
|
|
|
{
|
|
|
|
if (!set_event(thread))
|
|
|
|
goto error_thread_list;
|
|
|
|
}
|
2012-09-20 05:42:46 +04:00
|
|
|
|
2012-09-19 03:24:03 +04:00
|
|
|
return handle;
|
2015-05-18 12:28:00 +03:00
|
|
|
|
|
|
|
error_thread_list:
|
2015-05-27 19:15:17 +03:00
|
|
|
pthread_cond_destroy(&thread->threadIsReady);
|
|
|
|
error_thread_ready:
|
|
|
|
pthread_mutex_destroy(&thread->threadIsReadyMutex);
|
|
|
|
error_thread_ready_mutex:
|
2015-05-18 12:28:00 +03:00
|
|
|
pthread_mutex_destroy(&thread->mutex);
|
|
|
|
error_mutex:
|
|
|
|
if (thread->pipe_fd[1] >= 0)
|
|
|
|
close(thread->pipe_fd[1]);
|
|
|
|
if (thread->pipe_fd[0] >= 0)
|
|
|
|
close(thread->pipe_fd[0]);
|
|
|
|
error_pipefd0:
|
|
|
|
free(thread);
|
|
|
|
return NULL;
|
2012-09-18 03:17:19 +04:00
|
|
|
}
|
|
|
|
|
2014-07-15 13:11:59 +04:00
|
|
|
void cleanup_handle(void *obj)
|
2014-07-14 21:36:31 +04:00
|
|
|
{
|
2015-05-27 19:15:17 +03:00
|
|
|
int rc;
|
2014-11-20 19:48:02 +03:00
|
|
|
WINPR_THREAD* thread = (WINPR_THREAD*) obj;
|
2015-05-27 19:15:17 +03:00
|
|
|
|
2014-07-14 21:36:31 +04:00
|
|
|
|
2015-05-27 19:15:17 +03:00
|
|
|
rc = pthread_cond_destroy(&thread->threadIsReady);
|
2014-07-14 21:36:31 +04:00
|
|
|
if (rc)
|
2015-05-27 19:15:17 +03:00
|
|
|
WLog_ERR(TAG, "failed to destroy a condition variable [%d] %s (%d)",
|
2014-10-27 13:39:02 +03:00
|
|
|
rc, strerror(errno), errno);
|
2014-07-14 21:36:31 +04:00
|
|
|
|
2015-05-27 19:15:17 +03:00
|
|
|
rc = pthread_mutex_destroy(&thread->threadIsReadyMutex);
|
|
|
|
if (rc)
|
|
|
|
WLog_ERR(TAG, "failed to destroy a condition variable mutex [%d] %s (%d)",
|
|
|
|
rc, strerror(errno), errno);
|
|
|
|
|
|
|
|
rc = pthread_mutex_destroy(&thread->mutex);
|
|
|
|
if (rc)
|
|
|
|
WLog_ERR(TAG, "failed to destroy mutex [%d] %s (%d)",
|
|
|
|
rc, strerror(errno), errno);
|
2015-05-26 18:40:34 +03:00
|
|
|
|
2015-07-24 15:57:47 +03:00
|
|
|
if (thread->pipe_fd[0] >= 0)
|
2014-07-14 21:36:31 +04:00
|
|
|
close(thread->pipe_fd[0]);
|
|
|
|
|
2015-07-24 15:57:47 +03:00
|
|
|
if (thread->pipe_fd[1] >= 0)
|
2014-07-14 21:36:31 +04:00
|
|
|
close(thread->pipe_fd[1]);
|
|
|
|
|
2014-07-15 13:11:59 +04:00
|
|
|
if (thread_list && ListDictionary_Contains(thread_list, &thread->thread))
|
|
|
|
ListDictionary_Remove(thread_list, &thread->thread);
|
|
|
|
|
2014-10-27 13:39:02 +03:00
|
|
|
#if defined(WITH_DEBUG_THREADS)
|
|
|
|
|
|
|
|
if (thread->create_stack)
|
|
|
|
winpr_backtrace_free(thread->create_stack);
|
|
|
|
|
|
|
|
if (thread->exit_stack)
|
|
|
|
winpr_backtrace_free(thread->exit_stack);
|
|
|
|
|
|
|
|
#endif
|
2014-07-14 21:36:31 +04:00
|
|
|
free(thread);
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL ThreadCloseHandle(HANDLE handle)
|
|
|
|
{
|
2014-11-20 19:48:02 +03:00
|
|
|
WINPR_THREAD* thread = (WINPR_THREAD*) handle;
|
2014-07-14 21:36:31 +04:00
|
|
|
|
|
|
|
if (!thread_list)
|
|
|
|
{
|
2014-10-27 13:39:02 +03:00
|
|
|
WLog_ERR(TAG, "Thread list does not exist, check call!");
|
2014-07-14 21:36:31 +04:00
|
|
|
dump_thread(thread);
|
|
|
|
}
|
|
|
|
else if (!ListDictionary_Contains(thread_list, &thread->thread))
|
|
|
|
{
|
2014-10-27 13:39:02 +03:00
|
|
|
WLog_ERR(TAG, "Thread list does not contain this thread! check call!");
|
2014-07-14 21:36:31 +04:00
|
|
|
dump_thread(thread);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ListDictionary_Lock(thread_list);
|
|
|
|
dump_thread(thread);
|
|
|
|
|
2014-07-15 13:11:59 +04:00
|
|
|
if ((thread->started) && (WaitForSingleObject(thread, 0) != WAIT_OBJECT_0))
|
2014-07-14 21:36:31 +04:00
|
|
|
{
|
2014-10-27 13:39:02 +03:00
|
|
|
WLog_ERR(TAG, "Thread running, setting to detached state!");
|
2014-07-14 21:36:31 +04:00
|
|
|
thread->detached = TRUE;
|
|
|
|
pthread_detach(thread->thread);
|
|
|
|
}
|
2014-07-15 13:11:59 +04:00
|
|
|
else
|
2014-11-20 19:48:02 +03:00
|
|
|
{
|
2014-07-15 13:11:59 +04:00
|
|
|
cleanup_handle(thread);
|
2014-11-20 19:48:02 +03:00
|
|
|
}
|
2014-07-15 14:42:53 +04:00
|
|
|
|
2014-07-14 21:36:31 +04:00
|
|
|
ListDictionary_Unlock(thread_list);
|
|
|
|
|
|
|
|
if (ListDictionary_Count(thread_list) < 1)
|
|
|
|
{
|
|
|
|
ListDictionary_Free(thread_list);
|
|
|
|
thread_list = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-09-23 21:54:14 +04:00
|
|
|
HANDLE CreateRemoteThread(HANDLE hProcess, LPSECURITY_ATTRIBUTES lpThreadAttributes, SIZE_T dwStackSize,
|
2014-07-15 13:11:59 +04:00
|
|
|
LPTHREAD_START_ROUTINE lpStartAddress, LPVOID lpParameter, DWORD dwCreationFlags, LPDWORD lpThreadId)
|
2012-09-18 03:17:19 +04:00
|
|
|
{
|
2014-10-27 13:39:02 +03:00
|
|
|
WLog_ERR(TAG, "not implemented");
|
2012-09-23 21:54:14 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
2012-09-18 03:17:19 +04:00
|
|
|
|
2014-07-16 14:01:58 +04:00
|
|
|
VOID ExitThread(DWORD dwExitCode)
|
2012-09-23 21:54:14 +04:00
|
|
|
{
|
2014-11-16 17:21:13 +03:00
|
|
|
DWORD rc;
|
2014-07-14 21:36:31 +04:00
|
|
|
pthread_t tid = pthread_self();
|
|
|
|
|
2014-11-11 19:21:34 +03:00
|
|
|
if (!thread_list)
|
2014-07-14 21:36:31 +04:00
|
|
|
{
|
2014-10-27 13:39:02 +03:00
|
|
|
WLog_ERR(TAG, "function called without existing thread list!");
|
2014-07-14 21:36:31 +04:00
|
|
|
#if defined(WITH_DEBUG_THREADS)
|
|
|
|
DumpThreadHandles();
|
|
|
|
#endif
|
2014-11-11 19:21:34 +03:00
|
|
|
pthread_exit(0);
|
2014-07-14 21:36:31 +04:00
|
|
|
}
|
|
|
|
else if (!ListDictionary_Contains(thread_list, &tid))
|
|
|
|
{
|
2014-10-27 13:39:02 +03:00
|
|
|
WLog_ERR(TAG, "function called, but no matching entry in thread list!");
|
2014-07-14 21:36:31 +04:00
|
|
|
#if defined(WITH_DEBUG_THREADS)
|
|
|
|
DumpThreadHandles();
|
|
|
|
#endif
|
2014-11-11 19:21:34 +03:00
|
|
|
pthread_exit(0);
|
2014-07-14 21:36:31 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-11-11 19:21:34 +03:00
|
|
|
WINPR_THREAD* thread;
|
|
|
|
|
2014-07-14 21:36:31 +04:00
|
|
|
ListDictionary_Lock(thread_list);
|
|
|
|
thread = ListDictionary_GetItemValue(thread_list, &tid);
|
2014-11-11 19:21:34 +03:00
|
|
|
|
2014-07-14 21:36:31 +04:00
|
|
|
assert(thread);
|
2014-07-15 14:42:53 +04:00
|
|
|
thread->exited = TRUE;
|
|
|
|
thread->dwExitCode = dwExitCode;
|
2014-10-27 13:39:02 +03:00
|
|
|
#if defined(WITH_DEBUG_THREADS)
|
|
|
|
thread->exit_stack = winpr_backtrace(20);
|
2014-07-15 14:42:53 +04:00
|
|
|
#endif
|
2014-07-14 21:36:31 +04:00
|
|
|
ListDictionary_Unlock(thread_list);
|
2014-07-16 14:08:34 +04:00
|
|
|
set_event(thread);
|
|
|
|
|
2014-11-16 17:21:13 +03:00
|
|
|
rc = thread->dwExitCode;
|
2014-07-16 14:08:34 +04:00
|
|
|
if (thread->detached || !thread->started)
|
|
|
|
cleanup_handle(thread);
|
|
|
|
|
2014-11-16 17:21:13 +03:00
|
|
|
pthread_exit((void*) (size_t) rc);
|
2014-07-14 21:36:31 +04:00
|
|
|
}
|
2012-09-18 03:17:19 +04:00
|
|
|
}
|
|
|
|
|
2013-04-02 22:51:12 +04:00
|
|
|
BOOL GetExitCodeThread(HANDLE hThread, LPDWORD lpExitCode)
|
|
|
|
{
|
|
|
|
ULONG Type;
|
2015-07-03 10:36:58 +03:00
|
|
|
WINPR_HANDLE* Object;
|
2014-11-20 19:48:02 +03:00
|
|
|
WINPR_THREAD* thread;
|
2013-04-02 22:51:12 +04:00
|
|
|
|
|
|
|
if (!winpr_Handle_GetInfo(hThread, &Type, &Object))
|
|
|
|
return FALSE;
|
|
|
|
|
2014-11-20 19:48:02 +03:00
|
|
|
thread = (WINPR_THREAD*) Object;
|
2013-04-02 22:51:12 +04:00
|
|
|
*lpExitCode = thread->dwExitCode;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2013-01-20 05:32:14 +04:00
|
|
|
HANDLE _GetCurrentThread(VOID)
|
2012-09-18 03:17:19 +04:00
|
|
|
{
|
2014-07-14 21:36:31 +04:00
|
|
|
HANDLE hdl = NULL;
|
|
|
|
pthread_t tid = pthread_self();
|
|
|
|
|
2014-11-20 19:48:02 +03:00
|
|
|
if (!thread_list)
|
2014-07-14 21:36:31 +04:00
|
|
|
{
|
2014-10-27 13:39:02 +03:00
|
|
|
WLog_ERR(TAG, "function called without existing thread list!");
|
2014-07-14 21:36:31 +04:00
|
|
|
#if defined(WITH_DEBUG_THREADS)
|
|
|
|
DumpThreadHandles();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else if (!ListDictionary_Contains(thread_list, &tid))
|
|
|
|
{
|
2014-10-27 13:39:02 +03:00
|
|
|
WLog_ERR(TAG, "function called, but no matching entry in thread list!");
|
2014-07-14 21:36:31 +04:00
|
|
|
#if defined(WITH_DEBUG_THREADS)
|
|
|
|
DumpThreadHandles();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
hdl = ListDictionary_GetItemValue(thread_list, &tid);
|
|
|
|
}
|
|
|
|
|
|
|
|
return hdl;
|
2012-09-18 03:17:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
DWORD GetCurrentThreadId(VOID)
|
|
|
|
{
|
2013-01-22 03:33:00 +04:00
|
|
|
pthread_t tid;
|
|
|
|
tid = pthread_self();
|
2015-05-05 19:33:44 +03:00
|
|
|
|
2015-05-20 17:52:24 +03:00
|
|
|
/* Since pthread_t can be 64-bits on some systems, take just the */
|
|
|
|
/* lower 32-bits of it for the thread ID returned by this function. */
|
2016-02-04 14:57:21 +03:00
|
|
|
return (DWORD)tid & 0xffffffffUL;
|
2012-09-18 03:17:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
DWORD ResumeThread(HANDLE hThread)
|
|
|
|
{
|
2012-09-23 21:54:14 +04:00
|
|
|
ULONG Type;
|
2015-07-03 10:36:58 +03:00
|
|
|
WINPR_HANDLE* Object;
|
|
|
|
WINPR_THREAD* thread;
|
2012-09-23 21:54:14 +04:00
|
|
|
|
|
|
|
if (!winpr_Handle_GetInfo(hThread, &Type, &Object))
|
2015-07-16 14:48:14 +03:00
|
|
|
return (DWORD)-1;
|
2012-09-23 21:54:14 +04:00
|
|
|
|
2014-11-20 19:48:02 +03:00
|
|
|
thread = (WINPR_THREAD*) Object;
|
2015-07-16 14:48:14 +03:00
|
|
|
if (pthread_mutex_lock(&thread->mutex))
|
|
|
|
return (DWORD)-1;
|
2012-09-23 21:54:14 +04:00
|
|
|
|
|
|
|
if (!thread->started)
|
2015-07-23 12:52:24 +03:00
|
|
|
{
|
|
|
|
if (!winpr_StartThread(thread))
|
|
|
|
{
|
|
|
|
pthread_mutex_unlock(&thread->mutex);
|
|
|
|
return (DWORD)-1;
|
|
|
|
}
|
|
|
|
}
|
2014-07-14 21:36:31 +04:00
|
|
|
else
|
2014-10-27 13:39:02 +03:00
|
|
|
WLog_WARN(TAG, "Thread already started!");
|
2012-09-23 21:54:14 +04:00
|
|
|
|
2015-07-16 14:48:14 +03:00
|
|
|
if (pthread_mutex_unlock(&thread->mutex))
|
|
|
|
return (DWORD)-1;
|
|
|
|
|
2012-09-18 03:17:19 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD SuspendThread(HANDLE hThread)
|
|
|
|
{
|
2014-10-27 13:39:02 +03:00
|
|
|
WLog_ERR(TAG, "Function not implemented!");
|
2012-09-18 03:17:19 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL SwitchToThread(VOID)
|
|
|
|
{
|
2015-07-23 12:52:24 +03:00
|
|
|
WLog_ERR(TAG, "Function not implemented!");
|
2012-09-18 03:17:19 +04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL TerminateThread(HANDLE hThread, DWORD dwExitCode)
|
|
|
|
{
|
2012-09-23 21:54:14 +04:00
|
|
|
ULONG Type;
|
2015-07-03 10:36:58 +03:00
|
|
|
WINPR_HANDLE* Object;
|
2014-11-20 19:48:02 +03:00
|
|
|
WINPR_THREAD* thread;
|
2012-09-23 21:54:14 +04:00
|
|
|
|
|
|
|
if (!winpr_Handle_GetInfo(hThread, &Type, &Object))
|
2015-07-16 14:48:14 +03:00
|
|
|
return FALSE;
|
2012-09-23 21:54:14 +04:00
|
|
|
|
2014-11-20 19:48:02 +03:00
|
|
|
thread = (WINPR_THREAD*) Object;
|
2014-07-16 14:01:58 +04:00
|
|
|
thread->exited = TRUE;
|
|
|
|
thread->dwExitCode = dwExitCode;
|
2015-07-16 14:48:14 +03:00
|
|
|
if (pthread_mutex_lock(&thread->mutex))
|
|
|
|
return FALSE;
|
|
|
|
|
2012-10-14 04:31:01 +04:00
|
|
|
#ifndef ANDROID
|
2012-09-23 21:54:14 +04:00
|
|
|
pthread_cancel(thread->thread);
|
2014-07-14 21:36:31 +04:00
|
|
|
#else
|
2014-10-27 13:39:02 +03:00
|
|
|
WLog_ERR(TAG, "Function not supported on this platform!");
|
2012-10-14 04:31:01 +04:00
|
|
|
#endif
|
2015-07-16 14:48:14 +03:00
|
|
|
if (pthread_mutex_unlock(&thread->mutex))
|
|
|
|
return FALSE;
|
|
|
|
|
2015-01-28 14:43:20 +03:00
|
|
|
set_event(thread);
|
2012-09-18 03:17:19 +04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-07-14 21:36:31 +04:00
|
|
|
#if defined(WITH_DEBUG_THREADS)
|
|
|
|
VOID DumpThreadHandles(void)
|
|
|
|
{
|
2014-10-27 13:39:02 +03:00
|
|
|
char** msg;
|
|
|
|
size_t used, i;
|
|
|
|
void* stack = winpr_backtrace(20);
|
|
|
|
WLog_DBG(TAG, "---------------- Called from ----------------------------");
|
|
|
|
msg = winpr_backtrace_symbols(stack, &used);
|
|
|
|
|
2014-11-20 19:48:02 +03:00
|
|
|
for (i = 0; i < used; i++)
|
|
|
|
{
|
2014-10-27 13:39:02 +03:00
|
|
|
WLog_DBG(TAG, "[%d]: %s", i, msg[i]);
|
2014-11-20 19:48:02 +03:00
|
|
|
}
|
2014-10-27 13:39:02 +03:00
|
|
|
|
|
|
|
free(msg);
|
|
|
|
winpr_backtrace_free(stack);
|
|
|
|
WLog_DBG(TAG, "---------------- Start Dumping thread handles -----------");
|
2014-07-14 21:36:31 +04:00
|
|
|
|
|
|
|
if (!thread_list)
|
2014-11-20 19:48:02 +03:00
|
|
|
{
|
2014-10-27 13:39:02 +03:00
|
|
|
WLog_DBG(TAG, "All threads properly shut down and disposed of.");
|
2014-11-20 19:48:02 +03:00
|
|
|
}
|
2014-07-14 21:36:31 +04:00
|
|
|
else
|
|
|
|
{
|
|
|
|
ULONG_PTR *keys = NULL;
|
|
|
|
ListDictionary_Lock(thread_list);
|
|
|
|
int x, count = ListDictionary_GetKeys(thread_list, &keys);
|
2015-01-20 13:04:23 +03:00
|
|
|
WLog_DBG(TAG, "Dumping %d elements", count);
|
2014-07-14 21:36:31 +04:00
|
|
|
|
2014-11-20 19:48:02 +03:00
|
|
|
for (x = 0; x < count; x++)
|
2014-07-14 21:36:31 +04:00
|
|
|
{
|
2014-11-20 19:48:02 +03:00
|
|
|
WINPR_THREAD* thread = ListDictionary_GetItemValue(thread_list, (void*) keys[x]);
|
2014-10-27 13:39:02 +03:00
|
|
|
WLog_DBG(TAG, "Thread [%d] handle created still not closed!", x);
|
|
|
|
msg = winpr_backtrace_symbols(thread->create_stack, &used);
|
|
|
|
|
2014-11-20 19:48:02 +03:00
|
|
|
for (i = 0; i < used; i++)
|
|
|
|
{
|
2014-10-27 13:39:02 +03:00
|
|
|
WLog_DBG(TAG, "[%d]: %s", i, msg[i]);
|
2014-11-20 19:48:02 +03:00
|
|
|
}
|
2014-10-27 13:39:02 +03:00
|
|
|
|
|
|
|
free(msg);
|
2014-07-14 21:36:31 +04:00
|
|
|
|
|
|
|
if (thread->started)
|
2014-11-20 19:48:02 +03:00
|
|
|
{
|
2014-10-27 13:39:02 +03:00
|
|
|
WLog_DBG(TAG, "Thread [%d] still running!", x);
|
2014-11-20 19:48:02 +03:00
|
|
|
}
|
2014-07-14 21:36:31 +04:00
|
|
|
else
|
|
|
|
{
|
2014-10-27 13:39:02 +03:00
|
|
|
WLog_DBG(TAG, "Thread [%d] exited at:", x);
|
|
|
|
msg = winpr_backtrace_symbols(thread->exit_stack, &used);
|
|
|
|
|
|
|
|
for (i=0; i<used; i++)
|
|
|
|
WLog_DBG(TAG, "[%d]: %s", i, msg[i]);
|
|
|
|
|
|
|
|
free(msg);
|
2014-07-14 21:36:31 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-11 10:07:39 +03:00
|
|
|
free(keys);
|
2014-07-15 14:42:53 +04:00
|
|
|
|
2014-07-14 21:36:31 +04:00
|
|
|
ListDictionary_Unlock(thread_list);
|
|
|
|
}
|
|
|
|
|
2014-10-27 13:39:02 +03:00
|
|
|
WLog_DBG(TAG, "---------------- End Dumping thread handles -------------");
|
2014-07-14 21:36:31 +04:00
|
|
|
}
|
|
|
|
#endif
|
2012-09-18 03:17:19 +04:00
|
|
|
#endif
|
|
|
|
|