FreeRDP
thread.c File Reference
#include <winpr/assert.h>
#include <winpr/handle.h>
#include <winpr/thread.h>
#include <winpr/crt.h>
#include <winpr/platform.h>
#include <winpr/debug.h>
#include <errno.h>
#include <fcntl.h>
#include <winpr/collections.h>
#include "thread.h"
#include "apc.h"
#include "../handle/handle.h"
#include "../log.h"

Macros

#define TAG   WINPR_TAG("thread")
 

Functions

static BOOL ThreadCloseHandle (HANDLE handle)
 
static void cleanup_handle (void *obj)
 
static BOOL ThreadIsHandled (HANDLE handle)
 
static int ThreadGetFd (HANDLE handle)
 
static DWORD ThreadCleanupHandle (HANDLE handle)
 
static void dump_thread (WINPR_THREAD *thread)
 
static BOOL set_event (WINPR_THREAD *thread)
 
static BOOL reset_event (WINPR_THREAD *thread)
 
static BOOL initializeThreads (PINIT_ONCE InitOnce, PVOID Parameter, PVOID *Context)
 
static void * thread_launcher (void *arg)
 
static BOOL winpr_StartThread (WINPR_THREAD *thread)
 
HANDLE CreateThread (LPSECURITY_ATTRIBUTES lpThreadAttributes, SIZE_T dwStackSize, LPTHREAD_START_ROUTINE lpStartAddress, LPVOID lpParameter, DWORD dwCreationFlags, LPDWORD lpThreadId)
 
HANDLE CreateRemoteThread (HANDLE hProcess, LPSECURITY_ATTRIBUTES lpThreadAttributes, SIZE_T dwStackSize, LPTHREAD_START_ROUTINE lpStartAddress, LPVOID lpParameter, DWORD dwCreationFlags, LPDWORD lpThreadId)
 
VOID ExitThread (DWORD dwExitCode)
 
BOOL GetExitCodeThread (HANDLE hThread, LPDWORD lpExitCode)
 
WINPR_THREAD * winpr_GetCurrentThread (VOID)
 
HANDLE _GetCurrentThread (VOID)
 
DWORD GetCurrentThreadId (VOID)
 
static void userAPC (LPVOID arg)
 
DWORD QueueUserAPC (PAPCFUNC pfnAPC, HANDLE hThread, ULONG_PTR dwData)
 
DWORD ResumeThread (HANDLE hThread)
 
DWORD SuspendThread (HANDLE hThread)
 
BOOL SwitchToThread (VOID)
 
BOOL TerminateThread (HANDLE hThread, DWORD dwExitCode)
 

Variables

static WINPR_THREAD mainThread
 
static HANDLE_OPS ops
 
static INIT_ONCE threads_InitOnce = INIT_ONCE_STATIC_INIT
 
static pthread_t mainThreadId
 
static DWORD currentThreadTlsIndex = TLS_OUT_OF_INDEXES
 

Macro Definition Documentation

◆ TAG

#define TAG   WINPR_TAG("thread")

WinPR: Windows Portable Runtime Process Thread Functions

Copyright 2012 Marc-Andre Moreau marca.nosp@m.ndre.nosp@m..more.nosp@m.au@g.nosp@m.mail..nosp@m.com Copyright 2015 Hewlett-Packard Development Company, L.P. Copyright 2021 David Fort conta.nosp@m.ct@h.nosp@m.arden.nosp@m.ing-.nosp@m.consu.nosp@m.ltin.nosp@m.g.com

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. api-ms-win-core-processthreads-l1-1-1.dll

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

Function Documentation

◆ _GetCurrentThread()

HANDLE _GetCurrentThread ( VOID  )
Here is the call graph for this function:

◆ cleanup_handle()

void cleanup_handle ( void *  obj)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ CreateRemoteThread()

