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

Go to the source code of this file.

Classes

struct  queue_timer
 
struct  timer_queue
 

Macros

#define NDEBUG
 
#define EXPIRE_NEVER   (~(ULONGLONG) 0)
 
#define TIMER_QUEUE_MAGIC   0x516d6954 /* TimQ */
 

Functions

NTSTATUS RtlpInitializeTimerThread (VOID)
 
static PLARGE_INTEGER get_nt_timeout (PLARGE_INTEGER pTime, ULONG timeout)
 
static void queue_remove_timer (struct queue_timer *t)
 
static void timer_cleanup_callback (struct queue_timer *t)
 
static VOID WINAPI timer_callback_wrapper (LPVOID p)
 
static ULONGLONG queue_current_time (void)
 
static void queue_add_timer (struct queue_timer *t, ULONGLONG time, BOOL set_event)
 
static void queue_move_timer (struct queue_timer *t, ULONGLONG time, BOOL set_event)
 
static void queue_timer_expire (struct timer_queue *q)
 
static ULONG queue_get_timeout (struct timer_queue *q)
 
static DWORD WINAPI timer_queue_thread_proc (LPVOID p)
 
static void queue_destroy_timer (struct queue_timer *t)
 
NTSTATUS WINAPI RtlCreateTimerQueue (PHANDLE NewTimerQueue)
 
NTSTATUS WINAPI RtlDeleteTimerQueueEx (HANDLE TimerQueue, HANDLE CompletionEvent)
 
static struct timer_queueget_timer_queue (HANDLE TimerQueue)
 
NTSTATUS WINAPI RtlCreateTimer (HANDLE TimerQueue, PHANDLE NewTimer, WAITORTIMERCALLBACKFUNC Callback, PVOID Parameter, DWORD DueTime, DWORD Period, ULONG Flags)
 
NTSTATUS WINAPI RtlSetTimer (HANDLE TimerQueue, PHANDLE NewTimer, WAITORTIMERCALLBACKFUNC Callback, PVOID Parameter, DWORD DueTime, DWORD Period, ULONG Flags)
 
NTSTATUS WINAPI RtlUpdateTimer (HANDLE TimerQueue, HANDLE Timer, DWORD DueTime, DWORD Period)
 
NTSTATUS WINAPI RtlDeleteTimer (HANDLE TimerQueue, HANDLE Timer, HANDLE CompletionEvent)
 
NTSTATUS NTAPI RtlCancelTimer (HANDLE TimerQueue, HANDLE Timer)
 
NTSTATUS NTAPI RtlDeleteTimerQueue (HANDLE TimerQueue)
 

Variables

PRTL_START_POOL_THREAD RtlpStartThreadFunc
 
PRTL_EXIT_POOL_THREAD RtlpExitThreadFunc
 
HANDLE TimerThreadHandle = NULL
 

Macro Definition Documentation

◆ EXPIRE_NEVER

#define EXPIRE_NEVER   (~(ULONGLONG) 0)

Definition at line 64 of file timerqueue.c.

◆ NDEBUG

#define NDEBUG

Definition at line 13 of file timerqueue.c.

◆ TIMER_QUEUE_MAGIC

#define TIMER_QUEUE_MAGIC   0x516d6954 /* TimQ */

Definition at line 65 of file timerqueue.c.

Function Documentation

◆ get_nt_timeout()

static PLARGE_INTEGER get_nt_timeout ( PLARGE_INTEGER  pTime,
ULONG  timeout 
)
inlinestatic

Definition at line 32 of file timerqueue.c.

33 {
34  if (timeout == INFINITE) return NULL;
35  pTime->QuadPart = (ULONGLONG)timeout * -10000;
36  return pTime;
37 }
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 timer_queue_thread_proc().

◆ get_timer_queue()

static struct timer_queue* get_timer_queue ( HANDLE  TimerQueue)
static

Definition at line 375 of file timerqueue.c.

