ReactOS  0.4.15-dev-3175-g222acf5
wait.c File Reference
#include <rtl.h>
#include <debug.h>
Include dependency graph for wait.c:

Go to the source code of this file.

Classes

struct  _RTLP_WAIT
 

Macros

#define NDEBUG
 

Typedefs

typedef struct _RTLP_WAIT RTLP_WAIT
 
typedef struct _RTLP_WAITPRTLP_WAIT
 

Functions

static PLARGE_INTEGER get_nt_timeout (PLARGE_INTEGER pTime, ULONG timeout)
 
static VOID NTAPI Wait_thread_proc (LPVOID Arg)
 
NTSTATUS NTAPI RtlRegisterWait (PHANDLE NewWaitObject, HANDLE Object, WAITORTIMERCALLBACKFUNC Callback, PVOID Context, ULONG Milliseconds, ULONG Flags)
 
NTSTATUS NTAPI RtlDeregisterWaitEx (HANDLE WaitHandle, HANDLE CompletionEvent)
 
NTSTATUS NTAPI RtlDeregisterWait (HANDLE WaitHandle)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 16 of file wait.c.

Typedef Documentation

◆ PRTLP_WAIT

◆ RTLP_WAIT

Function Documentation

◆ get_nt_timeout()

static PLARGE_INTEGER get_nt_timeout ( PLARGE_INTEGER  pTime,
ULONG  timeout 
)
inlinestatic

Definition at line 34 of file wait.c.

35 {
36  if (timeout == INFINITE) return NULL;
37  pTime->QuadPart = (ULONGLONG)timeout * -10000;
38  return pTime;
39 }
Definition: dhcpd.h:245
_In_ PCCERT_CONTEXT _In_opt_ LPFILETIME pTime
Definition: wincrypt.h:4836
uint64_t ULONGLONG
Definition: typedefs.h:67
#define NULL
Definition: types.h:112
#define INFINITE
Definition: serial.h:102

Referenced by Wait_thread_proc().

◆ RtlDeregisterWait()

NTSTATUS NTAPI RtlDeregisterWait ( HANDLE  WaitHandle)

Definition at line 270 of file wait.c.

271 {
272  return RtlDeregisterWaitEx(WaitHandle, NULL);
273 }
NTSTATUS NTAPI RtlDeregisterWaitEx(HANDLE WaitHandle, HANDLE CompletionEvent)
Definition: wait.c:202
#define NULL
Definition: types.h:112

◆ RtlDeregisterWaitEx()

NTSTATUS NTAPI RtlDeregisterWaitEx ( HANDLE  WaitHandle,
HANDLE  CompletionEvent 
)

Definition at line 202 of file wait.c.

204 {
205  PRTLP_WAIT Wait = (PRTLP_WAIT) WaitHandle;
207 
208  //TRACE( "(%p)\n", WaitHandle );
209 
210  NtSetEvent( Wait->CancelEvent, NULL );
211  if (Wait->CallbackInProgress)
212  {
213  if (CompletionEvent != NULL)
214  {
215  if (CompletionEvent == INVALID_HANDLE_VALUE)
216  {
217  Status = NtCreateEvent( &CompletionEvent,
219  NULL,
221  FALSE );
222 
223  if (Status != STATUS_SUCCESS)
224  return Status;
225 
226  (void)InterlockedExchangePointer( &Wait->CompletionEvent, CompletionEvent );
227 
228  if (Wait->CallbackInProgress)
229  NtWaitForSingleObject( CompletionEvent, FALSE, NULL );
230 
231  NtClose( CompletionEvent );
232  }
233  else
234  {
235  (void)InterlockedExchangePointer( &Wait->CompletionEvent, CompletionEvent );
236 
237  if (Wait->CallbackInProgress)
239  }
240  }
241  else
243  }
244 
245  if (InterlockedIncrement( &Wait->DeleteCount ) == 2 )
246  {
248  NtClose( Wait->CancelEvent );
249  RtlFreeHeap( RtlGetProcessHeap(), 0, Wait );
250  }
251 
252  return Status;
253 }
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
_In_ WDFDPC _In_ BOOLEAN Wait
Definition: wdfdpc.h:167
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
NTSTATUS NTAPI NtCreateEvent(OUT PHANDLE EventHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, IN EVENT_TYPE EventType, IN BOOLEAN InitialState)
Definition: event.c:96
#define INVALID_HANDLE_VALUE
Definition: compat.h:590
struct _RTLP_WAIT * PRTLP_WAIT
#define FALSE
Definition: types.h:117
#define EVENT_ALL_ACCESS
Definition: isotest.c:82
Status
Definition: gdiplustypes.h:24
#define InterlockedExchangePointer(Target, Value)
Definition: dshow.h:45
NTSTATUS NTAPI NtSetEvent(IN HANDLE EventHandle, OUT PLONG PreviousState OPTIONAL)
Definition: event.c:455
#define STATUS_PENDING
Definition: ntstatus.h:82
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3398
#define InterlockedIncrement
Definition: armddk.h:53
#define NULL
Definition: types.h:112
#define STATUS_SUCCESS
Definition: shellext.h:65
NTSYSAPI NTSTATUS NTAPI NtWaitForSingleObject(IN HANDLE hObject, IN BOOLEAN bAlertable, IN PLARGE_INTEGER Timeout)

