/*
* COPYRIGHT: See COPYING in the top level directory
- * PROJECT: ReactOS CSR SubSystem
- * FILE: subsystems/win32/csrss/csrsrv/thredsup.c
+ * PROJECT: ReactOS Client/Server Runtime SubSystem
+ * FILE: subsystems/win32/csrsrv/thredsup.c
* PURPOSE: CSR Server DLL Thread Management
* PROGRAMMERS: ReactOS Portable Systems Group
* Alex Ionescu (alex@relsoft.net)
/* Allocate the structure */
CsrThread = RtlAllocateHeap(CsrHeap, HEAP_ZERO_MEMORY, sizeof(CSR_THREAD));
- if (!CsrThread) return(NULL);
+ if (!CsrThread) return NULL;
/* Reference the Thread and Process */
- CsrThread->ReferenceCount++;
- CsrProcess->ReferenceCount++;
+ CsrLockedReferenceThread(CsrThread);
+ CsrLockedReferenceProcess(CsrProcess);
/* Set the Parent Process */
CsrThread->Process = CsrProcess;
/* Get the thread */
FoundThread = CONTAINING_RECORD(NextEntry, CSR_THREAD, HashLinks);
+ /* Move to the next entry */
+ NextEntry = NextEntry->Flink;
+
/* Compare the CID */
- // FIXME: if (*(PULONGLONG)&FoundThread->ClientId == *(PULONGLONG)ClientId)
- if (FoundThread->ClientId.UniqueThread == ClientId->UniqueThread)
+ // if (*(PULONGLONG)&FoundThread->ClientId == *(PULONGLONG)ClientId)
+ if ( FoundThread->ClientId.UniqueProcess == ClientId->UniqueProcess &&
+ FoundThread->ClientId.UniqueThread == ClientId->UniqueThread )
{
/* Match found, return the process */
*Process = FoundThread->Process;
// DPRINT1("Found: %p %p\n", FoundThread, FoundThread->Process);
return FoundThread;
}
-
- /* Next */
- NextEntry = NextEntry->Flink;
}
/* Nothing found */
/* Check for TID Match */
if (FoundThread->ClientId.UniqueThread == Cid->UniqueThread) break;
- /* Next entry */
+ /* Move to the next entry */
NextEntry = NextEntry->Flink;
}
if (!LockCount)
{
/* Call the generic cleanup code */
- CsrThreadRefcountZero(CsrThread);
CsrAcquireProcessLock();
+ CsrThreadRefcountZero(CsrThread);
}
}
}
/* Lock the Owner Process */
- Status = CsrLockProcessByClientId(&ClientId->UniqueProcess, &CsrProcess);
+ Status = CsrLockProcessByClientId(ClientId->UniqueProcess, &CsrProcess);
if (!NT_SUCCESS(Status))
{
DPRINT1("No known process for %lx\n", ClientId->UniqueProcess);
*--*/
NTSTATUS
NTAPI
-#if 0
CsrCreateThread(IN PCSR_PROCESS CsrProcess,
IN HANDLE hThread,
IN PCLIENT_ID ClientId,
PCSR_PROCESS CurrentProcess;
CLIENT_ID CurrentCid;
KERNEL_USER_TIMES KernelTimes;
+
DPRINT("CSRSRV: %s called\n", __FUNCTION__);
if (HaveClient)
{
/* Get the current thread and CID */
- CurrentThread = NtCurrentTeb()->CsrClientThread;
+ CurrentThread = CsrGetClientThread();
CurrentCid = CurrentThread->ClientId;
/* Acquire the Process Lock */
/* Get the current Process and make sure the Thread is valid with this CID */
CurrentThread = CsrLocateThreadByClientId(&CurrentProcess, &CurrentCid);
+
+ /* Something is wrong if we get an empty thread back */
if (!CurrentThread)
{
DPRINT1("CSRSRV:%s: invalid thread!\n", __FUNCTION__);
/* Release the lock and return */
CsrReleaseProcessLock();
- return STATUS_SUCCESS;
-}
-#else
-CsrCreateThread(IN PCSR_PROCESS CsrProcess,
- IN HANDLE hThread,
- IN PCLIENT_ID ClientId)
-{
- PCSR_THREAD CsrThread;
- PCSR_PROCESS CurrentProcess;
- PCSR_THREAD CurrentThread = CsrGetClientThread();
- CLIENT_ID CurrentCid;
- KERNEL_USER_TIMES KernelTimes;
- /* Get the current thread and CID */
- CurrentCid = CurrentThread->ClientId;
-
- /* Acquire the Process Lock */
- CsrAcquireProcessLock();
-
- /* Get the current Process and make sure the Thread is valid with this CID */
- CurrentThread = CsrLocateThreadByClientId(&CurrentProcess,
- &CurrentCid);
-
- /* Something is wrong if we get an empty thread back */
- if (!CurrentThread)
- {
- DPRINT1("CSRSRV:%s: invalid thread!\n", __FUNCTION__);
- CsrReleaseProcessLock();
- return STATUS_THREAD_IS_TERMINATING;
- }
-
- /* Get the Thread Create Time */
- NtQueryInformationThread(hThread,
- ThreadTimes,
- (PVOID)&KernelTimes,
- sizeof(KernelTimes),
- NULL);
-
- /* Allocate a CSR Thread Structure */
- if (!(CsrThread = CsrAllocateThread(CsrProcess)))
- {
- DPRINT1("CSRSRV:%s: out of memory!\n", __FUNCTION__);
- CsrReleaseProcessLock();
- return STATUS_NO_MEMORY;
- }
-
- /* Save the data we have */
- CsrThread->CreateTime = KernelTimes.CreateTime;
- CsrThread->ClientId = *ClientId;
- CsrThread->ThreadHandle = hThread;
- CsrThread->Flags = 0;
-
- /* Insert the Thread into the Process */
- CsrInsertThread(CsrProcess, CsrThread);
-
- /* Release the lock and return */
- CsrReleaseProcessLock();
return STATUS_SUCCESS;
}
-#endif
/*++
* @name CsrDereferenceThread
break;
}
- /* Next entry */
+ /* Move to the next entry */
NextEntry = NextEntry->Flink;
}
{
/* Reference the found thread */
Status = STATUS_SUCCESS;
- CurrentThread->ReferenceCount++;
+ CsrLockedReferenceThread(CurrentThread);
*CsrThread = CurrentThread;
}
else