HANDLE CreateRemoteThread ( HANDLE  hProcess,
LPSECURITY_ATTRIBUTES  lpThreadAttributes,
SIZE_T  dwStackSize,
LPTHREAD_START_ROUTINE  lpStartAddress,
LPVOID  lpParameter,
DWORD  dwCreationFlags,
LPDWORD  lpThreadId 
)
Here is the call graph for this function:

◆ CreateThread()

HANDLE CreateThread ( LPSECURITY_ATTRIBUTES  lpThreadAttributes,
SIZE_T  dwStackSize,
LPTHREAD_START_ROUTINE  lpStartAddress,
LPVOID  lpParameter,
DWORD  dwCreationFlags,
LPDWORD  lpThreadId 
)
Here is the call graph for this function:

◆ dump_thread()

static void dump_thread ( WINPR_THREAD *  thread)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ExitThread()

VOID ExitThread ( DWORD  dwExitCode)
Here is the call graph for this function:

◆ GetCurrentThreadId()

DWORD GetCurrentThreadId ( VOID  )

◆ GetExitCodeThread()

BOOL GetExitCodeThread ( HANDLE  hThread,
LPDWORD  lpExitCode 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ initializeThreads()

static BOOL initializeThreads ( PINIT_ONCE  InitOnce,
PVOID  Parameter,
PVOID *  Context 
)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ QueueUserAPC()

DWORD QueueUserAPC ( PAPCFUNC  pfnAPC,
HANDLE  hThread,
ULONG_PTR  dwData 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ reset_event()

static BOOL reset_event ( WINPR_THREAD *  thread)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ResumeThread()

DWORD ResumeThread ( HANDLE  hThread)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_event()

static BOOL set_event ( WINPR_THREAD *  thread)
static

TODO: implement thread suspend/resume using pthreads http://stackoverflow.com/questions/3140867/suspend-pthreads-without-using-condition

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SuspendThread()

DWORD SuspendThread ( HANDLE  hThread)
Here is the call graph for this function:

◆ SwitchToThread()

BOOL SwitchToThread ( VOID  )

Note: on some operating systems sched_yield is a stub returning -1. usleep should at least trigger a context switch if any thread is waiting.

◆ TerminateThread()

BOOL TerminateThread ( HANDLE  hThread,
DWORD  dwExitCode 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ thread_launcher()

static void* thread_launcher ( void *  arg)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ThreadCleanupHandle()

static DWORD ThreadCleanupHandle ( HANDLE  handle)
static
Here is the call graph for this function:

◆ ThreadCloseHandle()

BOOL ThreadCloseHandle ( HANDLE  handle)
static
Here is the call graph for this function:

◆ ThreadGetFd()

static int ThreadGetFd ( HANDLE  handle)
static
Here is the call graph for this function:

◆ ThreadIsHandled()

static BOOL ThreadIsHandled ( HANDLE  handle)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ userAPC()

static void userAPC ( LPVOID  arg)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ winpr_GetCurrentThread()

WINPR_THREAD* winpr_GetCurrentThread ( VOID  )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ winpr_StartThread()

static BOOL winpr_StartThread ( WINPR_THREAD *  thread)
static
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ currentThreadTlsIndex

DWORD currentThreadTlsIndex = TLS_OUT_OF_INDEXES
static

◆ mainThread

WINPR_THREAD mainThread
static

◆ mainThreadId

pthread_t mainThreadId
static

◆ ops

◆ threads_InitOnce

INIT_ONCE threads_InitOnce = INIT_ONCE_STATIC_INIT
static
ThreadCloseHandle
static BOOL ThreadCloseHandle(HANDLE handle)
Definition: thread.c:545
ThreadIsHandled
static BOOL ThreadIsHandled(HANDLE handle)
Definition: thread.c:109
ThreadGetFd
static int ThreadGetFd(HANDLE handle)
Definition: thread.c:122
ThreadCleanupHandle
static DWORD ThreadCleanupHandle(HANDLE handle)
Definition: thread.c:132
NULL
if availableBytes return NULL
Definition: TPCircularBuffer.h:109