ReactOS 0.4.16-dev-570-g1868985
timer.c File Reference
#include <win32k.h>
Include dependency graph for timer.c:

Go to the source code of this file.

Macros

#define MAX_WINDOW_LESS_TIMER_ID   (32768 - 1)
 
#define NUM_WINDOW_LESS_TIMERS   (32768 - 256)
 
#define HINTINDEX_BEGIN_VALUE   0
 
#define IntLockWindowlessTimerBitmap()    ExEnterCriticalRegionAndAcquireFastMutexUnsafe(Mutex)
 
#define IntUnlockWindowlessTimerBitmap()    ExReleaseFastMutexUnsafeAndLeaveCriticalRegion(Mutex)
 
#define TimerEnterExclusive()
 
#define TimerLeave()
 

Functions

 DBG_DEFAULT_CHANNEL (UserTimer)
 
static PTIMER FASTCALL CreateTimer (VOID)
 
static BOOL FASTCALL RemoveTimer (PTIMER pTmr)
 
PTIMER FASTCALL FindTimer (PWND Window, UINT_PTR nID, UINT flags)
 
PTIMER FASTCALL FindSystemTimer (PMSG pMsg)
 
BOOL FASTCALL ValidateTimerCallback (PTHREADINFO pti, LPARAM lParam)
 
UINT_PTR FASTCALL IntSetTimer (PWND Window, UINT_PTR IDEvent, UINT Elapse, TIMERPROC TimerFunc, INT Type)
 
VOID CALLBACK SystemTimerProc (HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)
 
VOID FASTCALL StartTheTimers (VOID)
 
UINT_PTR FASTCALL SystemTimerSet (PWND Window, UINT_PTR nIDEvent, UINT uElapse, TIMERPROC lpTimerFunc)
 
BOOL FASTCALL PostTimerMessages (PWND Window)
 
VOID FASTCALL ProcessTimers (VOID)
 
BOOL FASTCALL DestroyTimersForWindow (PTHREADINFO pti, PWND Window)
 
BOOL FASTCALL DestroyTimersForThread (PTHREADINFO pti)
 
BOOL FASTCALL IntKillTimer (PWND Window, UINT_PTR IDEvent, BOOL SystemTimer)
 
NTSTATUS NTAPI InitTimerImpl (VOID)
 
UINT_PTR APIENTRY NtUserSetTimer (HWND hWnd, UINT_PTR nIDEvent, UINT uElapse, TIMERPROC lpTimerFunc)
 
BOOL APIENTRY NtUserKillTimer (HWND hWnd, UINT_PTR uIDEvent)
 
UINT_PTR APIENTRY NtUserSetSystemTimer (HWND hWnd, UINT_PTR nIDEvent, UINT uElapse, TIMERPROC lpTimerFunc)
 
BOOL APIENTRY NtUserValidateTimerCallback (LPARAM lParam)
 

Variables

static LIST_ENTRY TimersListHead
 
static LONG TimeLast = 0
 
static PFAST_MUTEX Mutex
 
static RTL_BITMAP WindowLessTimersBitMap
 
static PVOID WindowLessTimersBitMapBuffer
 
static ULONG HintIndex = HINTINDEX_BEGIN_VALUE
 
ERESOURCE TimerLock
 

Macro Definition Documentation

◆ HINTINDEX_BEGIN_VALUE

#define HINTINDEX_BEGIN_VALUE   0

Definition at line 24 of file timer.c.

◆ IntLockWindowlessTimerBitmap

#define IntLockWindowlessTimerBitmap ( )     ExEnterCriticalRegionAndAcquireFastMutexUnsafe(Mutex)

Definition at line 33 of file timer.c.

◆ IntUnlockWindowlessTimerBitmap

#define IntUnlockWindowlessTimerBitmap ( )     ExReleaseFastMutexUnsafeAndLeaveCriticalRegion(Mutex)

Definition at line 36 of file timer.c.

◆ MAX_WINDOW_LESS_TIMER_ID

#define MAX_WINDOW_LESS_TIMER_ID   (32768 - 1)

Definition at line 21 of file timer.c.

◆ NUM_WINDOW_LESS_TIMERS

#define NUM_WINDOW_LESS_TIMERS   (32768 - 256)

Definition at line 22 of file timer.c.

◆ TimerEnterExclusive

#define TimerEnterExclusive ( )
Value:
{ \
KeEnterCriticalRegion(); \
ExAcquireResourceExclusiveLite(&TimerLock, TRUE); \
}
#define TRUE
Definition: types.h:120
ERESOURCE TimerLock
Definition: timer.c:31

Definition at line 39 of file timer.c.

◆ TimerLeave

