mirror of
https://github.com/reactos/reactos.git
synced 2025-08-05 22:23:01 +00:00
Create a branch for cmake bringup.
svn path=/branches/cmake-bringup/; revision=48236
This commit is contained in:
parent
a28e798006
commit
c424146e2c
20602 changed files with 0 additions and 1140137 deletions
102
lib/sdk/crt/misc/tls.c
Normal file
102
lib/sdk/crt/misc/tls.c
Normal file
|
@ -0,0 +1,102 @@
|
|||
#include <precomp.h>
|
||||
#include <stdlib.h>
|
||||
#include <internal/tls.h>
|
||||
#include <internal/rterror.h>
|
||||
|
||||
|
||||
static unsigned long TlsIndex = (unsigned long)-1;
|
||||
|
||||
|
||||
static void InitThreadData(PTHREADDATA ThreadData)
|
||||
{
|
||||
ThreadData->terrno = 0;
|
||||
ThreadData->tdoserrno = 0;
|
||||
|
||||
ThreadData->fpecode = 0;
|
||||
|
||||
ThreadData->tnext = 1;
|
||||
|
||||
/* FIXME: init more thread local data */
|
||||
|
||||
}
|
||||
|
||||
|
||||
int CreateThreadData(void)
|
||||
{
|
||||
PTHREADDATA ThreadData;
|
||||
|
||||
TlsIndex = TlsAlloc();
|
||||
if (TlsIndex == (unsigned long)-1)
|
||||
return FALSE;
|
||||
|
||||
ThreadData = (PTHREADDATA)calloc(1, sizeof(THREADDATA));
|
||||
if (ThreadData == NULL)
|
||||
return FALSE;
|
||||
|
||||
if(!TlsSetValue(TlsIndex, (LPVOID)ThreadData))
|
||||
return FALSE;
|
||||
|
||||
InitThreadData(ThreadData);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
void DestroyThreadData(void)
|
||||
{
|
||||
if (TlsIndex != (unsigned long)-1)
|
||||
{
|
||||
TlsFree(TlsIndex);
|
||||
TlsIndex = (unsigned long)-1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void FreeThreadData(PTHREADDATA ThreadData)
|
||||
{
|
||||
if (TlsIndex != (unsigned long)-1)
|
||||
{
|
||||
if (ThreadData == NULL)
|
||||
ThreadData = TlsGetValue(TlsIndex);
|
||||
|
||||
if (ThreadData != NULL)
|
||||
{
|
||||
/* FIXME: free more thread local data */
|
||||
|
||||
free(ThreadData);
|
||||
}
|
||||
|
||||
TlsSetValue(TlsIndex, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
PTHREADDATA GetThreadData(void)
|
||||
{
|
||||
PTHREADDATA ThreadData;
|
||||
DWORD LastError;
|
||||
|
||||
LastError = GetLastError();
|
||||
ThreadData = TlsGetValue(TlsIndex);
|
||||
if (ThreadData == NULL)
|
||||
{
|
||||
ThreadData = (PTHREADDATA)calloc(1, sizeof(THREADDATA));
|
||||
if (ThreadData != NULL)
|
||||
{
|
||||
TlsSetValue(TlsIndex, (LPVOID)ThreadData);
|
||||
|
||||
InitThreadData(ThreadData);
|
||||
}
|
||||
else
|
||||
{
|
||||
_amsg_exit(_RT_THREAD); /* write message and die */
|
||||
}
|
||||
}
|
||||
|
||||
SetLastError(LastError);
|
||||
|
||||
return ThreadData;
|
||||
}
|
||||
|
||||
/* EOF */
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue