On 9月15日, 上午6时28分, "Dan Kegel" <[EMAIL PROTECTED]> wrote:
> I was getting TCPClientSocket working on Linux
> ( seehttp://codereview.chromium.org/3202for draft )
> and noticed that unless I capped the time
> MessagePumpLibevent::Run slept, various unit tests
> would seem to hang because MessageLoop::Quit()
> doesn't actually tell the message pump to break.
>
> Looking atMessagePumpWin, I don't see any
> obvious cap on the sleep time (unless there are
> too many objects in motion, which shouldn't be
> the case while running the unit tests).
>
> Anyone happen to know how long it usually sleeps?
> I'd check myself, but I won't be near a windows machine
> until tomorrow.
> - Dan
>
> p.s. sent via gmail-on-chromium-on-wine :-)
void MessagePumpWin::WaitForWork() {
// Wait until either an object is signaled or a message is
available. Handle
// (without returning) any APCs (only the IO thread currently has
APCs.)
// We do not support nested message loops when we have watched
objects. This
// is to avoid messy recursion problems.
DCHECK(objects_.empty() || state_->run_depth == 1) <<
"Cannot nest a message loop when there are watched objects!";
int wait_flags = MWMO_ALERTABLE | MWMO_INPUTAVAILABLE;
bool use_polling = false; // Poll if too many objects for one OS
Wait call.
for (;;) {
// Do initialization here, in case APC modifies object list.
size_t total_objs = objects_.size();
int delay;
size_t polling_index = 0; // The first unprocessed object index.
do {
size_t objs_len =
(polling_index < total_objs) ? total_objs - polling_index :
0;
if (objs_len >= MAXIMUM_WAIT_OBJECTS) {
objs_len = MAXIMUM_WAIT_OBJECTS - 1;
use_polling = true;
}
HANDLE* objs = objs_len ? polling_index + &objects_.front() :
NULL;
// Only wait up to the time needed by the timer manager to fire
the next
// set of timers.
delay = GetCurrentDelay();
if (use_polling && delay > kMultipleWaitPollingInterval)
delay = kMultipleWaitPollingInterval;
if (delay < 0) // Negative value means no timers waiting.
delay = INFINITE;
DWORD result;
result =
MsgWaitForMultipleObjectsEx(static_cast<DWORD>(objs_len), objs,
delay, QS_ALLINPUT,
wait_flags);
if (WAIT_IO_COMPLETION == result) {
// We'll loop here when we service an APC. At it currently
stands,
// *ONLY* the IO thread uses *any* APCs, so this should have
no impact
// on the UI thread.
break; // Break to outer loop, and waitforwork() again.
}
// Use unsigned type to simplify range detection;
size_t signaled_index = result - WAIT_OBJECT_0;
if (signaled_index < objs_len) {
SignalWatcher(polling_index + signaled_index);
return; // We serviced a signaled object.
}
if (objs_len == signaled_index)
return; // A WM_* message is available.
DCHECK_NE(WAIT_FAILED, result) << GetLastError();
DCHECK(!objs || result == WAIT_TIMEOUT);
if (!use_polling)
return;
polling_index += objs_len;
} while (polling_index < total_objs);
// For compatibility, we didn't return sooner. This made us do
*some* wait
// call(s) before returning. This will probably change in next
rev.
if (!delay || !GetCurrentDelay())
return; // No work done, but timer is ready to fire.
}
}
if the loop have no message and event
theloop will sleep in MsgWaitForMultipleObjectsEx funtion
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Chromium-dev" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/chromium-dev?hl=en
-~----------~----~----~----~------~----~------~--~---