#define TimerLeave ( )
Value:
{ \
ExReleaseResourceLite(&TimerLock); \
KeLeaveCriticalRegion(); \
}

Definition at line 45 of file timer.c.

Function Documentation

◆ CreateTimer()

static PTIMER FASTCALL CreateTimer ( VOID  )
static

Definition at line 56 of file timer.c.

57{
59 PTIMER Ret = NULL;
60
62 if (Ret)
63 {
66 }
67
68 return Ret;
69}
#define NULL
Definition: types.h:112
#define InsertTailList(ListHead, Entry)
ULONG Handle
Definition: gdb_input.c:15
@ TYPE_TIMER
Definition: ntuser.h:56
#define UserHMSetHandle(obj, handle)
Definition: ntuser.h:231
Definition: timer.h:4
LIST_ENTRY ptmrList
Definition: timer.h:6
PUSER_HANDLE_TABLE gHandleTable
Definition: object.c:13
PVOID FASTCALL UserCreateObject(PUSER_HANDLE_TABLE ht, PDESKTOP pDesktop, PTHREADINFO pti, HANDLE *h, HANDLE_TYPE type, ULONG size)
Definition: object.c:568
static LIST_ENTRY TimersListHead
Definition: timer.c:16

◆ DBG_DEFAULT_CHANNEL()

DBG_DEFAULT_CHANNEL ( UserTimer  )

◆ DestroyTimersForThread()

BOOL FASTCALL DestroyTimersForThread ( PTHREADINFO  pti)

Definition at line 555 of file timer.c.

556{
558 PTIMER pTmr;
559 BOOL TimersRemoved = FALSE;
560
562
563 while(pLE != &TimersListHead)
564 {
565 pTmr = CONTAINING_RECORD(pLE, TIMER, ptmrList);
566 pLE = pLE->Flink; /* get next timer list entry before current timer is removed */
567 if ((pTmr) && (pTmr->pti == pti))
568 {
569 TimersRemoved = RemoveTimer(pTmr);
570 }
571 }
572
573 TimerLeave();
574
575 return TimersRemoved;
576}
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
PTHREADINFO pti
Definition: timer.h:7
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
#define TimerLeave()
Definition: timer.c:45
static BOOL FASTCALL RemoveTimer(PTIMER pTmr)
Definition: timer.c:74
#define TimerEnterExclusive()
Definition: timer.c:39

Referenced by ExitThreadCallback().

◆ DestroyTimersForWindow()

BOOL FASTCALL DestroyTimersForWindow ( PTHREADINFO  pti,
PWND  Window 
)

Definition at line 528 of file timer.c.

529{
530 PLIST_ENTRY pLE;
531 PTIMER pTmr;
532 BOOL TimersRemoved = FALSE;
533
534 if (Window == NULL)
535 return FALSE;
536
538 pLE = TimersListHead.Flink;
539 while(pLE != &TimersListHead)
540 {
541 pTmr = CONTAINING_RECORD(pLE, TIMER, ptmrList);
542 pLE = pLE->Flink; /* get next timer list entry before current timer is removed */
543 if ((pTmr) && (pTmr->pti == pti) && (pTmr->pWnd == Window))
544 {
545 TimersRemoved = RemoveTimer(pTmr);
546 }
547 }
548
549 TimerLeave();
550
551 return TimersRemoved;
552}
Definition: window.c:28
PWND pWnd
Definition: timer.h:8

Referenced by co_UserFreeWindow(), and IntClientShutdown().

◆ FindSystemTimer()

PTIMER FASTCALL FindSystemTimer ( PMSG  pMsg)

Definition at line 131 of file timer.c.

132{
133 PLIST_ENTRY pLE;
134 PTIMER pTmr = NULL;
135
137 pLE = TimersListHead.Flink;
138 while (pLE != &TimersListHead)
139 {
140 pTmr = CONTAINING_RECORD(pLE, TIMER, ptmrList);
141
142 if ( pMsg->lParam == (LPARAM)pTmr->pfn &&
143 (pTmr->flags & TMRF_SYSTEM) )
144 break;
145
146 pLE = pLE->Flink;
147 }
148 TimerLeave();
149
150 return pTmr;
151}
TIMERPROC pfn
Definition: timer.h:13
FLONG flags
Definition: timer.h:12
LPARAM lParam
Definition: winuser.h:3120
#define TMRF_SYSTEM
Definition: timer.h:20
LONG_PTR LPARAM
Definition: windef.h:208

Referenced by IntDispatchMessage().

◆ FindTimer()

PTIMER FASTCALL FindTimer ( PWND  Window,
UINT_PTR  nID,
UINT  flags 
)

Definition at line 101 of file timer.c.