376 {
377  static struct timer_queue *default_timer_queue;
378 
379  if (TimerQueue)
380  return TimerQueue;
381  else
382  {
383  if (!default_timer_queue)
384  {
385  HANDLE q;
387  if (status == STATUS_SUCCESS)
388  {
390  (void **) &default_timer_queue, q, NULL);
391  if (p)
392  /* Got beat to the punch. */
394  }
395  }
396  return default_timer_queue;
397  }
398 }
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS WINAPI RtlDeleteTimerQueueEx(HANDLE TimerQueue, HANDLE CompletionEvent)
Definition: timerqueue.c:331
NTSTATUS WINAPI RtlCreateTimerQueue(PHANDLE NewTimerQueue)
Definition: timerqueue.c:285
#define InterlockedCompareExchangePointer
Definition: interlocked.h:129
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063
#define NULL
Definition: types.h:112
#define STATUS_SUCCESS
Definition: shellext.h:65
GLfloat GLfloat p
Definition: glext.h:8902
Definition: ps.c:97

Referenced by RtlCreateTimer().

◆ queue_add_timer()

static void queue_add_timer ( struct queue_timer t,
ULONGLONG  time,
BOOL  set_event 
)
static

Definition at line 114 of file timerqueue.c.

116 {
117  /* We MUST hold the queue cs while calling this function. */
118  struct timer_queue *q = t->q;
119  struct list *ptr = &q->timers;
120 
121  assert(!q->quit || (t->destroy && time == EXPIRE_NEVER));
122 
123  if (time != EXPIRE_NEVER)
124  LIST_FOR_EACH(ptr, &q->timers)
125  {
126  struct queue_timer *cur = LIST_ENTRY(ptr, struct queue_timer, entry);
127  if (time < cur->expire)
128  break;
129  }
130  list_add_before(ptr, &t->entry);
131 
132  t->expire = time;
133 
134  /* If we insert at the head of the list, we need to expire sooner
135  than expected. */
136  if (set_event && &t->entry == list_head(&q->timers))
137  NtSetEvent(q->event, NULL);
138 }
#define EXPIRE_NEVER
Definition: timerqueue.c:64
GLdouble GLdouble t
Definition: gl.h:2047
#define assert(x)
Definition: debug.h:53
__u16 time
Definition: mkdosfs.c:366
Definition: list.h:15
static PVOID ptr
Definition: dispmode.c:27
#define LIST_FOR_EACH(cursor, list)
Definition: list.h:188
ULONGLONG expire
Definition: timerqueue.c:49
NTSTATUS NTAPI NtSetEvent(IN HANDLE EventHandle, OUT PLONG PreviousState OPTIONAL)
Definition: event.c:455
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063
uint32_t entry
Definition: isohybrid.c:63
Definition: _list.h:228
FxCollectionEntry * cur
#define NULL
Definition: types.h:112
__WINE_SERVER_LIST_INLINE void list_add_before(struct list *elem, struct list *to_add)
Definition: list.h:87
#define LIST_ENTRY(type)
Definition: queue.h:175

Referenced by queue_move_timer(), and RtlCreateTimer().

◆ queue_current_time()

static ULONGLONG queue_current_time ( void  )
inlinestatic

Definition at line 107 of file timerqueue.c.

108 {
109  LARGE_INTEGER now, freq;
111  return now.QuadPart * 1000 / freq.QuadPart;
112 }
NTSTATUS NTAPI NtQueryPerformanceCounter(OUT PLARGE_INTEGER PerformanceCounter, OUT PLARGE_INTEGER PerformanceFrequency OPTIONAL)
Definition: profile.c:274
time_t now
Definition: finger.c:65
LONGLONG QuadPart
Definition: typedefs.h:114

Referenced by queue_get_timeout(), queue_timer_expire(), RtlCreateTimer(), and RtlUpdateTimer().

◆ queue_destroy_timer()

static void queue_destroy_timer ( struct queue_timer t)
static

Definition at line 258 of file timerqueue.c.

259 {
260  /* We MUST hold the queue cs while calling this function. */
261  t->destroy = TRUE;
262  if (t->runcount == 0)
263  /* Ensure a timer is promptly removed. If callbacks are pending,
264  it will be removed after the last one finishes by the callback
265  cleanup wrapper. */
267  else
268  /* Make sure no destroyed timer masks an active timer at the head
269  of the sorted list. */
271 }
static void queue_move_timer(struct queue_timer *t, ULONGLONG time, BOOL set_event)
Definition: timerqueue.c:140
#define TRUE
Definition: types.h:120
#define EXPIRE_NEVER
Definition: timerqueue.c:64
GLdouble GLdouble t
Definition: gl.h:2047
static void queue_remove_timer(struct queue_timer *t)
Definition: timerqueue.c:67
#define FALSE
Definition: types.h:117

