- Implement DestroyTimersForWindow and call it instead of MsqRemoveTimersWindow when destroying a window.
- Fire NewMessages event when cleaning up thread so that threads dont wait for new messages that will never be received. Fixes a problem where some application that use timers dont completly exit.
- IntSetTimer: Dont try to raise a timer from the dead. Once the TMRF_DELETEPENDING flag is set, let it be destroyed.
- co_MsqWaitForNewMessages: Call the wait without a timeout value as now when the timer expires the NewMessages event will be set to exit the wait.
- Message Queue specific timer code and old time queuing code is now dead. It will be removed later when we are happy with new timer implementation.

svn path=/trunk/; revision=47358
This commit is contained in:
Michael Martin 2010-05-26 02:04:09 +00:00
parent 7f82a194fa
commit bbe7ec53c5
6 changed files with 39 additions and 24 deletions

View file

@ -29,6 +29,7 @@ extern PKTIMER MasterTimer;
NTSTATUS FASTCALL InitTimerImpl(VOID); NTSTATUS FASTCALL InitTimerImpl(VOID);
BOOL FASTCALL DestroyTimersForThread(PTHREADINFO pti); BOOL FASTCALL DestroyTimersForThread(PTHREADINFO pti);
BOOL FASTCALL DestroyTimersForWindow(PTHREADINFO pti, PWINDOW_OBJECT Window);
BOOL FASTCALL IntKillTimer(PWINDOW_OBJECT Window, UINT_PTR IDEvent, BOOL SystemTimer); BOOL FASTCALL IntKillTimer(PWINDOW_OBJECT Window, UINT_PTR IDEvent, BOOL SystemTimer);
UINT_PTR FASTCALL IntSetTimer(PWINDOW_OBJECT Window, UINT_PTR IDEvent, UINT Elapse, TIMERPROC TimerFunc, INT Type); UINT_PTR FASTCALL IntSetTimer(PWINDOW_OBJECT Window, UINT_PTR IDEvent, UINT Elapse, TIMERPROC TimerFunc, INT Type);
PTIMER FASTCALL FindSystemTimer(PMSG); PTIMER FASTCALL FindSystemTimer(PMSG);

View file

@ -292,6 +292,7 @@ Win32kThreadCallback(struct _ETHREAD *Thread,
HOOK_DestroyThreadHooks(Thread); HOOK_DestroyThreadHooks(Thread);
/* Cleanup timers */ /* Cleanup timers */
DestroyTimersForThread(Win32Thread); DestroyTimersForThread(Win32Thread);
KeSetEvent(Win32Thread->MessageQueue->NewMessages, IO_NO_INCREMENT, FALSE);
UnregisterThreadHotKeys(Thread); UnregisterThreadHotKeys(Thread);
/* what if this co_ func crash in umode? what will clean us up then? */ /* what if this co_ func crash in umode? what will clean us up then? */
co_DestroyThreadWindows(Thread); co_DestroyThreadWindows(Thread);

View file

@ -67,7 +67,7 @@ IntClientShutdown(
co_IntSendMessage(WndChild->hSelf, WM_ENDSESSION, KillTimers, lParams); co_IntSendMessage(WndChild->hSelf, WM_ENDSESSION, KillTimers, lParams);
if (KillTimers) if (KillTimers)
{ {
MsqRemoveTimersWindow(WndChild->pti->MessageQueue, WndChild->hSelf); DestroyTimersForWindow(WndChild->pti, WndChild);
} }
lResult = MCSR_SHUTDOWNFINISHED; lResult = MCSR_SHUTDOWNFINISHED;
} }
@ -90,7 +90,7 @@ IntClientShutdown(
co_IntSendMessage(pWindow->hSelf, WM_ENDSESSION, KillTimers, lParams); co_IntSendMessage(pWindow->hSelf, WM_ENDSESSION, KillTimers, lParams);
if (KillTimers) if (KillTimers)
{ {
MsqRemoveTimersWindow(pWindow->pti->MessageQueue, pWindow->hSelf); DestroyTimersForWindow(pWindow->pti, pWindow);
} }
lResult = MCSR_SHUTDOWNFINISHED; lResult = MCSR_SHUTDOWNFINISHED;
} }

View file

@ -1366,19 +1366,8 @@ co_MsqWaitForNewMessages(PUSER_MESSAGE_QUEUE MessageQueue, PWINDOW_OBJECT WndFil
UINT MsgFilterMin, UINT MsgFilterMax) UINT MsgFilterMin, UINT MsgFilterMax)
{ {
PVOID WaitObjects[2] = {MessageQueue->NewMessages, &HardwareMessageEvent}; PVOID WaitObjects[2] = {MessageQueue->NewMessages, &HardwareMessageEvent};
LARGE_INTEGER TimerExpiry;
PLARGE_INTEGER Timeout;
NTSTATUS ret; NTSTATUS ret;
if (MsqGetFirstTimerExpiry(MessageQueue, WndFilter, MsgFilterMin, MsgFilterMax, &TimerExpiry))
{
Timeout = &TimerExpiry;
}
else
{
Timeout = NULL;
}
IdlePing(); // Going to wait so send Idle ping. IdlePing(); // Going to wait so send Idle ping.
UserLeaveCo(); UserLeaveCo();
@ -1389,11 +1378,9 @@ co_MsqWaitForNewMessages(PUSER_MESSAGE_QUEUE MessageQueue, PWINDOW_OBJECT WndFil
Executive, Executive,
UserMode, UserMode,
FALSE, FALSE,
Timeout, NULL,
NULL); NULL);
UserEnterCo(); UserEnterCo();
return ret; return ret;
} }

View file

@ -216,7 +216,7 @@ IntSetTimer( PWINDOW_OBJECT Window,
} }
pTmr = FindTimer(Window, IDEvent, Type, FALSE); pTmr = FindTimer(Window, IDEvent, Type, FALSE);
if (!pTmr) if ((!pTmr) || (pTmr->flags & TMRF_DELETEPENDING))
{ {
pTmr = CreateTimer(); pTmr = CreateTimer();
if (!pTmr) return 0; if (!pTmr) return 0;
@ -240,10 +240,6 @@ IntSetTimer( PWINDOW_OBJECT Window,
pTmr->cmsCountdown = Elapse; pTmr->cmsCountdown = Elapse;
pTmr->cmsRate = Elapse; pTmr->cmsRate = Elapse;
if (pTmr->flags & TMRF_DELETEPENDING)
{
pTmr->flags &= ~TMRF_DELETEPENDING;
}
ASSERT(MasterTimer != NULL); ASSERT(MasterTimer != NULL);
// Start the timer thread! // Start the timer thread!
@ -342,6 +338,7 @@ ProcessTimers(VOID)
LONG Time; LONG Time;
PLIST_ENTRY pLE; PLIST_ENTRY pLE;
PTIMER pTmr = FirstpTmr; PTIMER pTmr = FirstpTmr;
LONG TimerCount = 0;
if (!pTmr) return; if (!pTmr) return;
@ -354,6 +351,7 @@ ProcessTimers(VOID)
do do
{ {
TimerCount++;
if (pTmr->flags & TMRF_WAITING) if (pTmr->flags & TMRF_WAITING)
{ {
pLE = pTmr->ptmrList.Flink; pLE = pTmr->ptmrList.Flink;
@ -426,6 +424,7 @@ ProcessTimers(VOID)
TimeLast = Time; TimeLast = Time;
UserLeave(); UserLeave();
DPRINT("TimerCount = %d\n", TimerCount);
} }
// //
@ -524,6 +523,35 @@ if (Ret == 0) ASSERT(FALSE);
return Ret; return Ret;
} }
BOOL FASTCALL
DestroyTimersForWindow(PTHREADINFO pti, PWINDOW_OBJECT Window)
{
PLIST_ENTRY pLE;
PTIMER pTmr = FirstpTmr;
BOOL TimersRemoved = FALSE;
if ((FirstpTmr == NULL) || (Window == NULL))
return FALSE;
KeEnterCriticalRegion();
do
{
if ((pTmr) && (pTmr->pti == pti) && (pTmr->pWnd == Window))
{
pTmr->flags &= ~TMRF_READY;
pTmr->flags |= TMRF_DELETEPENDING;
TimersRemoved = TRUE;
}
pLE = pTmr->ptmrList.Flink;
pTmr = CONTAINING_RECORD(pLE, TIMER, ptmrList);
} while (pTmr != FirstpTmr);
KeLeaveCriticalRegion();
return TimersRemoved;
}
BOOL FASTCALL BOOL FASTCALL
DestroyTimersForThread(PTHREADINFO pti) DestroyTimersForThread(PTHREADINFO pti)
{ {
@ -553,7 +581,6 @@ DestroyTimersForThread(PTHREADINFO pti)
return TimersRemoved; return TimersRemoved;
} }
BOOL FASTCALL BOOL FASTCALL
IntKillTimer(PWINDOW_OBJECT Window, UINT_PTR IDEvent, BOOL SystemTimer) IntKillTimer(PWINDOW_OBJECT Window, UINT_PTR IDEvent, BOOL SystemTimer)
{ {
@ -568,7 +595,6 @@ IntKillTimer(PWINDOW_OBJECT Window, UINT_PTR IDEvent, BOOL SystemTimer)
return pTmr ? TRUE : FALSE; return pTmr ? TRUE : FALSE;
} }
// //
// //
// Old Kill Timer // Old Kill Timer

View file

@ -424,7 +424,7 @@ static LRESULT co_UserFreeWindow(PWINDOW_OBJECT Window,
if(BelongsToThreadData) if(BelongsToThreadData)
co_IntSendMessage(Window->hSelf, WM_NCDESTROY, 0, 0); co_IntSendMessage(Window->hSelf, WM_NCDESTROY, 0, 0);
} }
MsqRemoveTimersWindow(ThreadData->MessageQueue, Window->hSelf); DestroyTimersForWindow(ThreadData, Window);
HOOK_DestroyThreadHooks(ThreadData->pEThread); // This is needed here too! HOOK_DestroyThreadHooks(ThreadData->pEThread); // This is needed here too!
/* flush the message queue */ /* flush the message queue */