ReactOS 0.4.16-dev-297-gc569aee
wait.c File Reference
#include "srv.h"
#include <debug.h>
Include dependency graph for wait.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

BOOLEAN NTAPI CsrInitializeWait (IN CSR_WAIT_FUNCTION WaitFunction, IN PCSR_THREAD CsrWaitThread, IN OUT PCSR_API_MESSAGE WaitApiMessage, IN PVOID WaitContext, OUT PCSR_WAIT_BLOCK *NewWaitBlock)
 
BOOLEAN NTAPI CsrNotifyWaitBlock (IN PCSR_WAIT_BLOCK WaitBlock, IN PLIST_ENTRY WaitList, IN PVOID WaitArgument1, IN PVOID WaitArgument2, IN ULONG WaitFlags, IN BOOLEAN DereferenceThread)
 
BOOLEAN NTAPI CsrCreateWait (IN PLIST_ENTRY WaitList, IN CSR_WAIT_FUNCTION WaitFunction, IN PCSR_THREAD CsrWaitThread, IN OUT PCSR_API_MESSAGE WaitApiMessage, IN PVOID WaitContext)
 
VOID NTAPI CsrDereferenceWait (IN PLIST_ENTRY WaitList)
 
VOID NTAPI CsrMoveSatisfiedWait (IN PLIST_ENTRY DestinationList, IN PLIST_ENTRY WaitList)
 
BOOLEAN NTAPI CsrNotifyWait (IN PLIST_ENTRY WaitList, IN BOOLEAN NotifyAll, IN PVOID WaitArgument1, IN PVOID WaitArgument2)
 

Variables

RTL_CRITICAL_SECTION CsrWaitListsLock
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 14 of file wait.c.

Function Documentation

◆ CsrCreateWait()

BOOLEAN NTAPI CsrCreateWait ( IN PLIST_ENTRY  WaitList,
IN CSR_WAIT_FUNCTION  WaitFunction,
IN PCSR_THREAD  CsrWaitThread,
IN OUT PCSR_API_MESSAGE  WaitApiMessage,
IN PVOID  WaitContext 
)

Definition at line 209 of file wait.c.

214{
215 PCSR_WAIT_BLOCK WaitBlock;
216
217 /* Initialize the wait */
218 if (!CsrInitializeWait(WaitFunction,
219 CsrWaitThread,
220 WaitApiMessage,
221 WaitContext,
222 &WaitBlock))
223 {
224 return FALSE;
225 }
226
227 /* Acquire the Wait Lock */
229
230 /* Make sure the thread wasn't destroyed */
231 if (CsrWaitThread->Flags & CsrThreadTerminated)
232 {
233 /* Fail the wait */
234 RtlFreeHeap(CsrHeap, 0, WaitBlock);
236 return FALSE;
237 }
238
239 /* Associate the newly created wait to the waiting thread */
240 CsrWaitThread->WaitBlock = WaitBlock;
241
242 /* Insert the wait in the queue */
243 InsertTailList(WaitList, &WaitBlock->WaitList);
244
245 /* Return */
247 return TRUE;
248}
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:608
@ CsrThreadTerminated
Definition: csrsrv.h:106
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define InsertTailList(ListHead, Entry)
LIST_ENTRY WaitList
Definition: csrsrv.h:158
#define CsrAcquireWaitLock()
Definition: api.h:21
HANDLE CsrHeap
Definition: init.c:25
#define CsrReleaseWaitLock()
Definition: api.h:24
BOOLEAN NTAPI CsrInitializeWait(IN CSR_WAIT_FUNCTION WaitFunction, IN PCSR_THREAD CsrWaitThread, IN OUT PCSR_API_MESSAGE WaitApiMessage, IN PVOID WaitContext, OUT PCSR_WAIT_BLOCK *NewWaitBlock)
Definition: wait.c:50

Referenced by DoWriteConsole(), and WaitBeforeReading().

◆ CsrDereferenceWait()

VOID NTAPI CsrDereferenceWait ( IN PLIST_ENTRY  WaitList)

Definition at line 266 of file wait.c.

