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 * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -444,7 +444,7 @@ static NTSTATUS PsCreateTeb (HANDLE ProcessHandle,
{ {
Teb.Peb = Thread->ThreadsProcess->Peb; /* No PEB yet!! */ 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 */ /* store stack information from InitialTeb */
if (InitialTeb != NULL) if (InitialTeb != NULL)
@ -494,7 +494,7 @@ static NTSTATUS PsCreateTeb (HANDLE ProcessHandle,
*TebPtr = (PNT_TEB)TebBase; *TebPtr = (PNT_TEB)TebBase;
} }
// DPRINT1 ("TEB allocated at %p\n", TebBase); DPRINT("TEB allocated at %p\n", TebBase);
return Status; return Status;
} }
@ -589,7 +589,7 @@ NTSTATUS STDCALL NtCreateThread (PHANDLE ThreadHandle,
if (!CreateSuspended) if (!CreateSuspended)
{ {
DPRINT("Not creating suspended\n"); DPRINT("Not creating suspended\n");
PsUnfreezeThread(Thread, NULL); PsResumeThread(Thread);
} }
DPRINT("Thread %x\n", Thread); DPRINT("Thread %x\n", Thread);
DPRINT("ObGetReferenceCount(Thread) %d ObGetHandleCount(Thread) %x\n", DPRINT("ObGetReferenceCount(Thread) %d ObGetHandleCount(Thread) %x\n",
@ -648,8 +648,9 @@ NTSTATUS STDCALL PsCreateSystemThread(PHANDLE ThreadHandle,
*ClientId=Thread->Cid; *ClientId=Thread->Cid;
} }
PsUnfreezeThread(Thread, NULL); PsResumeThread(Thread);
return(STATUS_SUCCESS); 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 * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -306,6 +306,52 @@ ULONG PsFreezeThread(PETHREAD Thread,
return(r); 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) VOID PsInitThreadManagment(VOID)
/* /*
* FUNCTION: Initialize thread managment * FUNCTION: Initialize thread managment
@ -450,12 +496,35 @@ NTSTATUS STDCALL NtResumeThread (IN HANDLE ThreadHandle,
* ResumeCount = The resulting resume count. * ResumeCount = The resulting resume count.
* REMARK: * REMARK:
* A thread is resumed if its suspend count is 0. This procedure maps to * 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 * RETURNS: Status
*/ */
{ {
UNIMPLEMENTED; PETHREAD Thread;
return(STATUS_UNSUCCESSFUL); 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 * RETURNS: Status
*/ */
{ {
UNIMPLEMENTED; PETHREAD Thread;
return(STATUS_UNSUCCESSFUL); 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;
} }