104{
105 PLIST_ENTRY pLE;
106 PTIMER pTmr, RetTmr = NULL;
107
109 pLE = TimersListHead.Flink;
110 while (pLE != &TimersListHead)
111 {
112 pTmr = CONTAINING_RECORD(pLE, TIMER, ptmrList);
113
114 if ( pTmr->nID == nID &&
115 pTmr->pWnd == Window &&
116 (pTmr->flags & (TMRF_SYSTEM|TMRF_RIT)) == (flags & (TMRF_SYSTEM|TMRF_RIT)))
117 {
118 RetTmr = pTmr;
119 break;
120 }
121
122 pLE = pLE->Flink;
123 }
124 TimerLeave();
125
126 return RetTmr;
127}
GLbitfield flags
Definition: glext.h:7161
UINT_PTR nID
Definition: timer.h:9
#define TMRF_RIT
Definition: timer.h:21

Referenced by IntKillTimer(), and IntSetTimer().

◆ InitTimerImpl()

NTSTATUS NTAPI InitTimerImpl ( VOID  )

Definition at line 600 of file timer.c.

601{
602 ULONG BitmapBytes;
603
604 /* Allocate FAST_MUTEX from non paged pool */
606 if (!Mutex)
607 {
609 }
610
612
613 BitmapBytes = ALIGN_UP_BY(NUM_WINDOW_LESS_TIMERS, sizeof(ULONG) * 8) / 8;
616 {
617 return STATUS_UNSUCCESSFUL;
618 }
619
623
624 /* Yes we need this, since ExAllocatePoolWithTag isn't supposed to zero out allocated memory */
626
629
630 return STATUS_SUCCESS;
631}
#define ALIGN_UP_BY(size, align)
Definition: Mutex.h:16
#define RtlInitializeBitMap
Definition: dbgbitmap.h:326
#define RtlClearAllBits
Definition: dbgbitmap.h:329
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
NTSTATUS ExInitializeResourceLite(PULONG res)
Definition: env_spec_w32.h:641
#define NonPagedPool
Definition: env_spec_w32.h:307
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define STATUS_SUCCESS
Definition: shellext.h:65
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define TAG_INTERNAL_SYNC
Definition: tags.h:18
#define TAG_TIMERBMP
Definition: tags.h:10
#define NUM_WINDOW_LESS_TIMERS
Definition: timer.c:22
static RTL_BITMAP WindowLessTimersBitMap
Definition: timer.c:27
static PVOID WindowLessTimersBitMapBuffer
Definition: timer.c:28
FORCEINLINE VOID ExInitializeFastMutex(_Out_ PFAST_MUTEX FastMutex)
Definition: exfuncs.h:274
FAST_MUTEX
Definition: extypes.h:17

Referenced by DriverEntry().

◆ IntKillTimer()

BOOL FASTCALL IntKillTimer ( PWND  Window,
UINT_PTR  IDEvent,
BOOL  SystemTimer 
)

Definition at line 579 of file timer.c.

580{
581 PTIMER pTmr = NULL;
582 TRACE("IntKillTimer Window %p id %uI systemtimer %s\n",
583 Window, IDEvent, SystemTimer ? "TRUE" : "FALSE");
584
586 pTmr = FindTimer(Window, IDEvent, SystemTimer ? TMRF_SYSTEM : 0);
587
588 if (pTmr)
589 {
590 RemoveTimer(pTmr);
591 }
592 TimerLeave();
593
594 return pTmr ? TRUE : FALSE;
595}
#define TRACE(s)
Definition: solgame.cpp:4
PTIMER FASTCALL FindTimer(PWND Window, UINT_PTR nID, UINT flags)
Definition: timer.c:101

Referenced by co_UserHideCaret(), IntFlashWindowEx(), IntRemoveTrackMouseEvent(), IntTrackMouseEvent(), IntTrackMouseMove(), NtUserCallHwndParam(), NtUserCreateCaret(), NtUserKillTimer(), and SystemTimerProc().

◆ IntSetTimer()

UINT_PTR FASTCALL IntSetTimer ( PWND  Window,
UINT_PTR  IDEvent,
UINT  Elapse,
TIMERPROC  TimerFunc,
INT  Type 
)

Definition at line 182 of file timer.c.

187{
188 PTIMER pTmr;
189 UINT_PTR Ret = IDEvent;
190 ULONG ulBitmapIndex;
192 DueTime.QuadPart = (LONGLONG)(-97656); // 1024hz .9765625 ms set to 10.0 ms
193
194#if 0
195 /* Windows NT/2k/XP behaviour */
196 if (Elapse > USER_TIMER_MAXIMUM)
197 {
198 TRACE("Adjusting uElapse\n");
199 Elapse = 1;
200 }
201#else
202 /* Windows XP SP2 and Windows Server 2003 behaviour */
203 if (Elapse > USER_TIMER_MAXIMUM)
204 {
205 TRACE("Adjusting uElapse\n");
206 Elapse = USER_TIMER_MAXIMUM;
207 }
208#endif
209
210 /* Windows 2k/XP and Windows Server 2003 SP1 behaviour */
211 if (Elapse < USER_TIMER_MINIMUM)
212 {
213 TRACE("Adjusting uElapse\n");
214 Elapse = USER_TIMER_MINIMUM; // 1024hz .9765625 ms, set to 10.0 ms (+/-)1 ms
215 }
216
217 /* Passing an IDEvent of 0 and the SetTimer returns 1.
218 It will create the timer with an ID of 0 */
219 if ((Window) && (IDEvent == 0))
220 Ret = 1;
221
222 pTmr = FindTimer(Window, IDEvent, Type);
223
224 if ((!pTmr) && (Window == NULL) && (!(Type & TMRF_SYSTEM)))
225 {
227
229 HintIndex = (ulBitmapIndex + 1) % NUM_WINDOW_LESS_TIMERS;
230 if (ulBitmapIndex == ULONG_MAX)
231 {
233 ERR("Unable to find a free window-less timer id\n");
235 return 0;
236 }
237
238 ASSERT(ulBitmapIndex < NUM_WINDOW_LESS_TIMERS);
239 IDEvent = MAX_WINDOW_LESS_TIMER_ID - ulBitmapIndex;
240 Ret = IDEvent;
241
243 }
244
245 if (!pTmr)
246 {
247 pTmr = CreateTimer();
248 if (!pTmr) return 0;
249
250 if (Window && (Type & TMRF_TIFROMWND))
251 pTmr->pti = Window->head.pti->pEThread->Tcb.Win32Thread;
252 else
253 {
254 if (Type & TMRF_RIT)
255 pTmr->pti = ptiRawInput;
256 else
258 }
259
260 pTmr->pWnd = Window;
261 pTmr->cmsCountdown = Elapse;
262 pTmr->cmsRate = Elapse;
263 pTmr->pfn = TimerFunc;
264 pTmr->nID = IDEvent;
265 pTmr->flags = Type|TMRF_INIT;
266 }
267 else
268 {
269 pTmr->cmsCountdown = Elapse;
270 pTmr->cmsRate = Elapse;
271 }
272
274 // Start the timer thread!
275 if (TimersListHead.Flink == TimersListHead.Blink) // There is only one timer
277
278 return Ret;
279}
Type
Definition: Type.h:7
#define ERR(fmt,...)
Definition: precomp.h:57
#define RtlFindClearBitsAndSet
Definition: dbgbitmap.h:333
return pRequest CreateTimer()
#define ULONG_MAX
Definition: intsafe.h:155
#define ASSERT(a)
Definition: mode.c:44
unsigned __int3264 UINT_PTR
Definition: mstsclib_h.h:274
PVOID NTAPI PsGetCurrentThreadWin32Thread(VOID)
Definition: thread.c:805
struct _LIST_ENTRY * Blink
Definition: typedefs.h:122
INT cmsRate
Definition: timer.h:11
INT cmsCountdown
Definition: timer.h:10
BOOLEAN NTAPI KeSetTimer(IN OUT PKTIMER Timer, IN LARGE_INTEGER DueTime, IN PKDPC Dpc OPTIONAL)
Definition: timerobj.c:281
int64_t LONGLONG
Definition: typedefs.h:68
_In_ WDFTIMER _In_ LONGLONG DueTime
Definition: wdftimer.h:190
PTHREADINFO ptiRawInput
Definition: input.c:15
PKTIMER MasterTimer
Definition: input.c:16
#define IntLockWindowlessTimerBitmap()
Definition: timer.c:33
#define IntUnlockWindowlessTimerBitmap()
Definition: timer.c:36
static ULONG HintIndex
Definition: timer.c:29
#define MAX_WINDOW_LESS_TIMER_ID
Definition: timer.c:21
#define TMRF_INIT
Definition: timer.h:22
#define TMRF_TIFROMWND
Definition: timer.h:25
ENGAPI VOID APIENTRY EngSetLastError(_In_ ULONG iError)
Definition: error.c:22
#define ERROR_NO_SYSTEM_RESOURCES
Definition: winerror.h:931
#define USER_TIMER_MAXIMUM
Definition: winuser.h:908
#define USER_TIMER_MINIMUM
Definition: winuser.h:909

Referenced by co_IntSetCaretPos(), co_UserShowCaret(), IntFlashWindowEx(), IntTrackMouseEvent(), IntTrackMouseMove(), NtUserCreateCaret(), NtUserSetSystemTimer(), NtUserSetTimer(), StartTheTimers(), and SystemTimerSet().

◆ NtUserKillTimer()

BOOL APIENTRY NtUserKillTimer ( HWND  hWnd,
UINT_PTR  uIDEvent 
)

Definition at line 661 of file timer.c.

666{
667 PWND Window = NULL;
668 BOOL ret;
669
670 TRACE("Enter NtUserKillTimer\n");
673
674 ret = IntKillTimer(Window, uIDEvent, FALSE);
675
676 UserLeave();
677
678 TRACE("Leave NtUserKillTimer, ret=%i\n", ret);
679 return ret;
680}
HWND hWnd
Definition: settings.c:17
VOID FASTCALL UserLeave(VOID)
Definition: ntuser.c:258
VOID FASTCALL UserEnterExclusive(VOID)
Definition: ntuser.c:249
Definition: ntuser.h:694
PWND FASTCALL UserGetWindowObject(HWND hWnd)
Definition: window.c:124
int ret
BOOL FASTCALL IntKillTimer(PWND Window, UINT_PTR IDEvent, BOOL SystemTimer)
Definition: timer.c:579

Referenced by KillTimer().

◆ NtUserSetSystemTimer()

UINT_PTR APIENTRY NtUserSetSystemTimer ( HWND  hWnd,
UINT_PTR  nIDEvent,
UINT  uElapse,
TIMERPROC  lpTimerFunc 
)

Definition at line 685 of file timer.c.

691{
693
695 TRACE("Enter NtUserSetSystemTimer\n");
696
697 ret = IntSetTimer(UserGetWindowObject(hWnd), nIDEvent, uElapse, NULL, TMRF_SYSTEM);
698
699 UserLeave();
700
701 TRACE("Leave NtUserSetSystemTimer, ret=%u\n", ret);
702 return ret;
703}
UINT_PTR FASTCALL IntSetTimer(PWND Window, UINT_PTR IDEvent, UINT Elapse, TIMERPROC TimerFunc, INT Type)
Definition: timer.c:182

Referenced by SetSystemTimer().

◆ NtUserSetTimer()

UINT_PTR APIENTRY NtUserSetTimer ( HWND  hWnd,
UINT_PTR  nIDEvent,
UINT  uElapse,
TIMERPROC  lpTimerFunc 
)

Definition at line 635 of file timer.c.

642{
643 PWND Window = NULL;
645
646 TRACE("Enter NtUserSetTimer\n");
649
650 ret = IntSetTimer(Window, nIDEvent, uElapse, lpTimerFunc, TMRF_TIFROMWND);
651
652 UserLeave();
653 TRACE("Leave NtUserSetTimer, ret=%u\n", ret);
654
655 return ret;
656}

Referenced by SetTimer().

◆ NtUserValidateTimerCallback()

BOOL APIENTRY NtUserValidateTimerCallback ( LPARAM  lParam)

Definition at line 707 of file timer.c.

709{
710 BOOL Ret = FALSE;
711
713
715
716 UserLeave();
717 return Ret;
718}
LPARAM lParam
Definition: combotst.c:139
VOID FASTCALL UserEnterShared(VOID)
Definition: ntuser.c:242
BOOL FASTCALL ValidateTimerCallback(PTHREADINFO pti, LPARAM lParam)
Definition: timer.c:155

Referenced by DispatchMessageA(), and DispatchMessageW().

◆ PostTimerMessages()

BOOL FASTCALL PostTimerMessages ( PWND  Window)

Definition at line 401 of file timer.c.

402{
403 PLIST_ENTRY pLE;
404 MSG Msg;
405 PTHREADINFO pti;
406 BOOL Hit = FALSE;
407 PTIMER pTmr;
408
410
412 pLE = TimersListHead.Flink;
413 while(pLE != &TimersListHead)
414 {
415 pTmr = CONTAINING_RECORD(pLE, TIMER, ptmrList);
416 if ( (pTmr->flags & TMRF_READY) &&
417 (pTmr->pti == pti) &&
418 ((pTmr->pWnd == Window) || (Window == NULL)) )
419 {
420 Msg.hwnd = (pTmr->pWnd ? UserHMGetHandle(pTmr->pWnd) : NULL);
421 Msg.message = (pTmr->flags & TMRF_SYSTEM) ? WM_SYSTIMER : WM_TIMER;
422 Msg.wParam = (WPARAM) pTmr->nID;
423 Msg.lParam = (LPARAM) pTmr->pfn;
424 Msg.time = EngGetTickCount32();
425 // Fix all wine win:test_GetMessagePos WM_TIMER tests. See CORE-10867.
426 Msg.pt = gpsi->ptCursor;
427
429 pTmr->flags &= ~TMRF_READY;
431 Hit = TRUE;
432 // Now move this entry to the end of the list so it will not be
433 // called again in the next msg loop.
434 if (pLE != &TimersListHead)
435 {
438 }
439 break;
440 }
441
442 pLE = pLE->Flink;
443 }
444
445 TimerLeave();
446
447 return Hit;
448}
struct @1644 Msg[]
#define WM_SYSTIMER
Definition: comctl32.h:125
PSERVERINFO gpsi
Definition: imm.c:18
#define EngGetTickCount32()
Definition: eng.h:43
#define RemoveEntryList(Entry)
Definition: env_spec_w32.h:986
#define UserHMGetHandle(obj)
Definition: ntuser.h:230
VOID FASTCALL ClearMsgBitsMask(PTHREADINFO pti, UINT MessageBits)
Definition: msgqueue.c:445
VOID FASTCALL MsqPostMessage(PTHREADINFO pti, MSG *Msg, BOOLEAN HardwareMessage, DWORD MessageBits, DWORD dwQEvent, LONG_PTR ExtraInfo)
Definition: msgqueue.c:1337
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1829
#define TMRF_READY
Definition: timer.h:19
UINT_PTR WPARAM
Definition: windef.h:207
#define QS_TIMER
Definition: winuser.h:881
#define QS_ALLPOSTMESSAGE
Definition: winuser.h:885
#define WM_TIMER
Definition: winuser.h:1745
#define QS_POSTMESSAGE
Definition: winuser.h:880

Referenced by co_IntPeekMessage().

◆ ProcessTimers()

VOID FASTCALL ProcessTimers ( VOID  )

Definition at line 452 of file timer.c.

453{
455 LONG Time;
456 PLIST_ENTRY pLE;
457 PTIMER pTmr;
458 LONG TimerCount = 0;
459
461 pLE = TimersListHead.Flink;
463
464 DueTime.QuadPart = (LONGLONG)(-97656); // 1024hz .9765625 ms set to 10.0 ms
465
466 while(pLE != &TimersListHead)
467 {
468 pTmr = CONTAINING_RECORD(pLE, TIMER, ptmrList);
469 TimerCount++;
470 if (pTmr->flags & TMRF_WAITING)
471 {
472 pLE = pTmr->ptmrList.Flink;
473 pTmr = CONTAINING_RECORD(pLE, TIMER, ptmrList);
474 continue;
475 }
476
477 if (pTmr->flags & TMRF_INIT)
478 {
479 pTmr->flags &= ~TMRF_INIT; // Skip this run.
480 }
481 else
482 {
483 if (pTmr->cmsCountdown < 0)
484 {
485 ASSERT(pTmr->pti);
486 if ((!(pTmr->flags & TMRF_READY)) && (!(pTmr->pti->TIF_flags & TIF_INCLEANUP)))
487 {
488 if (pTmr->flags & TMRF_ONESHOT)
489 pTmr->flags |= TMRF_WAITING;
490
491 if (pTmr->flags & TMRF_RIT)
492 {
493 // Hard coded call here, inside raw input thread.
494 pTmr->pfn(NULL, WM_SYSTIMER, pTmr->nID, (LPARAM)pTmr);
495 }
496 else
497 {
498 pTmr->flags |= TMRF_READY; // Set timer ready to be ran.
499 // Set thread message queue for this timer.
500 if (pTmr->pti)
501 { // Wakeup thread
502 pTmr->pti->cTimersReady++;
503 ASSERT(pTmr->pti->pEventQueueServer != NULL);
504 MsqWakeQueue(pTmr->pti, QS_TIMER, TRUE);
505 }
506 }
507 }
508 pTmr->cmsCountdown = pTmr->cmsRate;
509 }
510 else
511 pTmr->cmsCountdown -= Time - TimeLast;
512 }
513
514 pLE = pLE->Flink;
515 }
516
517 // Restart the timer thread!
520
521 TimeLast = Time;
522
523 TimerLeave();
524 TRACE("TimerCount = %d\n", TimerCount);
525}
#define TIF_INCLEANUP
Definition: ntuser.h:263
static PLARGE_INTEGER Time
Definition: time.c:105
VOID FASTCALL MsqWakeQueue(PTHREADINFO pti, DWORD MessageBits, BOOL KeyEvent)
Definition: msgqueue.c:412
long LONG
Definition: pedump.c:60
PKEVENT pEventQueueServer
Definition: win32.h:125
UINT cTimersReady
Definition: win32.h:110
FLONG TIF_flags
Definition: win32.h:95
static LONG TimeLast
Definition: timer.c:17
#define TMRF_WAITING
Definition: timer.h:24
#define TMRF_ONESHOT
Definition: timer.h:23

