revert my last change Modified: trunk/reactos/lib/crt/crt.xml Modified: trunk/reactos/lib/crt/include/internal/tls.h Modified: trunk/reactos/lib/crt/misc/tls.c Modified: trunk/reactos/lib/crt/process/thread.c Added: trunk/reactos/lib/crt/wine/thread.c _____
Modified: trunk/reactos/lib/crt/crt.xml --- trunk/reactos/lib/crt/crt.xml 2006-01-13 17:32:59 UTC (rev 20834) +++ trunk/reactos/lib/crt/crt.xml 2006-01-13 17:54:37 UTC (rev 20835) @@ -385,6 +385,7 @@
<file>cppexcept.c</file> <file>heap.c</file> <file>scanf.c</file> + <file>thread.c</file> <file>undname.c</file> </directory> </module> _____
Modified: trunk/reactos/lib/crt/include/internal/tls.h --- trunk/reactos/lib/crt/include/internal/tls.h 2006-01-13 17:32:59 UTC (rev 20834) +++ trunk/reactos/lib/crt/include/internal/tls.h 2006-01-13 17:54:37 UTC (rev 20835) @@ -17,10 +17,6 @@
typedef struct _ThreadData { - HANDLE hThread; /* handle to the current thread */ - void (__cdecl *start_address)(void*); /* the start address supplied by _beginthread() */ - void* arglist; /* the argument list supplied by _beginthread() */ - int terrno; /* *nix error code */ unsigned long tdoserrno; /* Win32 error code (for I/O only) */ unsigned __int64 tnext; /* used by rand/srand */ @@ -45,8 +41,7 @@ int CreateThreadData(void); void DestroyThreadData(void);
-int SetThreadData(PTHREADDATA ThreadData); -void FreeThreadData(PTHREADDATA ThreadData); +void FreeThreadData(PTHREADDATA ptd); PTHREADDATA GetThreadData(void);
#endif /* __MSVCRT_INTERNAL_TLS_H */ _____
Modified: trunk/reactos/lib/crt/misc/tls.c --- trunk/reactos/lib/crt/misc/tls.c 2006-01-13 17:32:59 UTC (rev 20834) +++ trunk/reactos/lib/crt/misc/tls.c 2006-01-13 17:54:37 UTC (rev 20835) @@ -4,7 +4,7 @@
#include <internal/rterror.h>
-static DWORD TlsIndex = TLS_OUT_OF_INDEXES; +static unsigned long TlsIndex = (unsigned long)-1;
static void InitThreadData(PTHREADDATA ThreadData) @@ -19,38 +19,40 @@ }
-int SetThreadData(PTHREADDATA ThreadData) +int CreateThreadData(void) { - if(TlsIndex == TLS_OUT_OF_INDEXES || - !TlsSetValue(TlsIndex, ThreadData)) + 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; }
-int CreateThreadData(void) -{ - TlsIndex = TlsAlloc(); - return (TlsIndex != TLS_OUT_OF_INDEXES); -} - - void DestroyThreadData(void) { - if (TlsIndex != TLS_OUT_OF_INDEXES) + if (TlsIndex != (unsigned long)-1) { TlsFree(TlsIndex); - TlsIndex = TLS_OUT_OF_INDEXES; + TlsIndex = (unsigned long)-1; } }
void FreeThreadData(PTHREADDATA ThreadData) { - if (TlsIndex != TLS_OUT_OF_INDEXES) + if (TlsIndex != (unsigned long)-1) { if (ThreadData == NULL) ThreadData = TlsGetValue(TlsIndex); @@ -82,8 +84,6 @@ TlsSetValue(TlsIndex, (LPVOID)ThreadData);
InitThreadData(ThreadData); - - ThreadData->hThread = GetCurrentThread(); } else { _____
Modified: trunk/reactos/lib/crt/process/thread.c --- trunk/reactos/lib/crt/process/thread.c 2006-01-13 17:32:59 UTC (rev 20834) +++ trunk/reactos/lib/crt/process/thread.c 2006-01-13 17:54:37 UTC (rev 20835) @@ -1,102 +1,23 @@
#include <precomp.h>
-void _endthread(void); - -static DWORD WINAPI -_beginthread_start(PVOID lpParameter) -{ - PTHREADDATA ThreadData = (PTHREADDATA)lpParameter; - - if (SetThreadData(ThreadData)) - { - /* FIXME - wrap start_address in SEH! */ - ThreadData->start_address(ThreadData->arglist); - - _endthread(); - } - else - { - /* couldn't set the thread data, free it before terminating */ - free(ThreadData); - } - - ExitThread(0); -} - - +#if 0 /* - * @implemented - * - * FIXME: the return type should be uintptr_t + * @unimplemented */ unsigned long _beginthread( void (__cdecl *start_address)(void*), unsigned stack_size, void* arglist) { - HANDLE hThread; - PTHREADDATA ThreadData; - - if (start_address == NULL) { - __set_errno(EINVAL); - return (unsigned long)-1; - } - - /* allocate the thread data structure already here instead of allocating the - thread data structure in the thread itself. this way we can pass an error - code to the caller in case we don't have sufficient resources */ - ThreadData = malloc(sizeof(THREADDATA)); - if (ThreadData == NULL) - { - __set_errno(EAGAIN); - return (unsigned long)-1; - } - - ThreadData->start_address = start_address; - ThreadData->arglist = arglist; - - hThread = CreateThread(NULL, - stack_size, - _beginthread_start, - ThreadData, - CREATE_SUSPENDED, - NULL); - if (hThread == NULL) - { - free(ThreadData); - __set_errno(EAGAIN); - return (unsigned long)-1; - } - - ThreadData->hThread = hThread; - - if (ResumeThread(hThread) == (DWORD)-1) - { - CloseHandle(hThread); - - /* freeing the ThreadData _could_ cause a crash, but only in case someone - else resumed the thread and it got to free the context before we actually - get here, but that's _very_ unlikely! */ - free(ThreadData); - __set_errno(EAGAIN); - return (unsigned long)-1; - } - - return (unsigned long)hThread; + __set_errno ( ENOSYS ); + return (unsigned long)-1; } - +#endif /* - * @implemented + * @unimplemented */ void _endthread(void) { - PTHREADDATA ThreadData = GetThreadData(); - - /* close the thread handle */ - CloseHandle(ThreadData->hThread); - - /* NOTE: the thread data will be freed in the thread detach routine that will - call FreeThreadData */ - - ExitThread(0); } + +/* EOF */ _____
Copied: trunk/reactos/lib/crt/wine/thread.c (from rev 20833, trunk/reactos/lib/crt/wine/thread.c)