Author: dchapyshev Date: Fri Jul 17 20:42:12 2009 New Revision: 42012
URL: http://svn.reactos.org/svn/reactos?rev=42012&view=rev Log: - Samplify SwitchToThread and QueueUserWorkItem - Remove unneeded InternalWorkItemTrampoline function and QUEUE_USER_WORKITEM_CONTEXT structure - Other small changes
Modified: trunk/reactos/dll/win32/kernel32/thread/thread.c
Modified: trunk/reactos/dll/win32/kernel32/thread/thread.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/thread/t... ============================================================================== --- trunk/reactos/dll/win32/kernel32/thread/thread.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/kernel32/thread/thread.c [iso-8859-1] Fri Jul 17 20:42:12 2009 @@ -263,13 +263,13 @@ BOOL bInheritHandle, DWORD dwThreadId) { - NTSTATUS errCode; + NTSTATUS Status; HANDLE ThreadHandle; OBJECT_ATTRIBUTES ObjectAttributes; CLIENT_ID ClientId ;
ClientId.UniqueProcess = 0; - ClientId.UniqueThread = (HANDLE)dwThreadId; + ClientId.UniqueThread = ULongToHandle(dwThreadId);
InitializeObjectAttributes(&ObjectAttributes, NULL, @@ -277,13 +277,13 @@ NULL, NULL);
- errCode = NtOpenThread(&ThreadHandle, - dwDesiredAccess, - &ObjectAttributes, - &ClientId); - if (!NT_SUCCESS(errCode)) - { - SetLastErrorByStatus (errCode); + Status = NtOpenThread(&ThreadHandle, + dwDesiredAccess, + &ObjectAttributes, + &ClientId); + if (!NT_SUCCESS(Status)) + { + SetLastErrorByStatus(Status); return NULL; }
@@ -306,9 +306,7 @@ WINAPI SwitchToThread(VOID) { - NTSTATUS Status; - Status = NtYieldExecution(); - return Status != STATUS_NO_YIELD_PERFORMED; + return NtYieldExecution() != STATUS_NO_YIELD_PERFORMED; }
@@ -750,10 +748,10 @@ * @unimplemented */ LANGID WINAPI -SetThreadUILanguage(WORD wReserved) -{ - DPRINT1("SetThreadUILanguage(0x%4x) unimplemented!\n", wReserved); - return 0; +SetThreadUILanguage(LANGID LangId) +{ + DPRINT1("SetThreadUILanguage(0x%4x) unimplemented!\n", LangId); + return LangId; }
static void CALLBACK @@ -773,10 +771,13 @@
Status = NtQueueApcThread(hThread, IntCallUserApc, pfnAPC, (PVOID)dwData, NULL); - if (Status) + if (!NT_SUCCESS(Status)) + { SetLastErrorByStatus(Status); - - return NT_SUCCESS(Status); + return 0; + } + + return 1; }
/* @@ -853,34 +854,6 @@ }
-typedef struct _QUEUE_USER_WORKITEM_CONTEXT -{ - LPTHREAD_START_ROUTINE Function; - PVOID Context; -} QUEUE_USER_WORKITEM_CONTEXT, *PQUEUE_USER_WORKITEM_CONTEXT; - -static VOID -NTAPI -InternalWorkItemTrampoline(PVOID Context) -{ - QUEUE_USER_WORKITEM_CONTEXT Info; - - ASSERT(Context); - - /* Save the context to the stack */ - Info = *(volatile QUEUE_USER_WORKITEM_CONTEXT *)Context; - - /* Free the context before calling the callback. This avoids - a memory leak in case the thread dies... */ - RtlFreeHeap(RtlGetProcessHeap(), - 0, - Context); - - /* Call the real callback */ - Info.Function(Info.Context); -} - - /* * @implemented */ @@ -892,34 +865,13 @@ ULONG Flags ) { - PQUEUE_USER_WORKITEM_CONTEXT WorkItemContext; - NTSTATUS Status; - - /* Save the context for the trampoline function */ - WorkItemContext = RtlAllocateHeap(RtlGetProcessHeap(), - 0, - sizeof(*WorkItemContext)); - if (WorkItemContext == NULL) - { - SetLastError(ERROR_NOT_ENOUGH_MEMORY); - return FALSE; - } - - WorkItemContext->Function = Function; - WorkItemContext->Context = Context; - - /* NOTE: Don't use Function directly since the callback signature - differs. This might cause problems on certain platforms... */ - Status = RtlQueueWorkItem(InternalWorkItemTrampoline, - WorkItemContext, + NTSTATUS Status; + + Status = RtlQueueWorkItem((WORKERCALLBACKFUNC)Function, + Context, Flags); if (!NT_SUCCESS(Status)) { - /* Free the allocated context in case of failure */ - RtlFreeHeap(RtlGetProcessHeap(), - 0, - WorkItemContext); - SetLastErrorByStatus(Status); return FALSE; } @@ -942,16 +894,16 @@ ULONG dwFlags ) { - NTSTATUS Status = RtlRegisterWait( phNewWaitObject, - hObject, - Callback, - Context, - dwMilliseconds, - dwFlags ); - - if (Status != STATUS_SUCCESS) - { - SetLastError( RtlNtStatusToDosError(Status) ); + NTSTATUS Status = RtlRegisterWait(phNewWaitObject, + hObject, + Callback, + Context, + dwMilliseconds, + dwFlags); + + if (!NT_SUCCESS(Status)) + { + SetLastErrorByStatus(Status); return FALSE; } return TRUE; @@ -974,18 +926,19 @@ NTSTATUS Status; HANDLE hNewWaitObject;
- Status = RtlRegisterWait( &hNewWaitObject, - hObject, - Callback, - Context, - dwMilliseconds, - dwFlags ); - - if (Status != STATUS_SUCCESS) - { - SetLastError( RtlNtStatusToDosError(Status) ); + Status = RtlRegisterWait(&hNewWaitObject, + hObject, + Callback, + Context, + dwMilliseconds, + dwFlags); + + if (!NT_SUCCESS(Status)) + { + SetLastErrorByStatus(Status); return NULL; } + return hNewWaitObject; }
@@ -999,12 +952,14 @@ HANDLE WaitHandle ) { - NTSTATUS Status = RtlDeregisterWaitEx( WaitHandle, NULL ); - if (Status != STATUS_SUCCESS) - { - SetLastError( RtlNtStatusToDosError(Status) ); - return FALSE; - } + NTSTATUS Status = RtlDeregisterWaitEx(WaitHandle, NULL); + + if (!NT_SUCCESS(Status)) + { + SetLastErrorByStatus(Status); + return FALSE; + } + return TRUE; }
@@ -1019,12 +974,14 @@ HANDLE CompletionEvent ) { - NTSTATUS Status = RtlDeregisterWaitEx( WaitHandle, CompletionEvent ); - if (Status != STATUS_SUCCESS) - { - SetLastError( RtlNtStatusToDosError(Status) ); - return FALSE; - } + NTSTATUS Status = RtlDeregisterWaitEx(WaitHandle, CompletionEvent); + + if (!NT_SUCCESS(Status)) + { + SetLastErrorByStatus(Status); + return FALSE; + } + return TRUE; }