267{
268 PLIST_ENTRY NextEntry;
269 PCSR_WAIT_BLOCK WaitBlock;
270
271 /* Acquire the Process and Wait Locks */
274
275 /* Set the list pointers */
276 NextEntry = WaitList->Flink;
277
278 /* Start the loop */
279 while (NextEntry != WaitList)
280 {
281 /* Get the wait block */
282 WaitBlock = CONTAINING_RECORD(NextEntry, CSR_WAIT_BLOCK, WaitList);
283
284 /* Move to the next entry */
285 NextEntry = NextEntry->Flink;
286
287 /* Check if there's no Wait Routine (satisfied wait) */
288 if (WaitBlock->WaitFunction == NULL)
289 {
290 /* Remove it from the Wait List */
291 if (WaitBlock->WaitList.Flink)
292 {
293 RemoveEntryList(&WaitBlock->WaitList);
294 }
295
296 /* Dereference the thread waiting on it */
298
299 /* Free the block */
300 RtlFreeHeap(CsrHeap, 0, WaitBlock);
301 }
302 }
303
304 /* Release the locks */
307}
VOID NTAPI CsrDereferenceThread(IN PCSR_THREAD CsrThread)
Definition: thredsup.c:776
#define NULL
Definition: types.h:112
#define RemoveEntryList(Entry)
Definition: env_spec_w32.h:986
PCSR_THREAD WaitThread
Definition: csrsrv.h:160
CSR_WAIT_FUNCTION WaitFunction
Definition: csrsrv.h:161
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
#define CsrAcquireProcessLock()
Definition: api.h:12
#define CsrReleaseProcessLock()
Definition: api.h:15
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260

Referenced by ConioUnpause(), ConSrvCloseHandle(), and PostprocessInput().

◆ CsrInitializeWait()

BOOLEAN NTAPI CsrInitializeWait ( IN CSR_WAIT_FUNCTION  WaitFunction,
IN PCSR_THREAD  CsrWaitThread,
IN OUT PCSR_API_MESSAGE  WaitApiMessage,
IN PVOID  WaitContext,
OUT PCSR_WAIT_BLOCK NewWaitBlock 
)

Definition at line 50 of file wait.c.

55{
56 ULONG Size;
57 PCSR_WAIT_BLOCK WaitBlock;
58
59 /* Calculate the size of the wait block */
60 Size = sizeof(CSR_WAIT_BLOCK) -
61 sizeof(WaitBlock->WaitApiMessage) +
62 WaitApiMessage->Header.u1.s1.TotalLength;
63
64 /* Allocate the Wait Block */
66 if (!WaitBlock)
67 {
68 /* Fail */
69 WaitApiMessage->Status = STATUS_NO_MEMORY;
70 return FALSE;
71 }
72
73 /* Initialize it */
74 WaitBlock->Size = Size;
75 WaitBlock->WaitThread = CsrWaitThread;
76 WaitBlock->WaitContext = WaitContext;
77 WaitBlock->WaitFunction = WaitFunction;
78 WaitBlock->WaitList.Flink = NULL;
79 WaitBlock->WaitList.Blink = NULL;
80
81 /* Copy the message */
82 RtlCopyMemory(&WaitBlock->WaitApiMessage,
83 WaitApiMessage,
84 WaitApiMessage->Header.u1.s1.TotalLength);
85
86 /* Return the block */
87 *NewWaitBlock = WaitBlock;
88 return TRUE;
89}
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:590
struct _CSR_WAIT_BLOCK CSR_WAIT_BLOCK
#define STATUS_NO_MEMORY
Definition: d3dkmdt.h:51
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
PORT_MESSAGE Header
Definition: csrmsg.h:102
PVOID WaitContext
Definition: csrsrv.h:159
ULONG Size
Definition: csrsrv.h:157
CSR_API_MESSAGE WaitApiMessage
Definition: csrsrv.h:162
struct _LIST_ENTRY * Blink
Definition: typedefs.h:122
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
uint32_t ULONG
Definition: typedefs.h:59
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533

Referenced by CsrCreateWait().

◆ CsrMoveSatisfiedWait()

VOID NTAPI CsrMoveSatisfiedWait ( IN PLIST_ENTRY  DestinationList,
IN PLIST_ENTRY  WaitList 
)

Definition at line 330 of file wait.c.

332{
333 PLIST_ENTRY NextEntry;
334 PCSR_WAIT_BLOCK WaitBlock;
335
336 /* Acquire the Wait Lock */
338
339 /* Set the List pointers */
340 NextEntry = WaitList->Flink;
341
342 /* Start looping */
343 while (NextEntry != WaitList)
344 {
345 /* Get the Wait block */
346 WaitBlock = CONTAINING_RECORD(NextEntry, CSR_WAIT_BLOCK, WaitList);
347
348 /* Go to the next entry */
349 NextEntry = NextEntry->Flink;
350
351 /* Check if there's no Wait Routine (satisfied wait) */
352 if (WaitBlock->WaitFunction == NULL)
353 {
354 /* Remove it from the Wait Block Queue */
355 RemoveEntryList(&WaitBlock->WaitList);
356
357 /* Insert the wait into the destination list */
358 InsertTailList(DestinationList, &WaitBlock->WaitList);
359 }
360 }
361
362 /* Release the wait lock */
364}

◆ CsrNotifyWait()

BOOLEAN NTAPI CsrNotifyWait ( IN PLIST_ENTRY  WaitList,
IN BOOLEAN  NotifyAll,
IN PVOID  WaitArgument1,
IN PVOID  WaitArgument2 
)

Definition at line 388 of file wait.c.

392{
393 PLIST_ENTRY NextEntry;
394 PCSR_WAIT_BLOCK WaitBlock;
395 BOOLEAN NotifySuccess = FALSE;
396
397 /* Acquire the Wait Lock */
399
400 /* Set the List pointers */
401 NextEntry = WaitList->Flink;
402
403 /* Start looping */
404 while (NextEntry != WaitList)
405 {
406 /* Get the Wait block */
407 WaitBlock = CONTAINING_RECORD(NextEntry, CSR_WAIT_BLOCK, WaitList);
408
409 /* Go to the next entry */
410 NextEntry = NextEntry->Flink;
411
412 /* Check if there is a Wait Routine */
413 if (WaitBlock->WaitFunction != NULL)
414 {
415 /* Notify the Waiter */
416 NotifySuccess |= CsrNotifyWaitBlock(WaitBlock,
417 WaitList,
418 WaitArgument1,
419 WaitArgument2,
420 0,
421 FALSE);
422
423 /*
424 * We've already done a wait, so leave unless
425 * we want to notify all the waits...
426 */
427 if (!NotifyAll) break;
428 }
429 }
430
431 /* Release the wait lock and return */
433 return NotifySuccess;
434}
unsigned char BOOLEAN
BOOLEAN NTAPI CsrNotifyWaitBlock(IN PCSR_WAIT_BLOCK WaitBlock, IN PLIST_ENTRY WaitList, IN PVOID WaitArgument1, IN PVOID WaitArgument2, IN ULONG WaitFlags, IN BOOLEAN DereferenceThread)
Definition: wait.c:120

Referenced by ConioUnpause(), ConSrvCloseHandle(), and PostprocessInput().

◆ CsrNotifyWaitBlock()

BOOLEAN NTAPI CsrNotifyWaitBlock ( IN PCSR_WAIT_BLOCK  WaitBlock,
IN PLIST_ENTRY  WaitList,
IN PVOID  WaitArgument1,
IN PVOID  WaitArgument2,
IN ULONG  WaitFlags,
IN BOOLEAN  DereferenceThread 
)

Definition at line 120 of file wait.c.

126{
127 /* Call the wait function */
128 if (WaitBlock->WaitFunction(WaitList,
129 WaitBlock->WaitThread,
130 &WaitBlock->WaitApiMessage,
131 WaitBlock->WaitContext,
132 WaitArgument1,
133 WaitArgument2,
134 WaitFlags))
135 {
136 /* The wait is done, clear the block */
137 WaitBlock->WaitThread->WaitBlock = NULL;
138
139 /* Check for captured arguments */
140 if (WaitBlock->WaitApiMessage.CsrCaptureData)
141 {
142 /* Release them */
143 CsrReleaseCapturedArguments(&WaitBlock->WaitApiMessage);
144 }
145
146 /* Reply to the port */
147 NtReplyPort(WaitBlock->WaitThread->Process->ClientPort,
148 &WaitBlock->WaitApiMessage.Header);
149
150 /* Check if we should dereference the thread */
151 if (DereferenceThread)
152 {
153 /* Remove it from the Wait List */
154 if (WaitBlock->WaitList.Flink)
155 {
156 RemoveEntryList(&WaitBlock->WaitList);
157 }
158
159 /* Dereference the thread */
160 CsrDereferenceThread(WaitBlock->WaitThread);
161
162 /* Free the wait block */
163 RtlFreeHeap(CsrHeap, 0, WaitBlock);
164 }
165 else
166 {
167 /* The wait is complete, but the thread is being kept alive */
168 WaitBlock->WaitFunction = NULL;
169 }
170
171 /* The wait succeeded */
172 return TRUE;
173 }
174
175 /* The wait failed */
176 return FALSE;
177}
NTSTATUS NTAPI NtReplyPort(IN HANDLE PortHandle, IN PPORT_MESSAGE ReplyMessage)
Definition: reply.c:190
VOID NTAPI CsrReleaseCapturedArguments(IN PCSR_API_MESSAGE ApiMessage)
Definition: api.c:1337

Referenced by CsrDestroyProcess(), CsrDestroyThread(), and CsrNotifyWait().

Variable Documentation

◆ CsrWaitListsLock

RTL_CRITICAL_SECTION CsrWaitListsLock

Definition at line 19 of file wait.c.