Referenced by RtlDeregisterWait().

◆ RtlRegisterWait()

NTSTATUS NTAPI RtlRegisterWait ( PHANDLE  NewWaitObject,
HANDLE  Object,
WAITORTIMERCALLBACKFUNC  Callback,
PVOID  Context,
ULONG  Milliseconds,
ULONG  Flags 
)

Definition at line 132 of file wait.c.

138 {
141 
142  //TRACE( "(%p, %p, %p, %p, %d, 0x%x)\n", NewWaitObject, Object, Callback, Context, Milliseconds, Flags );
143 
144  Wait = RtlAllocateHeap( RtlGetProcessHeap(), 0, sizeof(RTLP_WAIT) );
145  if (!Wait)
146  return STATUS_NO_MEMORY;
147 
148  Wait->Object = Object;
149  Wait->Callback = Callback;
150  Wait->Context = Context;
151  Wait->Milliseconds = Milliseconds;
152  Wait->Flags = Flags;
153  Wait->CallbackInProgress = FALSE;
154  Wait->DeleteCount = 0;
155  Wait->CompletionEvent = NULL;
156 
157  Status = NtCreateEvent( &Wait->CancelEvent,
159  NULL,
161  FALSE );
162 
163  if (Status != STATUS_SUCCESS)
164  {
165  RtlFreeHeap( RtlGetProcessHeap(), 0, Wait );
166  return Status;
167  }
168 
171 
173  Wait,
174  Flags );
175 
176  if (Status != STATUS_SUCCESS)
177  {
178  NtClose( Wait->CancelEvent );
179  RtlFreeHeap( RtlGetProcessHeap(), 0, Wait );
180  return Status;
181  }
182 
183  *NewWaitObject = Wait;
184  return Status;
185 }
static VOID NTAPI Wait_thread_proc(LPVOID Arg)
Definition: wait.c:43
_In_ WDFDPC _In_ BOOLEAN Wait
Definition: wdfdpc.h:167
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
NTSYSAPI NTSTATUS NTAPI RtlQueueWorkItem(_In_ WORKERCALLBACKFUNC Function, _In_opt_ PVOID Context, _In_ ULONG Flags)
#define WT_EXECUTEINIOTHREAD
Definition: winnt_old.h:1073
NTSTATUS NTAPI NtCreateEvent(OUT PHANDLE EventHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, IN EVENT_TYPE EventType, IN BOOLEAN InitialState)
Definition: event.c:96
#define WT_TRANSFER_IMPERSONATION
Definition: winnt_old.h:1081
#define WT_EXECUTEINPERSISTENTTHREAD
Definition: winnt_old.h:1080
#define FALSE
Definition: types.h:117
#define EVENT_ALL_ACCESS
Definition: isotest.c:82
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
Status
Definition: gdiplustypes.h:24
#define WT_EXECUTELONGFUNCTION
Definition: winnt_old.h:1077
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3398
_Must_inspect_result_ _In_ WDFCOLLECTION _In_ WDFOBJECT Object
_In_ WDFINTERRUPT _In_ PFN_WDF_INTERRUPT_SYNCHRONIZE Callback
Definition: wdfinterrupt.h:456
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
#define NULL
Definition: types.h:112
struct tagContext Context
Definition: acpixf.h:1034
#define STATUS_SUCCESS
Definition: shellext.h:65

◆ Wait_thread_proc()

static VOID NTAPI Wait_thread_proc ( LPVOID  Arg)
static

Definition at line 43 of file wait.c.

44 {
45  PRTLP_WAIT Wait = (PRTLP_WAIT) Arg;
47  BOOLEAN alertable = (Wait->Flags & WT_EXECUTEINIOTHREAD) != 0;
48  HANDLE handles[2] = { Wait->CancelEvent, Wait->Object };
50  HANDLE completion_event;
51 
52 // TRACE("\n");
53 
54  while (TRUE)
55  {
57  handles,
58  WaitAny,
59  alertable,
60  get_nt_timeout( &timeout, Wait->Milliseconds ) );
61 
63  {
64  BOOLEAN TimerOrWaitFired;
65 
66  if (Status == STATUS_WAIT_1)
67  {
68  // TRACE( "object %p signaled, calling callback %p with context %p\n",
69  // Wait->Object, Wait->Callback,
70  // Wait->Context );
71  TimerOrWaitFired = FALSE;
72  }
73  else
74  {
75  // TRACE( "wait for object %p timed out, calling callback %p with context %p\n",
76  // Wait->Object, Wait->Callback,
77  // Wait->Context );
78  TimerOrWaitFired = TRUE;
79  }
80  Wait->CallbackInProgress = TRUE;
81  Wait->Callback( Wait->Context, TimerOrWaitFired );
82  Wait->CallbackInProgress = FALSE;
83 
84  if (Wait->Flags & WT_EXECUTEONLYONCE)
85  break;
86  }
87  else if (Status != STATUS_USER_APC)
88  break;
89  }
90 
91  completion_event = Wait->CompletionEvent;
92  if (completion_event) NtSetEvent( completion_event, NULL );
93 
94  if (InterlockedIncrement( &Wait->DeleteCount ) == 2 )
95  {
96  NtClose( Wait->CancelEvent );
97  RtlFreeHeap( RtlGetProcessHeap(), 0, Wait );
98  }
99 }
static struct object_header ** handles
Definition: handle.c:45
#define TRUE
Definition: types.h:120
_In_ WDFDPC _In_ BOOLEAN Wait
Definition: wdfdpc.h:167
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
#define WT_EXECUTEINIOTHREAD
Definition: winnt_old.h:1073
NTSTATUS NTAPI NtWaitForMultipleObjects(IN ULONG ObjectCount, IN PHANDLE HandleArray, IN WAIT_TYPE WaitType, IN BOOLEAN Alertable, IN PLARGE_INTEGER TimeOut OPTIONAL)
Definition: obwait.c:46
Definition: dhcpd.h:245
GLbitfield GLuint64 timeout
Definition: glext.h:7164
struct _RTLP_WAIT * PRTLP_WAIT
#define STATUS_TIMEOUT
Definition: ntstatus.h:81
#define STATUS_WAIT_1
Definition: ntstatus.h:71
static PLARGE_INTEGER get_nt_timeout(PLARGE_INTEGER pTime, ULONG timeout)
Definition: wait.c:34
#define FALSE
Definition: types.h:117
unsigned char BOOLEAN
Status
Definition: gdiplustypes.h:24
NTSTATUS NTAPI NtSetEvent(IN HANDLE EventHandle, OUT PLONG PreviousState OPTIONAL)
Definition: event.c:455
#define WT_EXECUTEONLYONCE
Definition: winnt_old.h:1076
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3398
#define STATUS_USER_APC
Definition: ntstatus.h:78
#define InterlockedIncrement
Definition: armddk.h:53
#define NULL
Definition: types.h:112

Referenced by RtlRegisterWait().