2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Client/Server Runtime SubSystem
4 * FILE: subsystems/win32/csrsrv/thredsup.c
5 * PURPOSE: CSR Server DLL Thread Management
6 * PROGRAMMERS: ReactOS Portable Systems Group
7 * Alex Ionescu (alex@relsoft.net)
10 /* INCLUDES *******************************************************************/
17 #define CsrHashThread(t) (HandleToUlong(t) % 257)
19 /* GLOBALS ********************************************************************/
21 LIST_ENTRY CsrThreadHashTable
[257];
24 /* PRIVATE FUNCTIONS **********************************************************/
30 * The ProtectHandle routine protects an object handle against closure.
32 * @return TRUE or FALSE.
39 ProtectHandle(IN HANDLE ObjectHandle
)
42 OBJECT_HANDLE_ATTRIBUTE_INFORMATION HandleInfo
;
44 /* Query current state */
45 Status
= NtQueryObject(ObjectHandle
,
46 ObjectHandleFlagInformation
,
50 if (NT_SUCCESS(Status
))
52 /* Enable protect from close */
53 HandleInfo
.ProtectFromClose
= TRUE
;
54 Status
= NtSetInformationObject(ObjectHandle
,
55 ObjectHandleFlagInformation
,
58 if (NT_SUCCESS(Status
)) return TRUE
;
61 /* We failed to or set the state */
66 * @name UnProtectHandle
69 * The UnProtectHandle routine unprotects an object handle against closure.
71 * @return TRUE or FALSE.
78 UnProtectHandle(IN HANDLE ObjectHandle
)
81 OBJECT_HANDLE_ATTRIBUTE_INFORMATION HandleInfo
;
83 /* Query current state */
84 Status
= NtQueryObject(ObjectHandle
,
85 ObjectHandleFlagInformation
,
89 if (NT_SUCCESS(Status
))
91 /* Disable protect from close */
92 HandleInfo
.ProtectFromClose
= FALSE
;
93 Status
= NtSetInformationObject(ObjectHandle
,
94 ObjectHandleFlagInformation
,
97 if (NT_SUCCESS(Status
)) return TRUE
;
100 /* We failed to or set the state */
105 * @name CsrAllocateThread
107 * The CsrAllocateThread routine allocates a new CSR Thread object.
110 * Pointer to the CSR Process which will contain this CSR Thread.
112 * @return Pointer to the newly allocated CSR Thread.
119 CsrAllocateThread(IN PCSR_PROCESS CsrProcess
)
121 PCSR_THREAD CsrThread
;
123 /* Allocate the structure */
124 CsrThread
= RtlAllocateHeap(CsrHeap
, HEAP_ZERO_MEMORY
, sizeof(CSR_THREAD
));
125 if (!CsrThread
) return NULL
;
127 /* Reference the Thread and Process */
128 CsrLockedReferenceThread(CsrThread
);
129 CsrLockedReferenceProcess(CsrProcess
);
131 /* Set the Parent Process */
132 CsrThread
->Process
= CsrProcess
;
139 * @name CsrLockedReferenceThread
141 * The CsrLockedReferenceThread references a CSR Thread while the
142 * Process Lock is already being held.
145 * Pointer to the CSR Thread to be referenced.
149 * @remarks This routine will return with the Process Lock held.
154 CsrLockedReferenceThread(IN PCSR_THREAD CsrThread
)
156 /* Increment the reference count */
157 ++CsrThread
->ReferenceCount
;
161 * @name CsrLocateThreadByClientId
163 * The CsrLocateThreadByClientId routine locates the CSR Thread and,
164 * optionally, its parent CSR Process, corresponding to a Client ID.
167 * Optional pointer to a CSR Process pointer which will contain
168 * the CSR Thread's parent.
171 * Pointer to a Client ID structure containing the Unique Thread ID
174 * @return Pointer to the CSR Thread corresponding to this CID, or NULL if
182 CsrLocateThreadByClientId(OUT PCSR_PROCESS
*Process OPTIONAL
,
183 IN PCLIENT_ID ClientId
)
186 PLIST_ENTRY ListHead
, NextEntry
;
187 PCSR_THREAD FoundThread
;
188 // ASSERT(ProcessStructureListLocked());
190 if (Process
) *Process
= NULL
;
192 /* Hash the Thread */
193 i
= CsrHashThread(ClientId
->UniqueThread
);
195 /* Set the list pointers */
196 ListHead
= &CsrThreadHashTable
[i
];
197 NextEntry
= ListHead
->Flink
;
200 while (NextEntry
!= ListHead
)
203 FoundThread
= CONTAINING_RECORD(NextEntry
, CSR_THREAD
, HashLinks
);
205 /* Move to the next entry */
206 NextEntry
= NextEntry
->Flink
;
208 /* Compare the CID */
209 // if (*(PULONGLONG)&FoundThread->ClientId == *(PULONGLONG)ClientId)
210 if ( FoundThread
->ClientId
.UniqueProcess
== ClientId
->UniqueProcess
&&
211 FoundThread
->ClientId
.UniqueThread
== ClientId
->UniqueThread
)
213 /* Match found, return the process */
214 if (Process
) *Process
= FoundThread
->Process
;
216 /* Return thread too */
226 * @name CsrLocateThreadInProcess
228 * The CsrLocateThreadInProcess routine locates the CSR Thread
229 * corresponding to a Client ID inside a specific CSR Process.
232 * Optional pointer to the CSR Process which contains the CSR Thread
233 * that will be looked up.
236 * Pointer to a Client ID structure containing the Unique Thread ID
239 * @return Pointer to the CSR Thread corresponding to this CID, or NULL if
242 * @remarks If the CsrProcess argument is NULL, the lookup will be done inside
248 CsrLocateThreadInProcess(IN PCSR_PROCESS CsrProcess OPTIONAL
,
251 PLIST_ENTRY ListHead
, NextEntry
;
252 PCSR_THREAD FoundThread
= NULL
;
254 /* Use the Root Process if none was specified */
255 if (!CsrProcess
) CsrProcess
= CsrRootProcess
;
257 /* Save the List pointers */
258 ListHead
= &CsrProcess
->ThreadList
;
259 NextEntry
= ListHead
->Flink
;
262 while (NextEntry
!= ListHead
)
264 /* Get Thread Entry */
265 FoundThread
= CONTAINING_RECORD(NextEntry
, CSR_THREAD
, Link
);
267 /* Check for TID Match */
268 if (FoundThread
->ClientId
.UniqueThread
== Cid
->UniqueThread
) break;
270 /* Move to the next entry */
271 NextEntry
= NextEntry
->Flink
;
274 /* Return what we found */
279 * @name CsrInsertThread
281 * The CsrInsertThread routine inserts a CSR Thread into its parent's
282 * Thread List and into the Thread Hash Table.
285 * Pointer to the CSR Process containing this CSR Thread.
288 * Pointer to the CSR Thread to be inserted.
297 CsrInsertThread(IN PCSR_PROCESS Process
,
298 IN PCSR_THREAD Thread
)
301 // ASSERT(ProcessStructureListLocked());
303 /* Insert it into the Regular List */
304 InsertTailList(&Process
->ThreadList
, &Thread
->Link
);
306 /* Increase Thread Count */
307 Process
->ThreadCount
++;
309 /* Hash the Thread */
310 i
= CsrHashThread(Thread
->ClientId
.UniqueThread
);
312 /* Insert it there too */
313 InsertHeadList(&CsrThreadHashTable
[i
], &Thread
->HashLinks
);
317 * @name CsrDeallocateThread
319 * The CsrDeallocateThread frees the memory associated with a CSR Thread.
322 * Pointer to the CSR Thread to be freed.
326 * @remarks Do not call this routine. It is reserved for the internal
327 * thread management routines when a CSR Thread has been cleanly
328 * dereferenced and killed.
333 CsrDeallocateThread(IN PCSR_THREAD CsrThread
)
335 /* Free the process object from the heap */
336 // ASSERT(CsrThread->WaitBlock == NULL);
337 RtlFreeHeap(CsrHeap
, 0, CsrThread
);
341 * @name CsrRemoveThread
343 * The CsrRemoveThread function undoes a CsrInsertThread operation and
344 * removes the CSR Thread from the the Hash Table and Thread List.
347 * Pointer to the CSR Thread to remove.
351 * @remarks If this CSR Thread is the last one inside a CSR Process, the
352 * parent will be dereferenced and the CsrProcessLastThreadTerminated
355 * After executing this routine, the CSR Thread will have the
356 * CsrThreadInTermination flag set.
361 CsrRemoveThread(IN PCSR_THREAD CsrThread
)
363 ASSERT(ProcessStructureListLocked());
365 /* Remove it from the List */
366 RemoveEntryList(&CsrThread
->Link
);
368 /* Decreate the thread count of the process */
369 CsrThread
->Process
->ThreadCount
--;
371 /* Remove it from the Hash List as well */
372 if (CsrThread
->HashLinks
.Flink
) RemoveEntryList(&CsrThread
->HashLinks
);
374 /* Check if this is the last Thread */
375 if (CsrThread
->Process
->ThreadCount
== 0)
377 /* Check if it's not already been marked for deletion */
378 if ((CsrThread
->Process
->Flags
& CsrProcessLastThreadTerminated
) == 0)
380 /* Let everyone know this process is about to lose the thread */
381 CsrThread
->Process
->Flags
|= CsrProcessLastThreadTerminated
;
383 /* Reference the Process */
384 CsrLockedDereferenceProcess(CsrThread
->Process
);
388 /* Mark the thread for deletion */
389 CsrThread
->Flags
|= CsrThreadInTermination
;
393 * @name CsrThreadRefcountZero
395 * The CsrThreadRefcountZero routine is executed when a CSR Thread has lost
396 * all its active references. It removes and de-allocates the CSR Thread.
399 * Pointer to the CSR Thread that is to be deleted.
403 * @remarks Do not call this routine. It is reserved for the internal
404 * thread management routines when a CSR Thread has lost all
407 * This routine is called with the Process Lock held.
412 CsrThreadRefcountZero(IN PCSR_THREAD CsrThread
)
414 PCSR_PROCESS CsrProcess
= CsrThread
->Process
;
416 ASSERT(ProcessStructureListLocked());
418 /* Remove this thread */
419 CsrRemoveThread(CsrThread
);
421 /* Release the Process Lock */
422 CsrReleaseProcessLock();
424 /* Close the NT Thread Handle */
425 if (CsrThread
->ThreadHandle
)
427 UnProtectHandle(CsrThread
->ThreadHandle
);
428 Status
= NtClose(CsrThread
->ThreadHandle
);
429 ASSERT(NT_SUCCESS(Status
));
432 /* De-allocate the CSR Thread Object */
433 CsrDeallocateThread(CsrThread
);
435 /* Remove a reference from the process */
436 CsrDereferenceProcess(CsrProcess
);
440 * @name CsrLockedDereferenceThread
442 * The CsrLockedDereferenceThread dereferences a CSR Thread while the
443 * Process Lock is already being held.
446 * Pointer to the CSR Thread to be dereferenced.
450 * @remarks This routine will return with the Process Lock held.
455 CsrLockedDereferenceThread(IN PCSR_THREAD CsrThread
)
459 /* Decrease reference count */
460 LockCount
= --CsrThread
->ReferenceCount
;
461 ASSERT(LockCount
>= 0);
464 /* Call the generic cleanup code */
465 CsrAcquireProcessLock();
466 CsrThreadRefcountZero(CsrThread
);
471 /* PUBLIC FUNCTIONS ***********************************************************/
474 * @name CsrAddStaticServerThread
477 * The CsrAddStaticServerThread routine adds a new CSR Thread to the
478 * CSR Server Process (CsrRootProcess).
481 * Handle to an existing NT Thread to which to associate this
485 * Pointer to the Client ID structure of the NT Thread to associate
486 * with this CSR Thread.
489 * Initial CSR Thread Flags to associate to this CSR Thread. Usually
490 * CsrThreadIsServerThread.
492 * @return Pointer to the newly allocated CSR Thread.
499 CsrAddStaticServerThread(IN HANDLE hThread
,
500 IN PCLIENT_ID ClientId
,
501 IN ULONG ThreadFlags
)
503 PCSR_THREAD CsrThread
;
506 CsrAcquireProcessLock();
508 /* Allocate the Server Thread */
509 CsrThread
= CsrAllocateThread(CsrRootProcess
);
512 /* Setup the Object */
513 CsrThread
->ThreadHandle
= hThread
;
514 ProtectHandle(hThread
);
515 CsrThread
->ClientId
= *ClientId
;
516 CsrThread
->Flags
= ThreadFlags
;
518 /* Insert it into the Thread List */
519 InsertTailList(&CsrRootProcess
->ThreadList
, &CsrThread
->Link
);
521 /* Increment the thread count */
522 CsrRootProcess
->ThreadCount
++;
526 DPRINT1("CsrAddStaticServerThread: alloc failed for thread 0x%x\n", hThread
);
529 /* Release the Process Lock and return */
530 CsrReleaseProcessLock();
535 * @name CsrCreateRemoteThread
538 * The CsrCreateRemoteThread routine creates a CSR Thread object for
539 * an NT Thread which is not part of the current NT Process.
542 * Handle to an existing NT Thread to which to associate this
546 * Pointer to the Client ID structure of the NT Thread to associate
547 * with this CSR Thread.
549 * @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL otherwise.
556 CsrCreateRemoteThread(IN HANDLE hThread
,
557 IN PCLIENT_ID ClientId
)
561 PCSR_THREAD CsrThread
;
562 PCSR_PROCESS CsrProcess
;
563 KERNEL_USER_TIMES KernelTimes
;
565 /* Get the Thread Create Time */
566 Status
= NtQueryInformationThread(hThread
,
571 if (!NT_SUCCESS(Status
))
573 DPRINT1("Failed to query thread times: %lx\n", Status
);
577 /* Lock the Owner Process */
578 Status
= CsrLockProcessByClientId(ClientId
->UniqueProcess
, &CsrProcess
);
579 if (!NT_SUCCESS(Status
))
581 DPRINT1("No known process for %lx\n", ClientId
->UniqueProcess
);
585 /* Make sure the thread didn't terminate */
586 if (KernelTimes
.ExitTime
.QuadPart
)
588 /* Unlock the process and return */
589 CsrUnlockProcess(CsrProcess
);
590 DPRINT1("Dead thread: %I64x\n", KernelTimes
.ExitTime
.QuadPart
);
591 return STATUS_THREAD_IS_TERMINATING
;
594 /* Allocate a CSR Thread Structure */
595 CsrThread
= CsrAllocateThread(CsrProcess
);
598 DPRINT1("CSRSRV: %s: out of memory!\n", __FUNCTION__
);
599 CsrUnlockProcess(CsrProcess
);
600 return STATUS_NO_MEMORY
;
603 /* Duplicate the Thread Handle */
604 Status
= NtDuplicateObject(NtCurrentProcess(),
610 DUPLICATE_SAME_ACCESS
);
612 if (!NT_SUCCESS(Status
))
614 DPRINT1("Thread duplication failed: %lx\n", Status
);
615 ThreadHandle
= hThread
;
618 /* Save the data we have */
619 CsrThread
->CreateTime
= KernelTimes
.CreateTime
;
620 CsrThread
->ClientId
= *ClientId
;
621 CsrThread
->ThreadHandle
= ThreadHandle
;
622 ProtectHandle(ThreadHandle
);
623 CsrThread
->Flags
= 0;
625 /* Insert the Thread into the Process */
626 CsrInsertThread(CsrProcess
, CsrThread
);
628 /* Release the lock and return */
629 CsrUnlockProcess(CsrProcess
);
630 return STATUS_SUCCESS
;
634 * @name CsrCreateThread
637 * The CsrCreateThread routine creates a CSR Thread object for an NT Thread.
640 * Pointer to the CSR Process which will contain the CSR Thread.
643 * Handle to an existing NT Thread to which to associate this
647 * Pointer to the Client ID structure of the NT Thread to associate
648 * with this CSR Thread.
650 * @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL otherwise.
657 CsrCreateThread(IN PCSR_PROCESS CsrProcess
,
659 IN PCLIENT_ID ClientId
,
660 IN BOOLEAN HaveClient
)
663 PCSR_THREAD CsrThread
, CurrentThread
;
664 PCSR_PROCESS CurrentProcess
;
665 CLIENT_ID CurrentCid
;
666 KERNEL_USER_TIMES KernelTimes
;
670 /* Get the current thread and CID */
671 CurrentThread
= CsrGetClientThread();
672 CurrentCid
= CurrentThread
->ClientId
;
674 /* Acquire the Process Lock */
675 CsrAcquireProcessLock();
677 /* Get the current Process and make sure the Thread is valid with this CID */
678 CurrentThread
= CsrLocateThreadByClientId(&CurrentProcess
, &CurrentCid
);
680 /* Something is wrong if we get an empty thread back */
683 DPRINT1("CSRSRV: %s: invalid thread!\n", __FUNCTION__
);
684 CsrReleaseProcessLock();
685 return STATUS_THREAD_IS_TERMINATING
;
690 /* Acquire the Process Lock */
691 CsrAcquireProcessLock();
694 /* Get the Thread Create Time */
695 Status
= NtQueryInformationThread(hThread
,
700 if (!NT_SUCCESS(Status
))
702 CsrReleaseProcessLock();
706 /* Allocate a CSR Thread Structure */
707 CsrThread
= CsrAllocateThread(CsrProcess
);
710 DPRINT1("CSRSRV: %s: out of memory!\n", __FUNCTION__
);
711 CsrReleaseProcessLock();
712 return STATUS_NO_MEMORY
;
715 /* Save the data we have */
716 CsrThread
->CreateTime
= KernelTimes
.CreateTime
;
717 CsrThread
->ClientId
= *ClientId
;
718 CsrThread
->ThreadHandle
= hThread
;
719 ProtectHandle(hThread
);
720 CsrThread
->Flags
= 0;
722 /* Insert the Thread into the Process */
723 CsrInsertThread(CsrProcess
, CsrThread
);
725 /* Release the lock and return */
726 CsrReleaseProcessLock();
728 return STATUS_SUCCESS
;
732 * @name CsrDereferenceThread
735 * The CsrDereferenceThread routine removes a reference from a CSR Thread.
738 * Pointer to the CSR Thread to dereference.
742 * @remarks If the reference count has reached zero (ie: the CSR Thread has
743 * no more active references), it will be deleted.
748 CsrDereferenceThread(IN PCSR_THREAD CsrThread
)
750 /* Acquire process lock */
751 CsrAcquireProcessLock();
753 /* Decrease reference count */
754 ASSERT(CsrThread
->ReferenceCount
> 0);
755 if ((--CsrThread
->ReferenceCount
) == 0)
757 /* Call the generic cleanup code */
758 CsrThreadRefcountZero(CsrThread
);
762 /* Just release the lock */
763 CsrReleaseProcessLock();
768 * @name CsrDestroyThread
771 * The CsrDestroyThread routine destroys the CSR Thread corresponding to
775 * Pointer to the Client ID Structure corresponding to the CSR
776 * Thread which is about to be destroyed.
778 * @return STATUS_SUCCESS in case of success, STATUS_THREAD_IS_TERMINATING
779 * if the CSR Thread is already terminating.
786 CsrDestroyThread(IN PCLIENT_ID Cid
)
788 CLIENT_ID ClientId
= *Cid
;
789 PCSR_THREAD CsrThread
;
790 PCSR_PROCESS CsrProcess
;
793 CsrAcquireProcessLock();
795 /* Find the thread */
796 CsrThread
= CsrLocateThreadByClientId(&CsrProcess
,
799 /* Make sure we got one back, and that it's not already gone */
800 if (!CsrThread
|| (CsrThread
->Flags
& CsrThreadTerminated
))
802 /* Release the lock and return failure */
803 CsrReleaseProcessLock();
804 return STATUS_THREAD_IS_TERMINATING
;
807 /* Set the terminated flag */
808 CsrThread
->Flags
|= CsrThreadTerminated
;
810 /* Acquire the Wait Lock */
811 CsrAcquireWaitLock();
813 /* Do we have an active wait block? */
814 if (CsrThread
->WaitBlock
)
816 /* Notify waiters of termination */
817 CsrNotifyWaitBlock(CsrThread
->WaitBlock
,
821 CsrProcessTerminating
,
825 /* Release the Wait Lock */
826 CsrReleaseWaitLock();
828 /* Dereference the thread */
829 CsrLockedDereferenceThread(CsrThread
);
831 /* Release the Process Lock and return success */
832 CsrReleaseProcessLock();
833 return STATUS_SUCCESS
;
837 * @name CsrExecServerThread
840 * The CsrExecServerThread routine creates an NT Thread and then
841 * initializes a CSR Thread for it.
843 * @param ThreadHandler
844 * Pointer to the thread's startup routine.
847 * Initial CSR Thread Flags to set to the CSR Thread.
849 * @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL otherwise.
851 * @remarks This routine is similar to CsrAddStaticServerThread, but it
852 * also creates an NT Thread instead of expecting one to already
858 CsrExecServerThread(IN PVOID ThreadHandler
,
861 PCSR_THREAD CsrThread
;
866 /* Acquire process lock */
867 CsrAcquireProcessLock();
869 /* Allocate a CSR Thread in the Root Process */
870 ASSERT(CsrRootProcess
!= NULL
);
871 CsrThread
= CsrAllocateThread(CsrRootProcess
);
875 CsrReleaseProcessLock();
876 return STATUS_NO_MEMORY
;
879 /* Create the Thread */
880 Status
= RtlCreateUserThread(NtCurrentProcess(),
890 if (!NT_SUCCESS(Status
))
893 CsrDeallocateThread(CsrThread
);
894 CsrReleaseProcessLock();
898 /* Setup the Thread Object */
899 CsrThread
->ThreadHandle
= hThread
;
900 ProtectHandle(hThread
);
901 CsrThread
->ClientId
= ClientId
;
902 CsrThread
->Flags
= Flags
;
904 /* Insert it into the Thread List */
905 InsertHeadList(&CsrRootProcess
->ThreadList
, &CsrThread
->Link
);
907 /* Increase the thread count */
908 CsrRootProcess
->ThreadCount
++;
911 CsrReleaseProcessLock();
916 * @name CsrLockThreadByClientId
919 * The CsrLockThreadByClientId routine locks the CSR Thread corresponding
920 * to the given Thread ID and optionally returns it.
923 * Thread ID corresponding to the CSR Thread which will be locked.
926 * Optional pointer to a CSR Thread pointer which will hold the
927 * CSR Thread corresponding to the given Thread ID.
929 * @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL otherwise.
931 * @remarks Locking a CSR Thread is defined as acquiring an extra
932 * reference to it and returning with the Process Lock held.
937 CsrLockThreadByClientId(IN HANDLE Tid
,
938 OUT PCSR_THREAD
*CsrThread
)
940 PLIST_ENTRY NextEntry
;
941 PCSR_THREAD CurrentThread
= NULL
;
942 NTSTATUS Status
= STATUS_UNSUCCESSFUL
;
945 /* Acquire the lock */
946 CsrAcquireProcessLock();
949 ASSERT(CsrThread
!= NULL
);
952 /* Convert to Hash */
953 i
= CsrHashThread(Tid
);
955 /* Setup the List Pointers */
956 NextEntry
= CsrThreadHashTable
[i
].Flink
;
959 while (NextEntry
!= &CsrThreadHashTable
[i
])
962 CurrentThread
= CONTAINING_RECORD(NextEntry
, CSR_THREAD
, HashLinks
);
964 /* Check for TID Match */
965 if ((CurrentThread
->ClientId
.UniqueThread
== Tid
) &&
966 (CurrentThread
->Flags
& CsrThreadTerminated
) == 0)
968 /* Get out of here */
972 /* Move to the next entry */
973 NextEntry
= NextEntry
->Flink
;
976 /* Nothing found if we got back to the list */
977 if (NextEntry
== &CsrThreadHashTable
[i
]) CurrentThread
= NULL
;
979 /* Did the loop find something? */
982 /* Reference the found thread */
983 Status
= STATUS_SUCCESS
;
984 CsrLockedReferenceThread(CurrentThread
);
985 *CsrThread
= CurrentThread
;
989 /* Nothing found, release the lock */
990 Status
= STATUS_UNSUCCESSFUL
;
991 CsrReleaseProcessLock();
994 /* Return the status */
999 * @name CsrReferenceThread
1002 * The CsrReferenceThread routine increases the active reference count of
1006 * Pointer to the CSR Thread whose reference count will be increased.
1010 * @remarks Do not use this routine if the Process Lock is already held.
1015 CsrReferenceThread(IN PCSR_THREAD CsrThread
)
1017 /* Acquire process lock */
1018 CsrAcquireProcessLock();
1021 ASSERT(CsrThread
->Flags
& CsrThreadTerminated
); // CSR_THREAD_DESTROYED in ASSERT
1022 ASSERT(CsrThread
->ReferenceCount
!= 0);
1024 /* Increment reference count */
1025 CsrThread
->ReferenceCount
++;
1027 /* Release the lock */
1028 CsrReleaseProcessLock();
1032 * @name CsrUnlockThread
1035 * The CsrUnlockThread undoes a previous CsrLockThreadByClientId operation.
1038 * Pointer to a previously locked CSR Thread.
1040 * @return STATUS_SUCCESS.
1042 * @remarks This routine must be called with the Process Lock held.
1047 CsrUnlockThread(IN PCSR_THREAD CsrThread
)
1049 /* Dereference the Thread */
1050 ASSERT(ProcessStructureListLocked());
1051 CsrLockedDereferenceThread(CsrThread
);
1053 /* Release the lock and return */
1054 CsrReleaseProcessLock();
1055 return STATUS_SUCCESS
;