Author: jimtabor
Date: Sat Jan 29 09:03:25 2011
New Revision: 50547
URL:
http://svn.reactos.org/svn/reactos?rev=50547&view=rev
Log:
[Win32k]
- Patch by rafalh <rafalh1992 at o2 dor pl>, see bug 5835. Fix timers
implementation.
Modified:
trunk/reactos/subsystems/win32/win32k/ntuser/timer.c
Modified: trunk/reactos/subsystems/win32/win32k/ntuser/timer.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/win32k/nt…
==============================================================================
--- trunk/reactos/subsystems/win32/win32k/ntuser/timer.c [iso-8859-1] (original)
+++ trunk/reactos/subsystems/win32/win32k/ntuser/timer.c [iso-8859-1] Sat Jan 29 09:03:25
2011
@@ -19,7 +19,7 @@
/* GLOBALS *******************************************************************/
-static PTIMER FirstpTmr = NULL;
+static LIST_ENTRY TimersListHead;
static LONG TimeLast = 0;
#define MAX_ELAPSE_TIME 0x7FFFFFFF
@@ -62,26 +62,13 @@
HANDLE Handle;
PTIMER Ret = NULL;
- if (!FirstpTmr)
- {
- ExInitializeResourceLite(&TimerLock);
- FirstpTmr = UserCreateObject(gHandleTable, NULL, &Handle, otTimer,
sizeof(TIMER));
- if (FirstpTmr)
- {
- FirstpTmr->head.h = Handle;
- InitializeListHead(&FirstpTmr->ptmrList);
- }
- Ret = FirstpTmr;
- }
- else
- {
- Ret = UserCreateObject(gHandleTable, NULL, &Handle, otTimer, sizeof(TIMER));
- if (Ret)
- {
- Ret->head.h = Handle;
- InsertTailList(&FirstpTmr->ptmrList, &Ret->ptmrList);
- }
- }
+ Ret = UserCreateObject(gHandleTable, NULL, &Handle, otTimer, sizeof(TIMER));
+ if (Ret)
+ {
+ Ret->head.h = Handle;
+ InsertTailList(&TimersListHead, &Ret->ptmrList);
+ }
+
return Ret;
}
@@ -118,12 +105,13 @@
UINT_PTR nID,
UINT flags)
{
- PLIST_ENTRY pLE;
- PTIMER pTmr = FirstpTmr, RetTmr = NULL;
+ PLIST_ENTRY pLE = TimersListHead.Flink;
+ PTIMER pTmr, RetTmr = NULL;
+
TimerEnterExclusive();
- do
- {
- if (!pTmr) break;
+ while (pLE != &TimersListHead)
+ {
+ pTmr = CONTAINING_RECORD(pLE, TIMER, ptmrList);
if ( pTmr->nID == nID &&
pTmr->pWnd == Window &&
@@ -133,32 +121,31 @@
break;
}
- pLE = pTmr->ptmrList.Flink;
+ pLE = pLE->Flink;
+ }
+ TimerLeave();
+
+ return RetTmr;
+}
+
+PTIMER
+FASTCALL
+FindSystemTimer(PMSG pMsg)
+{
+ PLIST_ENTRY pLE = TimersListHead.Flink;
+ PTIMER pTmr = NULL;
+
+ TimerEnterExclusive();
+ while (pLE != &TimersListHead)
+ {
pTmr = CONTAINING_RECORD(pLE, TIMER, ptmrList);
- } while (pTmr != FirstpTmr);
- TimerLeave();
-
- return RetTmr;
-}
-
-PTIMER
-FASTCALL
-FindSystemTimer(PMSG pMsg)
-{
- PLIST_ENTRY pLE;
- PTIMER pTmr = FirstpTmr;
- TimerEnterExclusive();
- do
- {
- if (!pTmr) break;
if ( pMsg->lParam == (LPARAM)pTmr->pfn &&
(pTmr->flags & TMRF_SYSTEM) )
break;
- pLE = pTmr->ptmrList.Flink;
- pTmr = CONTAINING_RECORD(pLE, TIMER, ptmrList);
- } while (pTmr != FirstpTmr);
+ pLE = pLE->Flink;
+ }
TimerLeave();
return pTmr;
@@ -169,15 +156,14 @@
ValidateTimerCallback(PTHREADINFO pti,
LPARAM lParam)
{
- PLIST_ENTRY pLE;
+ PLIST_ENTRY pLE = TimersListHead.Flink;
BOOL Ret = FALSE;
- PTIMER pTmr = FirstpTmr;
-
- if (!pTmr) return FALSE;
+ PTIMER pTmr;
TimerEnterExclusive();
- do
- {
+ while (pLE != &TimersListHead)
+ {
+ pTmr = CONTAINING_RECORD(pLE, TIMER, ptmrList);
if ( (lParam == (LPARAM)pTmr->pfn) &&
!(pTmr->flags & (TMRF_SYSTEM|TMRF_RIT)) &&
(pTmr->pti->ppi == pti->ppi) )
@@ -185,9 +171,8 @@
Ret = TRUE;
break;
}
- pLE = pTmr->ptmrList.Flink;
- pTmr = CONTAINING_RECORD(pLE, TIMER, ptmrList);
- } while (pTmr != FirstpTmr);
+ pLE = pLE->Flink;
+ }
TimerLeave();
return Ret;
@@ -286,7 +271,7 @@
ASSERT(MasterTimer != NULL);
// Start the timer thread!
- if (pTmr == FirstpTmr)
+ if (TimersListHead.Flink == TimersListHead.Blink) // There is only one timer
KeSetTimer(MasterTimer, DueTime, NULL);
return Ret;
@@ -334,22 +319,21 @@
FASTCALL
PostTimerMessages(PWND Window)
{
- PLIST_ENTRY pLE;
+ PLIST_ENTRY pLE = TimersListHead.Flink;
PUSER_MESSAGE_QUEUE ThreadQueue;
MSG Msg;
PTHREADINFO pti;
BOOL Hit = FALSE;
- PTIMER pTmr = FirstpTmr;
-
- if (!pTmr) return FALSE;
+ PTIMER pTmr;
pti = PsGetCurrentThreadWin32Thread();
ThreadQueue = pti->MessageQueue;
TimerEnterExclusive();
- do
- {
+ while(pLE != &TimersListHead)
+ {
+ pTmr = CONTAINING_RECORD(pLE, TIMER, ptmrList);
if ( (pTmr->flags & TMRF_READY) &&
(pTmr->pti == pti) &&
((pTmr->pWnd == Window) || (Window == NULL)) )
@@ -366,9 +350,8 @@
break;
}
- pLE = pTmr->ptmrList.Flink;
- pTmr = CONTAINING_RECORD(pLE, TIMER, ptmrList);
- } while (pTmr != FirstpTmr);
+ pLE = pLE->Flink;
+ }
TimerLeave();
@@ -381,11 +364,9 @@
{
LARGE_INTEGER TickCount, DueTime;
LONG Time;
- PLIST_ENTRY pLE;
- PTIMER pTmr = FirstpTmr;
+ PLIST_ENTRY pLE = TimersListHead.Flink;
+ PTIMER pTmr;
LONG TimerCount = 0;
-
- if (!pTmr) return;
TimerEnterExclusive();
@@ -394,8 +375,9 @@
DueTime.QuadPart = (LONGLONG)(-500000);
- do
- {
+ while(pLE != &TimersListHead)
+ {
+ pTmr = CONTAINING_RECORD(pLE, TIMER, ptmrList);
TimerCount++;
if (pTmr->flags & TMRF_WAITING)
{
@@ -440,9 +422,8 @@
pTmr->cmsCountdown -= Time - TimeLast;
}
- pLE = pTmr->ptmrList.Flink;
- pTmr = CONTAINING_RECORD(pLE, TIMER, ptmrList);
- } while (pTmr != FirstpTmr);
+ pLE = pLE->Flink;
+ }
// Restart the timer thread!
ASSERT(MasterTimer != NULL);
@@ -457,24 +438,24 @@
BOOL FASTCALL
DestroyTimersForWindow(PTHREADINFO pti, PWND Window)
{
- PLIST_ENTRY pLE;
- PTIMER pTmr = FirstpTmr;
+ PLIST_ENTRY pLE = TimersListHead.Flink;
+ PTIMER pTmr;
BOOL TimersRemoved = FALSE;
- if ((FirstpTmr == NULL) || (Window == NULL))
+ if ((Window == NULL))
return FALSE;
TimerEnterExclusive();
- do
+ while(pLE != &TimersListHead)
{
+ pTmr = CONTAINING_RECORD(pLE, TIMER, ptmrList);
+ pLE = pLE->Flink; /* get next timer list entry before current timer is removed
*/
if ((pTmr) && (pTmr->pti == pti) && (pTmr->pWnd == Window))
{
TimersRemoved = RemoveTimer(pTmr);
}
- pLE = pTmr->ptmrList.Flink;
- pTmr = CONTAINING_RECORD(pLE, TIMER, ptmrList);
- } while (pTmr != FirstpTmr);
+ }
TimerLeave();
@@ -484,24 +465,21 @@
BOOL FASTCALL
DestroyTimersForThread(PTHREADINFO pti)
{
- PLIST_ENTRY pLE;
- PTIMER pTmr = FirstpTmr;
+ PLIST_ENTRY pLE = TimersListHead.Flink;
+ PTIMER pTmr;
BOOL TimersRemoved = FALSE;
- if (FirstpTmr == NULL)
- return FALSE;
-
TimerEnterExclusive();
- do
+ while(pLE != &TimersListHead)
{
+ pTmr = CONTAINING_RECORD(pLE, TIMER, ptmrList);
+ pLE = pLE->Flink; /* get next timer list entry before current timer is removed
*/
if ((pTmr) && (pTmr->pti == pti))
{
TimersRemoved = RemoveTimer(pTmr);
}
- pLE = pTmr->ptmrList.Flink;
- pTmr = CONTAINING_RECORD(pLE, TIMER, ptmrList);
- } while (pTmr != FirstpTmr);
+ }
TimerLeave();
@@ -549,6 +527,9 @@
/* yes we need this, since ExAllocatePoolWithTag isn't supposed to zero out
allocated memory */
RtlClearAllBits(&WindowLessTimersBitMap);
+
+ ExInitializeResourceLite(&TimerLock);
+ InitializeListHead(&TimersListHead);
return STATUS_SUCCESS;
}