I'm porting legacy Windows code to Windows Runtime (WinRT), specifically Windows Phone 8.1. The code contains calls to thread local storage functions like TlsAlloc, TlsFree, TlsGetValue, and TlsSetValue. According to MSDN's "Win32 and COM for Windows Runtime apps (system)" page, these four TLS functions are supported under WinRT. Reading the TlsAlloc documentation, for example, one reads:
Windows Phone 8.1: This function is supported for Windows Phone Store apps on Windows Phone 8.1 and later. When a Windows Phone Store app calls this function, it is replaced with an inline call to FlsAlloc. Refer to FlsAlloc for function documentation.
When I #include the indicated header file, Processthreadsapi.h, in my legacy code, the compile fails:
error C2039: 'TlsAlloc' : is not a member of '`global namespace''
Examining Processthreadsapi.h shows why it doesn't help me:
/***********************************************************************************
* *
* processthreadsapi.h -- ApiSet Contract for api-ms-win-core-processthreads-l1 *
* *
* Copyright (c) Microsoft Corporation. All rights reserved. *
* *
***********************************************************************************/
. . .
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
. . .
#ifndef FLS_OUT_OF_INDEXES
#define FLS_OUT_OF_INDEXES ((DWORD)0xFFFFFFFF)
#endif
#define TLS_OUT_OF_INDEXES ((DWORD)0xFFFFFFFF)
_Must_inspect_result_
WINBASEAPI
DWORD
WINAPI
TlsAlloc(
VOID
);
WINBASEAPI
LPVOID
WINAPI
TlsGetValue(
_In_ DWORD dwTlsIndex
);
WINBASEAPI
BOOL
WINAPI
TlsSetValue(
_In_ DWORD dwTlsIndex,
_In_opt_ LPVOID lpTlsValue
);
WINBASEAPI
BOOL
WINAPI
TlsFree(
_In_ DWORD dwTlsIndex
);
. . .
#endif /* WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) */
. . .
The problem is clear: WinRT belongs to the world of WINAPI_PARTITION_APP, not WINAPI_PARTITION_DESKTOP. Therefore, when I compile my app for WinRT, I do not get any of these symbols and function declarations.
Is this only a Windows header problem, where MS should have included the Tls* functions for WinRT? Or is thread local storage not supported for WinRT, contrary to the documentation?