Sync to trunk head (r42241)
[reactos.git] / reactos / dll / win32 / kernel32 / thread / thread.c
index 62c9889..cb5dab7 100644 (file)
@@ -263,13 +263,13 @@ OpenThread(DWORD dwDesiredAccess,
            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 @@ OpenThread(DWORD dwDesiredAccess,
                                NULL,
                                NULL);
 
-    errCode = NtOpenThread(&ThreadHandle,
-                           dwDesiredAccess,
-                           &ObjectAttributes,
-                           &ClientId);
-    if (!NT_SUCCESS(errCode))
+    Status = NtOpenThread(&ThreadHandle,
+                          dwDesiredAccess,
+                          &ObjectAttributes,
+                          &ClientId);
+    if (!NT_SUCCESS(Status))
     {
-        SetLastErrorByStatus (errCode);
+        SetLastErrorByStatus(Status);
         return NULL;
     }
 
@@ -306,9 +306,7 @@ BOOL
 WINAPI
 SwitchToThread(VOID)
 {
-    NTSTATUS Status;
-    Status = NtYieldExecution();
-    return Status != STATUS_NO_YIELD_PERFORMED;
+    return NtYieldExecution() != STATUS_NO_YIELD_PERFORMED;
 }
 
 
@@ -755,10 +753,10 @@ GetThreadId(HANDLE Thread)
  * @unimplemented
  */
 LANGID WINAPI
-SetThreadUILanguage(WORD wReserved)
+SetThreadUILanguage(LANGID LangId)
 {
-  DPRINT1("SetThreadUILanguage(0x%4x) unimplemented!\n", wReserved);
-  return 0;
+  DPRINT1("SetThreadUILanguage(0x%4x) unimplemented!\n", LangId);
+  return LangId;
 }
 
 static void CALLBACK
@@ -778,10 +776,13 @@ QueueUserAPC(PAPCFUNC pfnAPC, HANDLE hThread, ULONG_PTR dwData)
 
   Status = NtQueueApcThread(hThread, IntCallUserApc, pfnAPC,
                             (PVOID)dwData, NULL);
-  if (Status)
+  if (!NT_SUCCESS(Status))
+  {
     SetLastErrorByStatus(Status);
+    return 0;
+  }
 
-  return NT_SUCCESS(Status);
+  return 1;
 }
 
 /*
@@ -947,16 +948,16 @@ RegisterWaitForSingleObject(
     ULONG dwFlags
     )
 {
-    NTSTATUS Status = RtlRegisterWait( phNewWaitObject,
-                                       hObject,
-                                       Callback,
-                                       Context,
-                                       dwMilliseconds,
-                                       dwFlags );
-
-    if (Status != STATUS_SUCCESS)
+    NTSTATUS Status = RtlRegisterWait(phNewWaitObject,
+                                      hObject,
+                                      Callback,
+                                      Context,
+                                      dwMilliseconds,
+                                      dwFlags);
+
+    if (!NT_SUCCESS(Status))
     {
-        SetLastError( RtlNtStatusToDosError(Status) );
+        SetLastErrorByStatus(Status);
         return FALSE;
     }
     return TRUE;
@@ -979,18 +980,19 @@ RegisterWaitForSingleObjectEx(
     NTSTATUS Status;
     HANDLE hNewWaitObject;
 
-    Status = RtlRegisterWait( &hNewWaitObject,
-                               hObject,
-                               Callback,
-                               Context,
-                               dwMilliseconds,
-                               dwFlags );
+    Status = RtlRegisterWait(&hNewWaitObject,
+                             hObject,
+                             Callback,
+                             Context,
+                             dwMilliseconds,
+                             dwFlags);
 
-    if (Status != STATUS_SUCCESS)
+    if (!NT_SUCCESS(Status))
     {
-        SetLastError( RtlNtStatusToDosError(Status) );
+        SetLastErrorByStatus(Status);
         return NULL;
     }
+
     return hNewWaitObject;
 }
 
@@ -1004,12 +1006,14 @@ UnregisterWait(
     HANDLE WaitHandle
     )
 {
-    NTSTATUS Status = RtlDeregisterWaitEx( WaitHandle, NULL );
-    if (Status != STATUS_SUCCESS)
+    NTSTATUS Status = RtlDeregisterWaitEx(WaitHandle, NULL);
+
+    if (!NT_SUCCESS(Status))
     {
-        SetLastError( RtlNtStatusToDosError(Status) );
+        SetLastErrorByStatus(Status);
         return FALSE;
     }
+
     return TRUE;
 }
 
@@ -1024,12 +1028,14 @@ UnregisterWaitEx(
     HANDLE CompletionEvent
     )
 {
-    NTSTATUS Status = RtlDeregisterWaitEx( WaitHandle, CompletionEvent );
-    if (Status != STATUS_SUCCESS)
+    NTSTATUS Status = RtlDeregisterWaitEx(WaitHandle, CompletionEvent);
+
+    if (!NT_SUCCESS(Status))
     {
-        SetLastError( RtlNtStatusToDosError(Status) );
+        SetLastErrorByStatus(Status);
         return FALSE;
     }
+
     return TRUE;
 }