Modified: trunk/reactos/ntoskrnl/include/internal/port.h
Modified: trunk/reactos/ntoskrnl/include/internal/ps.h
Modified: trunk/reactos/ntoskrnl/ke/kthread.c
Modified: trunk/reactos/ntoskrnl/ps/create.c
Modified: trunk/reactos/ntoskrnl/ps/kill.c
Modified: trunk/reactos/ntoskrnl/ps/suspend.c
Modified: trunk/reactos/ntoskrnl/ps/thread.c
--- trunk/reactos/ntoskrnl/include/internal/port.h 2005-03-18 05:53:04 UTC (rev 14174)
+++ trunk/reactos/ntoskrnl/include/internal/port.h 2005-03-18 07:19:30 UTC (rev 14175)
@@ -52,7 +52,7 @@
} EPORT_CONNECT_REPLY_MESSAGE, *PEPORT_CONNECT_REPLY_MESSAGE;
typedef struct _TERMINATION_PORT {
- LIST_ENTRY Links;
+ struct _TERMINATION_PORT *Next;
PVOID Port;
} TERMINATION_PORT, *PTERMINATION_PORT;
--- trunk/reactos/ntoskrnl/include/internal/ps.h 2005-03-18 05:53:04 UTC (rev 14174)
+++ trunk/reactos/ntoskrnl/include/internal/ps.h 2005-03-18 07:19:30 UTC (rev 14175)
@@ -156,6 +156,7 @@
#include <pshpack1.h>
+/* This needs to be fixed ASAP! */
typedef struct _ETHREAD
{
KTHREAD Tcb;
@@ -169,7 +170,10 @@
NTSTATUS ExitStatus;
PVOID OfsChain;
LIST_ENTRY PostBlockList;
- LIST_ENTRY TerminationPortList;
+ union {
+ struct _TERMINATION_PORT *TerminationPort;
+ struct _ETHREAD* ReaperLink;
+ };
KSPIN_LOCK ActiveTimerListLock;
LIST_ENTRY ActiveTimerListHead;
CLIENT_ID Cid;
--- trunk/reactos/ntoskrnl/ke/kthread.c 2005-03-18 05:53:04 UTC (rev 14174)
+++ trunk/reactos/ntoskrnl/ke/kthread.c 2005-03-18 07:19:30 UTC (rev 14175)
@@ -25,6 +25,7 @@
static ULONG PriorityListMask = 0;
ULONG IdleProcessorMask = 0;
extern BOOLEAN DoneInitYet;
+extern PETHREAD PspReaperList;
/* FUNCTIONS *****************************************************************/
@@ -331,13 +332,13 @@
PKTHREAD CurrentThread = KeGetCurrentThread();
/* Non-alertable kernel-mode suspended wait */
- DPRINT1("Waiting...\n");
+ DPRINT("Waiting...\n");
KeWaitForSingleObject(&CurrentThread->SuspendSemaphore,
Suspended,
KernelMode,
FALSE,
NULL);
- DPRINT1("Done Waiting\n");
+ DPRINT("Done Waiting\n");
}
VOID
@@ -389,7 +390,7 @@
ULONG PreviousCount;
KIRQL OldIrql;
- DPRINT1("KeResumeThread (Thread %p called). %x, %x\n", Thread, Thread->SuspendCount, Thread->FreezeCount);
+ DPRINT("KeResumeThread (Thread %p called). %x, %x\n", Thread, Thread->SuspendCount, Thread->FreezeCount);
/* Lock the Dispatcher */
OldIrql = KeAcquireDispatcherDatabaseLock();
@@ -428,7 +429,7 @@
ULONG PreviousCount;
KIRQL OldIrql;
- DPRINT1("KeSuspendThread (Thread %p called). %x, %x\n", Thread, Thread->SuspendCount, Thread->FreezeCount);
+ DPRINT("KeSuspendThread (Thread %p called). %x, %x\n", Thread, Thread->SuspendCount, Thread->FreezeCount);
/* Lock the Dispatcher */
OldIrql = KeAcquireDispatcherDatabaseLock();
@@ -802,6 +803,7 @@
/* Set up the Suspend Counts */
Thread->FreezeCount = 0;
Thread->SuspendCount = 0;
+ ((PETHREAD)Thread)->ReaperLink = NULL; /* Union. Will also clear termination port */
/* Do x86 specific part */
}
@@ -1194,18 +1196,21 @@
PKTHREAD Thread = KeGetCurrentThread();
/* Lock the Dispatcher Database and the APC Queue */
- DPRINT1("Terminating\n");
+ DPRINT("Terminating\n");
OldIrql = KeAcquireDispatcherDatabaseLock();
/* Insert into the Reaper List */
- InsertTailList(&PspReaperListHead, &((PETHREAD)Thread)->TerminationPortList);
+ DPRINT("List: %p\n", PspReaperList);
+ ((PETHREAD)Thread)->ReaperLink = PspReaperList;
+ PspReaperList = (PETHREAD)Thread;
+ DPRINT("List: %p\n", PspReaperList);
/* Check if it's active */
if (PspReaping == FALSE) {
/* Activate it. We use the internal function for speed, and use the Hyper Critical Queue */
PspReaping = TRUE;
- DPRINT1("Terminating\n");
+ DPRINT("Terminating\n");
KiInsertQueue(&ExWorkerQueue[HyperCriticalWorkQueue].WorkerQueue,
&PspReaperWorkItem.List,
FALSE);
@@ -1214,7 +1219,7 @@
/* Handle Kernel Queues */
if (Thread->Queue) {
- DPRINT1("Waking Queue\n");
+ DPRINT("Waking Queue\n");
RemoveEntryList(&Thread->QueueListEntry);
KiWakeQueue(Thread->Queue);
}
--- trunk/reactos/ntoskrnl/ps/create.c 2005-03-18 05:53:04 UTC (rev 14174)
+++ trunk/reactos/ntoskrnl/ps/create.c 2005-03-18 07:19:30 UTC (rev 14175)
@@ -93,7 +93,6 @@
DPRINT("Thread = %x\n",Thread);
KeInitializeThread(&Process->Pcb, &Thread->Tcb, First);
- InitializeListHead(&Thread->TerminationPortList);
InitializeListHead(&Thread->ActiveTimerListHead);
KeInitializeSpinLock(&Thread->ActiveTimerListLock);
InitializeListHead(&Thread->IrpList);
--- trunk/reactos/ntoskrnl/ps/kill.c 2005-03-18 05:53:04 UTC (rev 14174)
+++ trunk/reactos/ntoskrnl/ps/kill.c 2005-03-18 07:19:30 UTC (rev 14175)
@@ -18,7 +18,7 @@
#define TAG_TERMINATE_APC TAG('T', 'A', 'P', 'C')
-LIST_ENTRY PspReaperListHead;
+PETHREAD PspReaperList = NULL;
WORK_QUEUE_ITEM PspReaperWorkItem;
BOOLEAN PspReaping = FALSE;
extern LIST_ENTRY PsActiveProcessHead;
@@ -31,30 +31,51 @@
PspReapRoutine(PVOID Context)
{
KIRQL OldIrql;
- PETHREAD Thread;
- PLIST_ENTRY ListEntry;
+ PETHREAD Thread, NewThread;
/* Acquire lock */
DPRINT("Evil reaper running!!\n");
OldIrql = KeAcquireDispatcherDatabaseLock();
- /* Loop the reap list */
- while((ListEntry = RemoveHeadList(&PspReaperListHead)) != &PspReaperListHead) {
+ /* Get the first Thread Entry */
+ Thread = PspReaperList;
+ PspReaperList = NULL;
+ DPRINT("PspReaperList: %x\n", Thread);
+
+ /* Check to see if the list is empty */
+ do {
- /* Get the Current Thread to Terminate */
- Thread = CONTAINING_RECORD(ListEntry, ETHREAD, TerminationPortList);
-
/* Unlock the Dispatcher */
KeReleaseDispatcherDatabaseLock(OldIrql);
-
- /* Remove the Reference */
- ObDereferenceObject(Thread);
- /* Reacquire the Lock */
+ /* Is there a thread on the list? */
+ while (Thread) {
+
+ /* Get the next Thread */
+ DPRINT("Thread: %x\n", Thread);
+ DPRINT("Thread: %x\n", Thread->ReaperLink);
+ NewThread = Thread->ReaperLink;
+
+ /* Remove reference to current thread */
+ ObDereferenceObject(Thread);
+
+ /* Move to next Thread */
+ Thread = NewThread;
+ }
+
+ /* No more linked threads... Reacquire the Lock */
OldIrql = KeAcquireDispatcherDatabaseLock();
- }
+
+ /* Now try to get a new thread from the list */
+ Thread = PspReaperList;
+ PspReaperList = NULL;
+ DPRINT("PspReaperList: %x\n", Thread);
+
+ /* Loop again if there is a new thread */
+ } while (Thread);
PspReaping = FALSE;
+ DPRINT("Done reaping\n");
KeReleaseDispatcherDatabaseLock(OldIrql);
}
@@ -158,7 +179,6 @@
PEPROCESS CurrentProcess;
SIZE_T Length = PAGE_SIZE;
PVOID TebBlock;
- PLIST_ENTRY CurrentEntry;
PTERMINATION_PORT TerminationPort;
DPRINT("PsTerminateCurrentThread(ExitStatus %x)\n", ExitStatus);
@@ -204,19 +224,19 @@
}
/* Process the Termination Ports */
- while ((CurrentEntry = RemoveHeadList(&CurrentThread->TerminationPortList)) !=
- &CurrentThread->TerminationPortList) {
+ TerminationPort = CurrentThread->TerminationPort;
+ DPRINT("TerminationPort: %p\n", TerminationPort);
+ while (TerminationPort) {
- /* Get the Termination Port */
- TerminationPort = CONTAINING_RECORD(CurrentEntry,
- TERMINATION_PORT,
- Links);
-
/* Send the LPC Message */
LpcSendTerminationPort(TerminationPort->Port, CurrentThread->CreateTime);
/* Free the Port */
ExFreePool(TerminationPort);
+
+ /* Get the next one */
+ TerminationPort = TerminationPort->Next;
+ DPRINT("TerminationPort: %p\n", TerminationPort);
}
/* Rundown Win32 Structures */
@@ -508,6 +528,7 @@
NTSTATUS Status;
PTERMINATION_PORT TerminationPort;
PVOID TerminationLpcPort;
+ PETHREAD Thread;
PAGED_CODE();
@@ -530,8 +551,12 @@
TAG('P', 's', 'T', '=')))) {
/* Associate the Port */
+ Thread = PsGetCurrentThread();
TerminationPort->Port = TerminationLpcPort;
- InsertTailList(&PsGetCurrentThread()->TerminationPortList, &TerminationPort->Links);
+ DPRINT("TerminationPort: %p\n", TerminationPort);
+ TerminationPort->Next = Thread->TerminationPort;
+ Thread->TerminationPort = TerminationPort;
+ DPRINT("TerminationPort: %p\n", Thread->TerminationPort);
/* Return success */
return(STATUS_SUCCESS);
--- trunk/reactos/ntoskrnl/ps/suspend.c 2005-03-18 05:53:04 UTC (rev 14174)
+++ trunk/reactos/ntoskrnl/ps/suspend.c 2005-03-18 07:19:30 UTC (rev 14175)
@@ -40,8 +40,8 @@
PAGED_CODE();
- DPRINT1("NtResumeThead(ThreadHandle %lx SuspendCount %p)\n",
- ThreadHandle, SuspendCount);
+ DPRINT("NtResumeThead(ThreadHandle %lx SuspendCount %p)\n",
+ ThreadHandle, SuspendCount);
/* Get the Thread Object */
Status = ObReferenceObjectByHandle(ThreadHandle,
--- trunk/reactos/ntoskrnl/ps/thread.c 2005-03-18 05:53:04 UTC (rev 14174)
+++ trunk/reactos/ntoskrnl/ps/thread.c 2005-03-18 07:19:30 UTC (rev 14175)
@@ -473,7 +473,6 @@
DoneInitYet = TRUE;
- InitializeListHead(&PspReaperListHead);
ExInitializeWorkItem(&PspReaperWorkItem, PspReapRoutine, NULL);
}