FreeRDP
|
#include <winpr/config.h>
#include <winpr/assert.h>
#include <winpr/handle.h>
#include <winpr/thread.h>
#include <winpr/crt.h>
#include <winpr/platform.h>
#include <string.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 | MIN(x, y) (((x) < (y)) ? (x) : (y)) |
#define | MAX(x, y) (((x) > (y)) ? (x) : (y)) |
#define | TAG WINPR_TAG("thread") |
#define | run_mutex_init(fkt, mux, arg) run_mutex_init_(fkt, #fkt, mux, arg) |
#define | run_mutex_fkt(fkt, mux) run_mutex_fkt_(fkt, #fkt, mux) |
#define | run_cond_init(fkt, cond, arg) run_cond_init_(fkt, #fkt, cond, arg) |
#define | run_cond_fkt(fkt, cond) run_cond_fkt_(fkt, #fkt, cond) |
Functions | |
static BOOL | ThreadCloseHandle (HANDLE handle) |
static void | cleanup_handle (void *obj) |
static BOOL | ThreadIsHandled (HANDLE handle) |
static int | ThreadGetFd (HANDLE handle) |
static BOOL | run_mutex_init_ (int(*fkt)(pthread_mutex_t *, const pthread_mutexattr_t *), const char *name, pthread_mutex_t *mutex, const pthread_mutexattr_t *mutexattr) |
static BOOL | run_mutex_fkt_ (int(*fkt)(pthread_mutex_t *mux), const char *name, pthread_mutex_t *mutex) |
static BOOL | run_cond_init_ (int(*fkt)(pthread_cond_t *, const pthread_condattr_t *), const char *name, pthread_cond_t *condition, const pthread_condattr_t *conditionattr) |
static BOOL | run_cond_fkt_ (int(*fkt)(pthread_cond_t *mux), const char *name, pthread_cond_t *condition) |
static int | pthread_mutex_checked_unlock (pthread_mutex_t *mutex) |
static BOOL | mux_condition_bundle_init (mux_condition_bundle *bundle) |
static void | mux_condition_bundle_uninit (mux_condition_bundle *bundle) |
static BOOL | mux_condition_bundle_signal (mux_condition_bundle *bundle) |
static BOOL | mux_condition_bundle_lock (mux_condition_bundle *bundle) |
static BOOL | mux_condition_bundle_unlock (mux_condition_bundle *bundle) |
static BOOL | mux_condition_bundle_wait (mux_condition_bundle *bundle, const char *name) |
static BOOL | signal_thread_ready (WINPR_THREAD *thread) |
static BOOL | signal_thread_is_running (WINPR_THREAD *thread) |
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 BOOL | signal_and_wait_for_ready (WINPR_THREAD *thread) |
static void * | thread_launcher (void *arg) |
static BOOL | winpr_StartThread (WINPR_THREAD *thread) |
BOOL | SetThreadPriority (HANDLE hThread, int nPriority) |
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) |
VOID | DumpThreadHandles (void) |
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 |
WinPR: Windows Portable Runtime Process Thread Functions
Copyright 2012 Marc-Andre Moreau marca Copyright 2015 Hewlett-Packard Development Company, L.P. Copyright 2021 David Fort ndre .more au@g mail. comconta ct@h arden ing- consu ltin 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.
#define run_cond_fkt | ( | fkt, | |
cond | |||
) | run_cond_fkt_(fkt, #fkt, cond) |
#define run_cond_init | ( | fkt, | |
cond, | |||
arg | |||
) | run_cond_init_(fkt, #fkt, cond, arg) |
#define run_mutex_fkt | ( | fkt, | |
mux | |||
) | run_mutex_fkt_(fkt, #fkt, mux) |
#define run_mutex_init | ( | fkt, | |
mux, | |||
arg | |||
) | run_mutex_init_(fkt, #fkt, mux, arg) |
#define TAG WINPR_TAG("thread") |
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
HANDLE _GetCurrentThread | ( | VOID | ) |
|
static |
HANDLE CreateRemoteThread | ( | HANDLE | hProcess, |
LPSECURITY_ATTRIBUTES | lpThreadAttributes, | ||
SIZE_T | dwStackSize, | ||
LPTHREAD_START_ROUTINE | lpStartAddress, | ||
LPVOID | lpParameter, | ||
DWORD | dwCreationFlags, | ||
LPDWORD | lpThreadId | ||
) |
HANDLE CreateThread | ( | LPSECURITY_ATTRIBUTES | lpThreadAttributes, |
SIZE_T | dwStackSize, | ||
LPTHREAD_START_ROUTINE | lpStartAddress, | ||
LPVOID | lpParameter, | ||
DWORD | dwCreationFlags, | ||
LPDWORD | lpThreadId | ||
) |
|
static |
VOID DumpThreadHandles | ( | void | ) |
VOID ExitThread | ( | DWORD | dwExitCode | ) |
DWORD GetCurrentThreadId | ( | VOID | ) |
BOOL GetExitCodeThread | ( | HANDLE | hThread, |
LPDWORD | lpExitCode | ||
) |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
DWORD QueueUserAPC | ( | PAPCFUNC | pfnAPC, |
HANDLE | hThread, | ||
ULONG_PTR | dwData | ||
) |
|
static |
DWORD ResumeThread | ( | HANDLE | hThread | ) |
|
static |
|
static |
|
static |
|
static |
|
static |
TODO: implement thread suspend/resume using pthreads http://stackoverflow.com/questions/3140867/suspend-pthreads-without-using-condition
BOOL SetThreadPriority | ( | HANDLE | hThread, |
int | nPriority | ||
) |
|
static |
|
static |
|
static |
DWORD SuspendThread | ( | HANDLE | hThread | ) |
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.
BOOL TerminateThread | ( | HANDLE | hThread, |
DWORD | dwExitCode | ||
) |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
WINPR_THREAD* winpr_GetCurrentThread | ( | VOID | ) |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |