Implemented NtResumeThread() and NtSuspendThread()

Cleanup

svn path=/trunk/; revision=1473
This commit is contained in:
Eric Kohl 2000-12-22 13:37:41 +00:00
parent 64ba922c19
commit 91bcb7413f
2 changed files with 110 additions and 18 deletions

View 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,7 +494,7 @@ 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;
}
@ -589,7 +589,7 @@ NTSTATUS STDCALL NtCreateThread (PHANDLE ThreadHandle,
if (!CreateSuspended)
{
DPRINT("Not creating suspended\n");
PsUnfreezeThread(Thread, NULL);
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 */

View 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
@ -450,12 +496,35 @@ NTSTATUS STDCALL NtResumeThread (IN HANDLE ThreadHandle,
* 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 )
* 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;
}
@ -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;
}