Referenced by RtlDeleteTimer(), and RtlDeleteTimerQueueEx().

◆ queue_get_timeout()

static ULONG queue_get_timeout ( struct timer_queue q)
static

Definition at line 193 of file timerqueue.c.

194 {
195  struct queue_timer *t;
197 
199  if (list_head(&q->timers))
200  {
201  t = LIST_ENTRY(list_head(&q->timers), struct queue_timer, entry);
202  assert(!t->destroy || t->expire == EXPIRE_NEVER);
203 
204  if (t->expire != EXPIRE_NEVER)
205  {
207  timeout = t->expire < time ? 0 : (ULONG)(t->expire - time);
208  }
209  }
211 
212  return timeout;
213 }
#define EXPIRE_NEVER
Definition: timerqueue.c:64
GLdouble GLdouble t
Definition: gl.h:2047
NTSYSAPI NTSTATUS NTAPI RtlEnterCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
#define assert(x)
Definition: debug.h:53
Definition: dhcpd.h:245
__u16 time
Definition: mkdosfs.c:366
GLbitfield GLuint64 timeout
Definition: glext.h:7164
__WINE_SERVER_LIST_INLINE struct list * list_head(const struct list *list)
Definition: list.h:131
NTSYSAPI NTSTATUS NTAPI RtlLeaveCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
uint64_t ULONGLONG
Definition: typedefs.h:67
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063
static ULONGLONG queue_current_time(void)
Definition: timerqueue.c:107
uint32_t entry
Definition: isohybrid.c:63
unsigned int ULONG
Definition: retypes.h:1
#define LIST_ENTRY(type)
Definition: queue.h:175
#define INFINITE
Definition: serial.h:102

Referenced by timer_queue_thread_proc().

◆ queue_move_timer()

static void queue_move_timer ( struct queue_timer t,
ULONGLONG  time,
BOOL  set_event 
)
inlinestatic

Definition at line 140 of file timerqueue.c.

142 {
143  /* We MUST hold the queue cs while calling this function. */
144  list_remove(&t->entry);
145  queue_add_timer(t, time, set_event);
146 }
GLdouble GLdouble t
Definition: gl.h:2047
__u16 time
Definition: mkdosfs.c:366
static void queue_add_timer(struct queue_timer *t, ULONGLONG time, BOOL set_event)
Definition: timerqueue.c:114
__WINE_SERVER_LIST_INLINE void list_remove(struct list *elem)
Definition: list.h:108

Referenced by queue_destroy_timer(), queue_timer_expire(), and RtlUpdateTimer().

◆ queue_remove_timer()

static void queue_remove_timer ( struct queue_timer t)
static

Definition at line 67 of file timerqueue.c.

68 {
69  /* We MUST hold the queue cs while calling this function. This ensures
70  that we cannot queue another callback for this timer. The runcount
71  being zero makes sure we don't have any already queued. */
72  struct timer_queue *q = t->q;
73 
74  assert(t->runcount == 0);
75  assert(t->destroy);
76 
77  list_remove(&t->entry);
78  if (t->event)
79  NtSetEvent(t->event, NULL);
80  RtlFreeHeap(RtlGetProcessHeap(), 0, t);
81 
82  if (q->quit && list_empty(&q->timers))
83  NtSetEvent(q->event, NULL);
84 }
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
GLdouble GLdouble t
Definition: gl.h:2047
#define assert(x)
Definition: debug.h:53
__WINE_SERVER_LIST_INLINE void list_remove(struct list *elem)
Definition: list.h:108
NTSTATUS NTAPI NtSetEvent(IN HANDLE EventHandle, OUT PLONG PreviousState OPTIONAL)
Definition: event.c:455
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063
__WINE_SERVER_LIST_INLINE int list_empty(const struct list *list)
Definition: list.h:143
#define NULL
Definition: types.h:112

Referenced by queue_destroy_timer(), and timer_cleanup_callback().

◆ queue_timer_expire()

static void queue_timer_expire ( struct timer_queue q)
static

Definition at line 148 of file timerqueue.c.