Referenced by RawInputThreadMain().

◆ RemoveTimer()

static BOOL FASTCALL RemoveTimer ( PTIMER  pTmr)
static

Definition at line 74 of file timer.c.

75{
76 BOOL Ret = FALSE;
77 if (pTmr)
78 {
79 /* Set the flag, it will be removed when ready */
81 if ((pTmr->pWnd == NULL) && (!(pTmr->flags & TMRF_SYSTEM))) // System timers are reusable.
82 {
83 ULONG ulBitmapIndex;
84
86 ulBitmapIndex = (ULONG)(MAX_WINDOW_LESS_TIMER_ID - pTmr->nID);
88 RtlClearBit(&WindowLessTimersBitMap, ulBitmapIndex);
90 }
93 }
94 if (!Ret) ERR("Warning: Unable to delete timer\n");
95
96 return Ret;
97}
#define RtlClearBit
Definition: dbgbitmap.h:330
BOOL FASTCALL UserDereferenceObject(PVOID Object)
Definition: object.c:644
BOOL FASTCALL UserDeleteObject(HANDLE h, HANDLE_TYPE type)
Definition: object.c:717

Referenced by DestroyTimersForThread(), DestroyTimersForWindow(), and IntKillTimer().

◆ StartTheTimers()

VOID FASTCALL StartTheTimers ( VOID  )

Definition at line 374 of file timer.c.

375{
376 // Need to start gdi syncro timers then start timer with Hang App proc
377 // that calles Idle process so the screen savers will know to run......
379// Test Timers
380// IntSetTimer(NULL, 0, 1000, SystemTimerProc, TMRF_RIT);
381}
VOID CALLBACK HungAppSysTimerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)
Definition: msgqueue.c:2193

Referenced by RawInputThreadMain().

◆ SystemTimerProc()

VOID CALLBACK SystemTimerProc ( HWND  hwnd,
UINT  uMsg,
UINT_PTR  idEvent,
DWORD  dwTime 
)

Definition at line 286 of file timer.c.

290{
291 PDESKTOP pDesk;
292 PWND pWnd = NULL;
293
294 if (hwnd)
295 {
297 if (!pWnd)
298 {
299 ERR("System Timer Proc has invalid window handle! %p Id: %u\n", hwnd, idEvent);
300 return;
301 }
302 }
303 else
304 {
305 TRACE( "Windowless Timer Running!\n" );
306 return;
307 }
308
309 switch (idEvent)
310 {
311/*
312 Used in NtUserTrackMouseEvent.
313 */
315 {
316 POINT Point;
317 UINT Msg;
319
320 pDesk = pWnd->head.rpdesk;
321 if ( pDesk->dwDTFlags & DF_TME_HOVER &&
322 pWnd == pDesk->spwndTrack )
323 {
324 Point = gpsi->ptCursor;
325 if ( RECTL_bPointInRect(&pDesk->rcMouseHover, Point.x, Point.y) )
326 {
327 if (pDesk->htEx == HTCLIENT) // In a client area.
328 {
329 wParam = MsqGetDownKeyState(pWnd->head.pti->MessageQueue);
331
332 if (pWnd->ExStyle & WS_EX_LAYOUTRTL)
333 {
334 Point.x = pWnd->rcClient.right - Point.x - 1;
335 }
336 else
337 Point.x -= pWnd->rcClient.left;
338 Point.y -= pWnd->rcClient.top;
339 }
340 else
341 {
342 wParam = pDesk->htEx; // Need to support all HTXYZ hits.
344 }
345 TRACE("Generating WM_NCMOUSEHOVER\n");
347 pDesk->dwDTFlags &= ~DF_TME_HOVER;
348 break; // Kill this timer.
349 }
350 }
351 }
352 return; // Not this window so just return.
353
355 {
356 FLASHWINFO fwi =
357 {sizeof(FLASHWINFO),
358 UserHMGetHandle(pWnd),
359 FLASHW_SYSTIMER,0,0};
360
361 IntFlashWindowEx(pWnd, &fwi);
362 }
363 return;
364
365 default:
366 ERR("System Timer Proc invalid id %u!\n", idEvent);
367 break;
368 }
369 IntKillTimer(pWnd, idEvent, TRUE);
370}
WPARAM wParam
Definition: combotst.c:138
WPARAM FASTCALL MsqGetDownKeyState(PUSER_MESSAGE_QUEUE MessageQueue)
Definition: msgqueue.c:338
unsigned int UINT
Definition: ndis.h:50
#define FLASHW_SYSTIMER
Definition: painting.h:4
#define WM_MOUSEHOVER
Definition: commctrl.h:4979
PWND spwndTrack
Definition: desktop.h:31
DWORD htEx
Definition: desktop.h:32
RECT rcMouseHover
Definition: desktop.h:33
DWORD dwDTFlags
Definition: desktop.h:12
struct _DESKTOP * rpdesk
Definition: ntuser.h:194
DWORD ExStyle
Definition: ntuser.h:704
THRDESKHEAD head
Definition: ntuser.h:695
RECT rcClient
Definition: ntuser.h:717
LONG right
Definition: windef.h:308
LONG top
Definition: windef.h:307
LONG left
Definition: windef.h:306
BOOL FASTCALL IntFlashWindowEx(PWND pWnd, PFLASHWINFO pfwi)
Definition: painting.c:1311
FORCEINLINE BOOL RECTL_bPointInRect(_In_ const RECTL *prcl, _In_ INT x, _In_ INT y)
Definition: rect.h:52
#define DF_TME_HOVER
Definition: desktop.h:47
BOOL FASTCALL UserPostMessage(HWND Wnd, UINT Msg, WPARAM wParam, LPARAM lParam)
Definition: message.c:1395
#define ID_EVENT_SYSTIMER_MOUSEHOVER
Definition: timer.h:27
#define ID_EVENT_SYSTIMER_FLASHWIN
Definition: timer.h:28
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
#define WS_EX_LAYOUTRTL
Definition: winuser.h:390
#define MAKELPARAM(l, h)
Definition: winuser.h:4011
#define HTCLIENT
Definition: winuser.h:2478
#define WM_NCMOUSEHOVER
Definition: winuser.h:1844

Referenced by IntFlashWindowEx(), IntTrackMouseEvent(), and IntTrackMouseMove().

◆ SystemTimerSet()

UINT_PTR FASTCALL SystemTimerSet ( PWND  Window,
UINT_PTR  nIDEvent,
UINT  uElapse,
TIMERPROC  lpTimerFunc 
)

Definition at line 385 of file timer.c.

389{
390 if (Window && Window->head.pti->pEThread->ThreadsProcess != PsGetCurrentProcess())
391 {
393 TRACE("SysemTimerSet: Access Denied!\n");
394 return 0;
395 }
396 return IntSetTimer( Window, nIDEvent, uElapse, lpTimerFunc, TMRF_SYSTEM);
397}
#define ERROR_ACCESS_DENIED
Definition: compat.h:97
#define PsGetCurrentProcess
Definition: psfuncs.h:17

◆ ValidateTimerCallback()

BOOL FASTCALL ValidateTimerCallback ( PTHREADINFO  pti,
LPARAM  lParam 
)

Definition at line 155 of file timer.c.

157{
158 PLIST_ENTRY pLE;
159 BOOL Ret = FALSE;
160 PTIMER pTmr;
161
163 pLE = TimersListHead.Flink;
164 while (pLE != &TimersListHead)
165 {
166 pTmr = CONTAINING_RECORD(pLE, TIMER, ptmrList);
167 if ( (lParam == (LPARAM)pTmr->pfn) &&
168 !(pTmr->flags & (TMRF_SYSTEM|TMRF_RIT)) &&
169 (pTmr->pti->ppi == pti->ppi) )
170 {
171 Ret = TRUE;
172 break;
173 }
174 pLE = pLE->Flink;
175 }
176 TimerLeave();
177
178 return Ret;
179}
PPROCESSINFO ppi
Definition: win32.h:88

Referenced by IntDispatchMessage(), and NtUserValidateTimerCallback().

Variable Documentation

◆ HintIndex

ULONG HintIndex = HINTINDEX_BEGIN_VALUE
static

Definition at line 29 of file timer.c.

Referenced by IntSetTimer().

◆ Mutex

Definition at line 26 of file timer.c.

◆ TimeLast

LONG TimeLast = 0
static

Definition at line 17 of file timer.c.

Referenced by ProcessTimers().

◆ TimerLock

ERESOURCE TimerLock

Definition at line 31 of file timer.c.

Referenced by InitTimerImpl().

◆ TimersListHead

◆ WindowLessTimersBitMap

RTL_BITMAP WindowLessTimersBitMap
static

Definition at line 27 of file timer.c.

Referenced by InitTimerImpl(), IntSetTimer(), and RemoveTimer().

◆ WindowLessTimersBitMapBuffer

PVOID WindowLessTimersBitMapBuffer
static

Definition at line 28 of file timer.c.

Referenced by InitTimerImpl().