| 1 | // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF |
| 2 | // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO |
| 3 | // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A |
| 4 | // PARTICULAR PURPOSE. |
| 5 | // |
| 6 | // Copyright (c) Microsoft Corporation. All rights reserved. |
| 7 | // |
| 8 | // |
| 9 | // Emulates a subset of the Win32 threading API as a layer on top of WinRT threadpools. |
| 10 | // |
| 11 | // Supported features: |
| 12 | // |
| 13 | // - CreateThread (returns a standard Win32 handle which can be waited on, then closed) |
| 14 | // - CREATE_SUSPENDED and ResumeThread |
| 15 | // - Partial support for SetThreadPriority (see below) |
| 16 | // - Sleep |
| 17 | // - Thread local storage (TlsAlloc, TlsFree, TlsGetValue, TlsSetValue) |
| 18 | // |
| 19 | // Differences from Win32: |
| 20 | // |
| 21 | // - If using TLS other than from this CreateThread emulation, call TlsShutdown before thread/task exit |
| 22 | // - No ExitThread or TerminateThread (just return from the thread function to exit) |
| 23 | // - No SuspendThread, so ResumeThread is only useful in combination with CREATE_SUSPENDED |
| 24 | // - SetThreadPriority is only available while a thread is in CREATE_SUSPENDED state |
| 25 | // - SetThreadPriority only supports three priority levels (negative, zero, or positive) |
| 26 | // - No thread identifier APIs (GetThreadId, GetCurrentThreadId, OpenThread) |
| 27 | // - No affinity APIs |
| 28 | // - No GetExitCodeThread |
| 29 | // - Failure cases return error codes but do not always call SetLastError |
| 30 | |
| 31 | #pragma once |
| 32 | |
| 33 | #include <windows.h> |
| 34 | |
| 35 | #ifdef __cplusplus |
| 36 | //namespace ThreadEmulation |
| 37 | //{ |
| 38 | extern "C" |
| 39 | { |
| 40 | #endif |
| 41 | #ifndef CREATE_SUSPENDED |
| 42 | #define CREATE_SUSPENDED 0x00000004 |
| 43 | #endif |
| 44 | |
| 45 | HANDLE WINAPI CreateThreadRT(_In_opt_ LPSECURITY_ATTRIBUTES unusedThreadAttributes, _In_ SIZE_T unusedStackSize, _In_ LPTHREAD_START_ROUTINE lpStartAddress, _In_opt_ LPVOID lpParameter, _In_ DWORD dwCreationFlags, _Out_opt_ LPDWORD unusedThreadId); |
| 46 | DWORD WINAPI ResumeThreadRT(_In_ HANDLE hThread); |
| 47 | BOOL WINAPI SetThreadPriorityRT(_In_ HANDLE hThread, _In_ int nPriority); |
| 48 | |
| 49 | VOID WINAPI SleepRT(_In_ DWORD dwMilliseconds); |
| 50 | |
| 51 | DWORD WINAPI TlsAllocRT(); |
| 52 | BOOL WINAPI TlsFreeRT(_In_ DWORD dwTlsIndex); |
| 53 | LPVOID WINAPI TlsGetValueRT(_In_ DWORD dwTlsIndex); |
| 54 | BOOL WINAPI TlsSetValueRT(_In_ DWORD dwTlsIndex, _In_opt_ LPVOID lpTlsValue); |
| 55 | |
| 56 | void WINAPI TlsShutdown(); |
| 57 | #ifdef __cplusplus |
| 58 | } |
| 59 | #endif |