mirror of
https://github.com/reactos/reactos.git
synced 2025-08-02 05:25:48 +00:00
Create a branch for Aleksandar Andrejevic for his work on NTVDM. See http://jira.reactos.org/browse/CORE-7250 for more details.
svn path=/branches/ntvdm/; revision=59241
This commit is contained in:
parent
3e3200acef
commit
4f0b8d3db0
20620 changed files with 0 additions and 1232833 deletions
73
lib/sdk/crt/misc/tls.c
Normal file
73
lib/sdk/crt/misc/tls.c
Normal file
|
@ -0,0 +1,73 @@
|
|||
#include <precomp.h>
|
||||
#include <stdlib.h>
|
||||
#include <internal/tls.h>
|
||||
#include <internal/rterror.h>
|
||||
|
||||
/* Index to TLS */
|
||||
static DWORD msvcrt_tls_index;
|
||||
|
||||
inline BOOL msvcrt_init_tls(void)
|
||||
{
|
||||
msvcrt_tls_index = TlsAlloc();
|
||||
|
||||
if (msvcrt_tls_index == TLS_OUT_OF_INDEXES)
|
||||
{
|
||||
ERR("TlsAlloc() failed!\n");
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
inline BOOL msvcrt_free_tls(void)
|
||||
{
|
||||
if (!TlsFree(msvcrt_tls_index))
|
||||
{
|
||||
ERR("TlsFree() failed!\n");
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
thread_data_t *msvcrt_get_thread_data(void)
|
||||
{
|
||||
thread_data_t *ptr;
|
||||
DWORD err = GetLastError(); /* need to preserve last error */
|
||||
|
||||
if (!(ptr = TlsGetValue( msvcrt_tls_index )))
|
||||
{
|
||||
if (!(ptr = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*ptr) )))
|
||||
_amsg_exit( _RT_THREAD );
|
||||
if (!TlsSetValue( msvcrt_tls_index, ptr )) _amsg_exit( _RT_THREAD );
|
||||
ptr->tid = GetCurrentThreadId();
|
||||
ptr->handle = INVALID_HANDLE_VALUE;
|
||||
ptr->random_seed = 1;
|
||||
ptr->locinfo = MSVCRT_locale->locinfo;
|
||||
ptr->mbcinfo = MSVCRT_locale->mbcinfo;
|
||||
}
|
||||
SetLastError( err );
|
||||
return ptr;
|
||||
}
|
||||
|
||||
inline void msvcrt_free_tls_mem(void)
|
||||
{
|
||||
thread_data_t *tls = TlsGetValue(msvcrt_tls_index);
|
||||
|
||||
if (tls)
|
||||
{
|
||||
CloseHandle(tls->handle);
|
||||
HeapFree(GetProcessHeap(),0,tls->efcvt_buffer);
|
||||
HeapFree(GetProcessHeap(),0,tls->asctime_buffer);
|
||||
HeapFree(GetProcessHeap(),0,tls->wasctime_buffer);
|
||||
HeapFree(GetProcessHeap(),0,tls->strerror_buffer);
|
||||
HeapFree(GetProcessHeap(),0,tls->wcserror_buffer);
|
||||
HeapFree(GetProcessHeap(),0,tls->time_buffer);
|
||||
//if(tls->have_locale) {
|
||||
// free_locinfo(tls->locinfo);
|
||||
// free_mbcinfo(tls->mbcinfo);
|
||||
//}
|
||||
}
|
||||
HeapFree(GetProcessHeap(), 0, tls);
|
||||
}
|
||||
|
||||
/* EOF */
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue