Implemented NtResumeThread() and NtSuspendThread()
authorEric Kohl <eric.kohl@reactos.org>
Fri, 22 Dec 2000 13:37:41 +0000 (13:37 +0000)
committerEric Kohl <eric.kohl@reactos.org>
Fri, 22 Dec 2000 13:37:41 +0000 (13:37 +0000)
Cleanup

svn path=/trunk/; revision=1473

reactos/ntoskrnl/ps/create.c
reactos/ntoskrnl/ps/thread.c

index 1f0fbb3..d71e30c 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: create.c,v 1.24 2000/10/22 16:36:53 ekohl Exp $
+/* $Id: create.c,v 1.25 2000/12/22 13:37:41 ekohl Exp $
  *
  * COPYRIGHT:              See COPYING in the top level directory
  * PROJECT:                ReactOS kernel
@@ -444,7 +444,7 @@ static NTSTATUS PsCreateTeb (HANDLE ProcessHandle,
      {
         Teb.Peb = Thread->ThreadsProcess->Peb; /* No PEB yet!! */
      }
-//   DPRINT1("Teb.Peb %x\n", Teb.Peb);
+   DPRINT("Teb.Peb %x\n", Teb.Peb);
    
    /* store stack information from InitialTeb */
    if (InitialTeb != NULL)
@@ -494,13 +494,13 @@ static NTSTATUS PsCreateTeb (HANDLE ProcessHandle,
         *TebPtr = (PNT_TEB)TebBase;
      }
 
-//   DPRINT1 ("TEB allocated at %p\n", TebBase);
+   DPRINT("TEB allocated at %p\n", TebBase);
 
    return Status;
 }
 
 
-NTSTATUS STDCALL NtCreateThread (PHANDLE                       ThreadHandle,
+NTSTATUS STDCALL NtCreateThread (PHANDLE               ThreadHandle,
                                 ACCESS_MASK            DesiredAccess,
                                 POBJECT_ATTRIBUTES     ObjectAttributes,
                                 HANDLE                 ProcessHandle,
@@ -588,8 +588,8 @@ NTSTATUS STDCALL NtCreateThread (PHANDLE                    ThreadHandle,
    
    if (!CreateSuspended)
      {
-        DPRINT("Not creating suspended\n");
-       PsUnfreezeThread(Thread, NULL);
+       DPRINT("Not creating suspended\n");
+       PsResumeThread(Thread);
      }
    DPRINT("Thread %x\n", Thread);
    DPRINT("ObGetReferenceCount(Thread) %d ObGetHandleCount(Thread) %x\n",
@@ -648,8 +648,9 @@ NTSTATUS STDCALL PsCreateSystemThread(PHANDLE ThreadHandle,
        *ClientId=Thread->Cid;
      }  
 
-   PsUnfreezeThread(Thread, NULL);
+   PsResumeThread(Thread);
    
    return(STATUS_SUCCESS);
 }
 
+/* EOF */
index 78ad8ef..c2c1fb8 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: thread.c,v 1.60 2000/12/10 23:42:01 dwelch Exp $
+/* $Id: thread.c,v 1.61 2000/12/22 13:37:41 ekohl Exp $
  *
  * COPYRIGHT:              See COPYING in the top level directory
  * PROJECT:                ReactOS kernel
@@ -306,6 +306,52 @@ ULONG PsFreezeThread(PETHREAD Thread,
    return(r);
 }
 
+ULONG PsResumeThread(PETHREAD Thread)
+{
+   KIRQL oldIrql;
+   ULONG SuspendCount;
+
+   KeAcquireSpinLock(&PiThreadListLock, &oldIrql);
+
+   if (Thread->Tcb.SuspendCount > 0)
+     {
+       Thread->Tcb.SuspendCount--;
+       SuspendCount = Thread->Tcb.SuspendCount;
+       Thread->Tcb.State = THREAD_STATE_RUNNABLE;
+       PsInsertIntoThreadList(Thread->Tcb.Priority, Thread);
+     }
+
+   KeReleaseSpinLock(&PiThreadListLock, oldIrql);
+
+   return SuspendCount;
+}
+
+ULONG PsSuspendThread(PETHREAD Thread)
+{
+   KIRQL oldIrql;
+   ULONG PreviousSuspendCount;
+
+   KeAcquireSpinLock(&PiThreadListLock, &oldIrql);
+
+   PreviousSuspendCount = Thread->Tcb.SuspendCount;
+   if (Thread->Tcb.SuspendCount < MAXIMUM_SUSPEND_COUNT)
+     {
+       Thread->Tcb.SuspendCount++;
+     }
+
+   if (PsGetCurrentThread() == Thread)
+     {
+       DbgPrint("Cannot suspend self\n");
+       KeBugCheck(0);
+     }
+
+   Thread->Tcb.State = THREAD_STATE_SUSPENDED;
+
+   KeReleaseSpinLock(&PiThreadListLock, oldIrql);
+
+   return PreviousSuspendCount;
+}
+
 VOID PsInitThreadManagment(VOID)
 /*
  * FUNCTION: Initialize thread managment
@@ -430,7 +476,7 @@ NTSTATUS STDCALL NtAlertThread (IN HANDLE ThreadHandle)
    (VOID)PsUnfreezeThread(Thread, &ThreadStatus);
    
    ObDereferenceObject(Thread);
-   return(STATUS_SUCCESS);   
+   return(STATUS_SUCCESS);
 }
 
 NTSTATUS STDCALL NtOpenThread(OUT      PHANDLE ThreadHandle,
@@ -449,13 +495,36 @@ NTSTATUS STDCALL NtResumeThread (IN       HANDLE  ThreadHandle,
  *        ThreadHandle = Handle to the thread that should be resumed
  *        ResumeCount =  The resulting resume count.
  * REMARK:
- *       A thread is resumed if its suspend count is 0. This procedure maps to
- *        the win32 ResumeThread function. ( documentation about the the suspend count can be found here aswell )
+ *        A thread is resumed if its suspend count is 0. This procedure maps to
+ *        the win32 ResumeThread function. ( documentation about the the suspend
+ *        count can be found here aswell )
  * RETURNS: Status
  */
 {
-   UNIMPLEMENTED;
-   return(STATUS_UNSUCCESSFUL);
+   PETHREAD Thread;
+   NTSTATUS Status;
+   ULONG Count;
+
+   Status = ObReferenceObjectByHandle(ThreadHandle,
+                                     THREAD_SUSPEND_RESUME,
+                                     PsThreadType,
+                                     UserMode,
+                                     (PVOID*)&Thread,
+                                     NULL);
+   if (!NT_SUCCESS(Status))
+     {
+       return(Status);
+     }
+
+   Count = PsResumeThread(Thread);
+   if (SuspendCount != NULL)
+     {
+       *SuspendCount = Count;
+     }
+
+   ObDereferenceObject((PVOID)Thread);
+
+   return STATUS_SUCCESS;
 }
 
 
@@ -467,7 +536,7 @@ NTSTATUS STDCALL NtSuspendThread (IN HANDLE ThreadHandle,
  *        ThreadHandle = Handle to the thread that should be resumed
  *        PreviousSuspendCount =  The resulting/previous suspend count.
  * REMARK:
- *       A thread will be suspended if its suspend count is greater than 0. 
+ *        A thread will be suspended if its suspend count is greater than 0. 
  *        This procedure maps to the win32 SuspendThread function. ( 
  *        documentation about the the suspend count can be found here aswell )
  *        The suspend count is not increased if it is greater than 
@@ -475,8 +544,30 @@ NTSTATUS STDCALL NtSuspendThread (IN HANDLE ThreadHandle,
  * RETURNS: Status
  */ 
 {
-   UNIMPLEMENTED;
-   return(STATUS_UNSUCCESSFUL);
+   PETHREAD Thread;
+   NTSTATUS Status;
+   ULONG Count;
+
+   Status = ObReferenceObjectByHandle(ThreadHandle,
+                                     THREAD_SUSPEND_RESUME,
+                                     PsThreadType,
+                                     UserMode,
+                                     (PVOID*)&Thread,
+                                     NULL);
+   if (!NT_SUCCESS(Status))
+     {
+       return(Status);
+     }
+
+   Count = PsSuspendThread(Thread);
+   if (PreviousSuspendCount != NULL)
+     {
+       *PreviousSuspendCount = Count;
+     }
+
+   ObDereferenceObject((PVOID)Thread);
+
+   return STATUS_SUCCESS;
 }
 
 
@@ -490,14 +581,14 @@ NTSTATUS STDCALL NtContinue(IN PCONTEXT   Context,
      {
        DbgPrint("NtContinue called but TrapFrame was NULL\n");
        KeBugCheck(0);
-     }   
+     }
    KeContextToTrapFrame(Context, TrapFrame);
    return(STATUS_SUCCESS);
 }
 
 
 NTSTATUS STDCALL NtYieldExecution(VOID)
-{ 
+{
    PsDispatchThread(THREAD_STATE_RUNNABLE);
    return(STATUS_SUCCESS);
 }