From 3a80656b879964c08ed5d3cfc58b9160b5ca492c Mon Sep 17 00:00:00 2001 From: "locka%iol.ie" Date: Tue, 23 Jan 2001 14:15:57 +0000 Subject: [PATCH] Added a timer to the message loop to prevent 100% cpu usage when the message queue was empty. b=58701 git-svn-id: svn://10.0.0.236/trunk@85359 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/embedding/tests/winEmbed/winEmbed.cpp | 47 ++++++++++++------- 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/mozilla/embedding/tests/winEmbed/winEmbed.cpp b/mozilla/embedding/tests/winEmbed/winEmbed.cpp index 29c5332956f..af9e122162b 100644 --- a/mozilla/embedding/tests/winEmbed/winEmbed.cpp +++ b/mozilla/embedding/tests/winEmbed/winEmbed.cpp @@ -84,28 +84,39 @@ int main(int argc, char *argv[]) // Open the initial browser window OpenWebPage(szFirstURL); + MSG msg; + // Main message loop: - MSG msg; + HANDLE hFakeEvent = CreateEvent(NULL, TRUE, FALSE, NULL); while (1) { - if (!::PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) - { - NS_DoIdleEmbeddingStuff(); - continue; - } - if (!::GetMessage(&msg, NULL, 0, 0)) - { - break; - } - PRBool wasHandled = PR_FALSE; - NS_HandleEmbeddingEvent(msg, wasHandled); - if (wasHandled) - { - continue; - } - TranslateMessage(&msg); - DispatchMessage(&msg); + // Process pending messages + while (::PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) + { + if (!::GetMessage(&msg, NULL, 0, 0)) + { + // WM_QUIT + goto end_msg_loop; + } + + PRBool wasHandled = PR_FALSE; + NS_HandleEmbeddingEvent(msg, wasHandled); + if (wasHandled) + { + continue; + } + TranslateMessage(&msg); + DispatchMessage(&msg); + } + + // Do idle stuff + NS_DoIdleEmbeddingStuff(); + + MsgWaitForMultipleObjects(1, &hFakeEvent, FALSE, 100, QS_ALLEVENTS); } + CloseHandle(hFakeEvent); + +end_msg_loop: // Close down Embedding APIs NS_TermEmbedding();