Added tracking of running threads in a process, and termination of process when all threads terminate

svn path=/trunk/; revision=888
This commit is contained in:
Phillip Susi 1999-12-18 07:33:53 +00:00
parent 4e94397e24
commit bfaef27782
3 changed files with 20 additions and 4 deletions

View file

@ -1,4 +1,4 @@
/* $Id: create.c,v 1.2 1999/12/14 18:35:19 phreak Exp $
/* $Id: create.c,v 1.3 1999/12/18 07:33:53 phreak Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -150,7 +150,7 @@ NTSTATUS PsInitializeThread(HANDLE ProcessHandle,
Thread->ThreadsProcess = Process;
KeInitializeDpc( &Thread->Tcb.TimerDpc, PiTimeoutThread, Thread );
Thread->Tcb.WaitBlockList = NULL;
InsertTailList( &Thread->ThreadsProcess->Pcb.ThreadListHead, &Thread->Tcb.ProcessThreadListEntry );
KeInitializeDispatcherHeader(&Thread->Tcb.DispatcherHeader,
InternalThreadType,
sizeof(ETHREAD),

View file

@ -117,6 +117,7 @@ VOID PsInitProcessManagment(VOID)
KeAcquireSpinLock(&PsProcessListLock, &oldIrql);
InsertHeadList(&PsProcessListHead, &KProcess->ProcessListEntry);
InitializeListHead( &KProcess->ThreadListHead );
KeReleaseSpinLock(&PsProcessListLock, oldIrql);
ObCreateHandle(SystemProcess,
@ -278,6 +279,7 @@ NtCreateProcess (
KeAcquireSpinLock(&PsProcessListLock, &oldIrql);
InsertHeadList(&PsProcessListHead, &KProcess->ProcessListEntry);
InitializeListHead( &KProcess->ThreadListHead );
KeReleaseSpinLock(&PsProcessListLock, oldIrql);
Status = PsCreatePeb (*ProcessHandle);

View file

@ -1,4 +1,4 @@
/* $Id: thread.c,v 1.42 1999/12/16 22:59:03 phreak Exp $
/* $Id: thread.c,v 1.43 1999/12/18 07:33:53 phreak Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -161,11 +161,25 @@ VOID PsReapThreads(VOID)
if (current->Tcb.State == THREAD_STATE_TERMINATED_1)
{
PEPROCESS Process = current->ThreadsProcess;
NTSTATUS Status = current->ExitStatus;
ObReferenceObjectByPointer( Process, 0, PsProcessType, KernelMode );
DPRINT("Reaping thread %x\n", current);
current->Tcb.State = THREAD_STATE_TERMINATED_2;
RemoveEntryList( &current->Tcb.ProcessThreadListEntry );
KeReleaseSpinLock(&PiThreadListLock, oldIrql);
ObDereferenceObject(current);
KeAcquireSpinLock(&PiThreadListLock, &oldIrql);
if( IsListEmpty( &Process->Pcb.ThreadListHead ) )
{
//TODO: Optimize this so it doesnt jerk the IRQL around so much :)
DPRINT( "Last thread terminated, terminating process\n" );
KeReleaseSpinLock(&PiThreadListLock, oldIrql);
PiTerminateProcess( Process, Status );
KeAcquireSpinLock(&PiThreadListLock, &oldIrql);
}
ObDereferenceObject( Process );
current_entry = PiThreadListHead.Flink;
}
}