149 {
150  struct queue_timer *t = NULL;
151 
153  if (list_head(&q->timers))
154  {
155  ULONGLONG now, next;
156  t = LIST_ENTRY(list_head(&q->timers), struct queue_timer, entry);
157  if (!t->destroy && t->expire <= ((now = queue_current_time())))
158  {
159  ++t->runcount;
160  if (t->period)
161  {
162  next = t->expire + t->period;
163  /* avoid trigger cascade if overloaded / hibernated */
164  if (next < now)
165  next = now + t->period;
166  }
167  else
168  next = EXPIRE_NEVER;
170  }
171  else
172  t = NULL;
173  }
175 
176  if (t)
177  {
178  if (t->flags & WT_EXECUTEINTIMERTHREAD)
180  else
181  {
182  ULONG flags
183  = (t->flags
187  if (status != STATUS_SUCCESS)
189  }
190  }
191 }
static void queue_move_timer(struct queue_timer *t, ULONGLONG time, BOOL set_event)
Definition: timerqueue.c:140
#define EXPIRE_NEVER
Definition: timerqueue.c:64
LONG NTSTATUS
Definition: precomp.h:26
static VOID WINAPI timer_callback_wrapper(LPVOID p)
Definition: timerqueue.c:100
NTSYSAPI NTSTATUS NTAPI RtlQueueWorkItem(_In_ WORKERCALLBACKFUNC Function, _In_opt_ PVOID Context, _In_ ULONG Flags)
#define WT_EXECUTEINIOTHREAD
Definition: winnt_old.h:1073
GLdouble GLdouble t
Definition: gl.h:2047
NTSYSAPI NTSTATUS NTAPI RtlEnterCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
#define WT_TRANSFER_IMPERSONATION
Definition: winnt_old.h:1081
#define WT_EXECUTEINPERSISTENTTHREAD
Definition: winnt_old.h:1080
__WINE_SERVER_LIST_INLINE struct list * list_head(const struct list *list)
Definition: list.h:131
static void timer_cleanup_callback(struct queue_timer *t)
Definition: timerqueue.c:86
#define FALSE
Definition: types.h:117
NTSYSAPI NTSTATUS NTAPI RtlLeaveCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
time_t now
Definition: finger.c:65
#define WT_EXECUTELONGFUNCTION
Definition: winnt_old.h:1077
uint64_t ULONGLONG
Definition: typedefs.h:67
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063
GLbitfield flags
Definition: glext.h:7161
#define WT_EXECUTEINTIMERTHREAD
Definition: winnt_old.h:1078
static ULONGLONG queue_current_time(void)
Definition: timerqueue.c:107
uint32_t entry
Definition: isohybrid.c:63
static unsigned __int64 next
Definition: rand_nt.c:6
#define NULL
Definition: types.h:112
unsigned int ULONG
Definition: retypes.h:1
#define STATUS_SUCCESS
Definition: shellext.h:65
#define LIST_ENTRY(type)
Definition: queue.h:175
Definition: ps.c:97

Referenced by timer_queue_thread_proc().

◆ RtlCancelTimer()

NTSTATUS NTAPI RtlCancelTimer ( HANDLE  TimerQueue,
HANDLE  Timer 
)

Definition at line 585 of file timerqueue.c.

586 {
587  return RtlDeleteTimer(TimerQueue, Timer, NULL);
588 }
NTSTATUS WINAPI RtlDeleteTimer(HANDLE TimerQueue, HANDLE Timer, HANDLE CompletionEvent)
Definition: timerqueue.c:540
#define NULL
Definition: types.h:112

◆ RtlCreateTimer()

NTSTATUS WINAPI RtlCreateTimer ( HANDLE  TimerQueue,
PHANDLE  NewTimer,
WAITORTIMERCALLBACKFUNC  Callback,
PVOID  Parameter,
DWORD  DueTime,
DWORD  Period,
ULONG  Flags 
)

Definition at line 425 of file timerqueue.c.

429 {
431  struct queue_timer *t;
432  struct timer_queue *q = get_timer_queue(TimerQueue);
433 
434  if (!q) return STATUS_NO_MEMORY;
435  if (q->magic != TIMER_QUEUE_MAGIC) return STATUS_INVALID_HANDLE;
436 
437  t = RtlAllocateHeap(RtlGetProcessHeap(), 0, sizeof *t);
438  if (!t)
439  return STATUS_NO_MEMORY;
440 
441  t->q = q;
442  t->runcount = 0;
443  t->callback = Callback;
444  t->param = Parameter;
445  t->period = Period;
446  t->flags = Flags;
447  t->destroy = FALSE;
448  t->event = NULL;
449 
452  if (q->quit)
454  else
457 
458  if (status == STATUS_SUCCESS)
459  *NewTimer = t;
460  else
461  RtlFreeHeap(RtlGetProcessHeap(), 0, t);
462 
463  return status;
464 }
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
GLdouble GLdouble t
Definition: gl.h:2047
NTSYSAPI NTSTATUS NTAPI RtlEnterCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
_In_ LARGE_INTEGER _In_ ULONG Period
Definition: kefuncs.h:1324
_In_ PVOID Parameter
Definition: ldrtypes.h:241
#define STATUS_INVALID_HANDLE
Definition: ntstatus.h:245
static void queue_add_timer(struct queue_timer *t, ULONGLONG time, BOOL set_event)
Definition: timerqueue.c:114
#define FALSE
Definition: types.h:117
NTSYSAPI NTSTATUS NTAPI RtlLeaveCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
static struct timer_queue * get_timer_queue(HANDLE TimerQueue)
Definition: timerqueue.c:375
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
#define TIMER_QUEUE_MAGIC
Definition: timerqueue.c:65
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063
static ULONGLONG queue_current_time(void)
Definition: timerqueue.c:107
_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
_In_ WDFTIMER _In_ LONGLONG DueTime
Definition: wdftimer.h:187
#define STATUS_SUCCESS
Definition: shellext.h:65
static SERVICE_STATUS status
Definition: service.c:31
Definition: ps.c:97

Referenced by CreateTimerQueueTimer(), RtlSetTimer(), and SetTimerQueueTimer().

◆ RtlCreateTimerQueue()

NTSTATUS WINAPI RtlCreateTimerQueue ( PHANDLE  NewTimerQueue)

Definition at line 285 of file timerqueue.c.

286 {
288  struct timer_queue *q = RtlAllocateHeap(RtlGetProcessHeap(), 0, sizeof *q);
289  if (!q)
290  return STATUS_NO_MEMORY;
291 
293  list_init(&q->timers);
294  q->quit = FALSE;
295  q->magic = TIMER_QUEUE_MAGIC;
297  if (status != STATUS_SUCCESS)
298  {
299  RtlFreeHeap(RtlGetProcessHeap(), 0, q);
300  return status;
301  }
303  if (status != STATUS_SUCCESS)
304  {
305  NtClose(q->event);
306  RtlFreeHeap(RtlGetProcessHeap(), 0, q);
307  return status;
308  }
309 
310  NtResumeThread(q->thread, NULL);
311  *NewTimerQueue = q;
312  return STATUS_SUCCESS;
313 }
PRTL_START_POOL_THREAD RtlpStartThreadFunc
Definition: workitem.c:45
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 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
NTSTATUS NTAPI NtResumeThread(IN HANDLE ThreadHandle, OUT PULONG SuspendCount OPTIONAL)
Definition: state.c:290
NTSYSAPI NTSTATUS NTAPI RtlInitializeCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
#define TIMER_QUEUE_MAGIC
Definition: timerqueue.c:65
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3398
static DWORD WINAPI timer_queue_thread_proc(LPVOID p)
Definition: timerqueue.c:215
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
#define NULL
Definition: types.h:112
__WINE_SERVER_LIST_INLINE void list_init(struct list *list)
Definition: list.h:149
#define STATUS_SUCCESS
Definition: shellext.h:65
static SERVICE_STATUS status
Definition: service.c:31
Definition: ps.c:97

Referenced by BasepCreateDefaultTimerQueue(), CreateTimerQueue(), and get_timer_queue().

◆ RtlDeleteTimer()

NTSTATUS WINAPI RtlDeleteTimer ( HANDLE  TimerQueue,
HANDLE  Timer,
HANDLE  CompletionEvent 
)

Definition at line 540 of file timerqueue.c.

542 {
543  struct queue_timer *t = Timer;
544  struct timer_queue *q;
546  HANDLE event = NULL;
547 
548  if (!Timer)
550  q = t->q;
551  if (CompletionEvent == INVALID_HANDLE_VALUE)
552  {
554  if (status == STATUS_SUCCESS)
556  }
557  else if (CompletionEvent)
558  event = CompletionEvent;
559 
561  t->event = event;
562  if (t->runcount == 0 && event)
566 
567  if (CompletionEvent == INVALID_HANDLE_VALUE && event)
568  {
569  if (status == STATUS_PENDING)
570  {
573  }
574  NtClose(event);
575  }
576 
577  return status;
578 }
LONG NTSTATUS
Definition: precomp.h:26
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
GLdouble GLdouble t
Definition: gl.h:2047
NTSYSAPI NTSTATUS NTAPI RtlEnterCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
#define INVALID_HANDLE_VALUE
Definition: compat.h:590
#define FALSE
Definition: types.h:117
NTSYSAPI NTSTATUS NTAPI RtlLeaveCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
#define EVENT_ALL_ACCESS
Definition: isotest.c:82
static void queue_destroy_timer(struct queue_timer *t)
Definition: timerqueue.c:258
#define STATUS_PENDING
Definition: ntstatus.h:82
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3398
#define STATUS_INVALID_PARAMETER_1
Definition: ntstatus.h:475
struct _cl_event * event
Definition: glext.h:7739
_Must_inspect_result_ _In_ PWDF_TIMER_CONFIG _In_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFTIMER * Timer
Definition: wdftimer.h:153
#define NULL
Definition: types.h:112
#define STATUS_SUCCESS
Definition: shellext.h:65
static SERVICE_STATUS status
Definition: service.c:31
Definition: ps.c:97
NTSYSAPI NTSTATUS NTAPI NtWaitForSingleObject(IN HANDLE hObject, IN BOOLEAN bAlertable, IN PLARGE_INTEGER Timeout)

Referenced by CancelTimerQueueTimer(), DeleteTimerQueueTimer(), and RtlCancelTimer().

◆ RtlDeleteTimerQueue()

NTSTATUS NTAPI RtlDeleteTimerQueue ( HANDLE  TimerQueue)

Definition at line 595 of file timerqueue.c.

596 {
597  return RtlDeleteTimerQueueEx(TimerQueue, INVALID_HANDLE_VALUE);
598 }
#define INVALID_HANDLE_VALUE
Definition: compat.h:590
NTSTATUS WINAPI RtlDeleteTimerQueueEx(HANDLE TimerQueue, HANDLE CompletionEvent)
Definition: timerqueue.c:331

◆ RtlDeleteTimerQueueEx()

NTSTATUS WINAPI RtlDeleteTimerQueueEx ( HANDLE  TimerQueue,
HANDLE  CompletionEvent 
)

Definition at line 331 of file timerqueue.c.

332 {
333  struct timer_queue *q = TimerQueue;
334  struct queue_timer *t, *temp;
335  HANDLE thread;
337 
338  if (!q || q->magic != TIMER_QUEUE_MAGIC)
339  return STATUS_INVALID_HANDLE;
340 
341  thread = q->thread;
342 
344  q->quit = TRUE;
345  if (list_head(&q->timers))
346  /* When the last timer is removed, it will signal the timer thread to
347  exit... */
348  LIST_FOR_EACH_ENTRY_SAFE(t, temp, &q->timers, struct queue_timer, entry)
350  else
351  /* However if we have none, we must do it ourselves. */
352  NtSetEvent(q->event, NULL);
354 
355  if (CompletionEvent == INVALID_HANDLE_VALUE)
356  {
359  }
360  else
361  {
362  if (CompletionEvent)
363  {
364  DPRINT1("asynchronous return on completion event unimplemented\n");
366  NtSetEvent(CompletionEvent, NULL);
367  }
369  }
370 
371  NtClose(thread);
372  return status;
373 }
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
GLdouble GLdouble t
Definition: gl.h:2047
NTSYSAPI NTSTATUS NTAPI RtlEnterCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
#define INVALID_HANDLE_VALUE
Definition: compat.h:590
#define STATUS_INVALID_HANDLE
Definition: ntstatus.h:245
__WINE_SERVER_LIST_INLINE struct list * list_head(const struct list *list)
Definition: list.h:131
#define FALSE
Definition: types.h:117
NTSYSAPI NTSTATUS NTAPI RtlLeaveCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
static void queue_destroy_timer(struct queue_timer *t)
Definition: timerqueue.c:258
NTSTATUS NTAPI NtSetEvent(IN HANDLE EventHandle, OUT PLONG PreviousState OPTIONAL)
Definition: event.c:455
#define STATUS_PENDING
Definition: ntstatus.h:82
#define TIMER_QUEUE_MAGIC
Definition: timerqueue.c:65
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3398
static HANDLE thread
Definition: service.c:33
uint32_t entry
Definition: isohybrid.c:63
#define LIST_FOR_EACH_ENTRY_SAFE(cursor, cursor2, list, type, field)
Definition: list.h:204
static calc_node_t temp
Definition: rpn_ieee.c:38
#define NULL
Definition: types.h:112
#define DPRINT1
Definition: precomp.h:8
#define STATUS_SUCCESS
Definition: shellext.h:65
static SERVICE_STATUS status
Definition: service.c:31
Definition: ps.c:97
NTSYSAPI NTSTATUS NTAPI NtWaitForSingleObject(IN HANDLE hObject, IN BOOLEAN bAlertable, IN PLARGE_INTEGER Timeout)

Referenced by DeleteTimerQueue(), DeleteTimerQueueEx(), get_timer_queue(), and RtlDeleteTimerQueue().

◆ RtlpInitializeTimerThread()

NTSTATUS RtlpInitializeTimerThread ( VOID  )

Definition at line 27 of file timerqueue.c.

28 {
30 }
return STATUS_NOT_IMPLEMENTED

Referenced by RtlpQueueWorkerThread().

◆ RtlSetTimer()

NTSTATUS WINAPI RtlSetTimer ( HANDLE  TimerQueue,
PHANDLE  NewTimer,
WAITORTIMERCALLBACKFUNC  Callback,
PVOID  Parameter,
DWORD  DueTime,
DWORD  Period,
ULONG  Flags 
)

Definition at line 468 of file timerqueue.c.

476 {
477  return RtlCreateTimer(TimerQueue,
478  NewTimer,
479  Callback,
480  Parameter,
481  DueTime,
482  Period,
483  Flags);
484 }
_In_ LARGE_INTEGER _In_ ULONG Period
Definition: kefuncs.h:1324
_In_ PVOID Parameter
Definition: ldrtypes.h:241
NTSTATUS WINAPI RtlCreateTimer(HANDLE TimerQueue, PHANDLE NewTimer, WAITORTIMERCALLBACKFUNC Callback, PVOID Parameter, DWORD DueTime, DWORD Period, ULONG Flags)
Definition: timerqueue.c:425
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
_In_ WDFINTERRUPT _In_ PFN_WDF_INTERRUPT_SYNCHRONIZE Callback
Definition: wdfinterrupt.h:456
_In_ WDFTIMER _In_ LONGLONG DueTime
Definition: wdftimer.h:187

◆ RtlUpdateTimer()

NTSTATUS WINAPI RtlUpdateTimer ( HANDLE  TimerQueue,
HANDLE  Timer,
DWORD  DueTime,
DWORD  Period 
)

Definition at line 504 of file timerqueue.c.

506 {
507  struct queue_timer *t = Timer;
508  struct timer_queue *q = t->q;
509 
511  /* Can't change a timer if it was once-only or destroyed. */
512  if (t->expire != EXPIRE_NEVER)
513  {
514  t->period = Period;
516  }
518 
519  return STATUS_SUCCESS;
520 }
static void queue_move_timer(struct queue_timer *t, ULONGLONG time, BOOL set_event)
Definition: timerqueue.c:140
#define TRUE
Definition: types.h:120
#define EXPIRE_NEVER
Definition: timerqueue.c:64
GLdouble GLdouble t
Definition: gl.h:2047
NTSYSAPI NTSTATUS NTAPI RtlEnterCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
_In_ LARGE_INTEGER _In_ ULONG Period
Definition: kefuncs.h:1324
NTSYSAPI NTSTATUS NTAPI RtlLeaveCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063
static ULONGLONG queue_current_time(void)
Definition: timerqueue.c:107
_Must_inspect_result_ _In_ PWDF_TIMER_CONFIG _In_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFTIMER * Timer
Definition: wdftimer.h:153
_In_ WDFTIMER _In_ LONGLONG DueTime
Definition: wdftimer.h:187
#define STATUS_SUCCESS
Definition: shellext.h:65

Referenced by ChangeTimerQueueTimer().

◆ timer_callback_wrapper()

static VOID WINAPI timer_callback_wrapper ( LPVOID  p)
static

Definition at line 100 of file timerqueue.c.

101 {
102  struct queue_timer *t = p;
103  t->callback(t->param, TRUE);
105 }
#define TRUE
Definition: types.h:120
GLdouble GLdouble t
Definition: gl.h:2047
static void timer_cleanup_callback(struct queue_timer *t)
Definition: timerqueue.c:86
GLfloat GLfloat p
Definition: glext.h:8902

Referenced by queue_timer_expire().

◆ timer_cleanup_callback()

static void timer_cleanup_callback ( struct queue_timer t)
static

Definition at line 86 of file timerqueue.c.

87 {
88  struct timer_queue *q = t->q;
90 
91  assert(0 < t->runcount);
92  --t->runcount;
93 
94  if (t->destroy && t->runcount == 0)
96 
98 }
GLdouble GLdouble t
Definition: gl.h:2047
NTSYSAPI NTSTATUS NTAPI RtlEnterCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
#define assert(x)
Definition: debug.h:53
static void queue_remove_timer(struct queue_timer *t)
Definition: timerqueue.c:67
NTSYSAPI NTSTATUS NTAPI RtlLeaveCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063

Referenced by queue_timer_expire(), and timer_callback_wrapper().

◆ timer_queue_thread_proc()

static DWORD WINAPI timer_queue_thread_proc ( LPVOID  p)
static

Definition at line 215 of file timerqueue.c.

216 {
217  struct timer_queue *q = p;
218  ULONG timeout_ms;
219 
220  timeout_ms = INFINITE;
221  for (;;)
222  {
225  BOOL done = FALSE;
226 
228  q->event, FALSE, get_nt_timeout(&timeout, timeout_ms));
229 
230  if (status == STATUS_WAIT_0)
231  {
232  /* There are two possible ways to trigger the event. Either
233  we are quitting and the last timer got removed, or a new
234  timer got put at the head of the list so we need to adjust
235  our timeout. */
237  if (q->quit && list_empty(&q->timers))
238  done = TRUE;
240  }
241  else if (status == STATUS_TIMEOUT)
243 
244  if (done)
245  break;
246 
247  timeout_ms = queue_get_timeout(q);
248  }
249 
250  NtClose(q->event);
252  q->magic = 0;
253  RtlFreeHeap(RtlGetProcessHeap(), 0, q);
255  return 0;
256 }
#define TRUE
Definition: types.h:120
PRTL_EXIT_POOL_THREAD RtlpExitThreadFunc
Definition: workitem.c:46
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 RtlEnterCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
static ULONG queue_get_timeout(struct timer_queue *q)
Definition: timerqueue.c:193
Definition: dhcpd.h:245
static PLARGE_INTEGER get_nt_timeout(PLARGE_INTEGER pTime, ULONG timeout)
Definition: timerqueue.c:32
GLbitfield GLuint64 timeout
Definition: glext.h:7164
#define STATUS_TIMEOUT
Definition: ntstatus.h:81
#define STATUS_WAIT_0
Definition: ntstatus.h:237
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
NTSYSAPI NTSTATUS NTAPI RtlLeaveCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3398
__WINE_SERVER_LIST_INLINE int list_empty(const struct list *list)
Definition: list.h:143
static void queue_timer_expire(struct timer_queue *q)
Definition: timerqueue.c:148
unsigned int ULONG
Definition: retypes.h:1
#define STATUS_SUCCESS
Definition: shellext.h:65
GLfloat GLfloat p
Definition: glext.h:8902
NTSYSAPI NTSTATUS NTAPI RtlDeleteCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
#define INFINITE
Definition: serial.h:102
static SERVICE_STATUS status
Definition: service.c:31
Definition: ps.c:97
NTSYSAPI NTSTATUS NTAPI NtWaitForSingleObject(IN HANDLE hObject, IN BOOLEAN bAlertable, IN PLARGE_INTEGER Timeout)

Referenced by RtlCreateTimerQueue().

Variable Documentation

◆ RtlpExitThreadFunc

◆ RtlpStartThreadFunc

PRTL_START_POOL_THREAD RtlpStartThreadFunc

◆ TimerThreadHandle

HANDLE TimerThreadHandle = NULL

Definition at line 24 of file timerqueue.c.

Referenced by RtlpQueueWorkerThread().