[poe-commits] SF.net SVN: poe: [2201] trunk/poe/lib/POE
Brought to you by:
rcaputo
From: <rc...@us...> - 2007-07-23 07:22:57
|
Revision: 2201 http://svn.sourceforge.net/poe/?rev=2201&view=rev Author: rcaputo Date: 2007-07-23 00:22:57 -0700 (Mon, 23 Jul 2007) Log Message: ----------- Resolve a CPU spinning issue when using the Tk event loop without any event watchers. Resolves ticket 27359 reported by Craig at Lucent. Others have also reported this issue, but not in a ticket. :) Modified Paths: -------------- trunk/poe/lib/POE/Loop/TkCommon.pm trunk/poe/lib/POE/Resource/Events.pm Modified: trunk/poe/lib/POE/Loop/TkCommon.pm =================================================================== --- trunk/poe/lib/POE/Loop/TkCommon.pm 2007-07-23 01:37:08 UTC (rev 2200) +++ trunk/poe/lib/POE/Loop/TkCommon.pm 2007-07-23 07:22:57 UTC (rev 2201) @@ -23,7 +23,6 @@ use Tk qw(DoOneEvent DONT_WAIT ALL_EVENTS); my $_watcher_time; -my $_waiting_for_event = 0; #------------------------------------------------------------------------------ # Signal handler maintenance functions. @@ -34,15 +33,11 @@ $window->OnDestroy( sub { if ($self->_data_ses_count()) { - $self->_dispatch_event( $self, $self, EN_SIGNAL, ET_SIGNAL, [ 'UIDESTROY' ], __FILE__, __LINE__, time(), -__LINE__ ); - - # Flag the main loop as done. - $_waiting_for_event = 0; } } ); @@ -56,10 +51,9 @@ $self->loop_pause_time_watcher(); my $timeout = $next_time - time(); - return if $timeout < 0; - $_waiting_for_event = 1; + $timeout = "idle" if $timeout < 0; $_watcher_time = $poe_main_window->after( - $timeout * 1000, [ sub { $_waiting_for_event = 0 } ] + $timeout * 1000, [ sub { } ] ); } @@ -74,7 +68,6 @@ $_watcher_time->cancel() if $_watcher_time->can("cancel"); $_watcher_time = undef; } - $_waiting_for_event = 0; } # TODO - Ton Hospel's Tk event loop doesn't mix alarms and immediate @@ -139,12 +132,7 @@ my $now; $now = time() if TRACE_STATISTICS; - # Idle until the next POE event is due. Process at least one event - # to update the waiting flag, then block until a POE event is ready. - DoOneEvent(DONT_WAIT | ALL_EVENTS); - while ($_waiting_for_event) { - DoOneEvent(ALL_EVENTS); - } + DoOneEvent(ALL_EVENTS); $self->_data_stat_add('idle_seconds', time() - $now) if TRACE_STATISTICS; Modified: trunk/poe/lib/POE/Resource/Events.pm =================================================================== --- trunk/poe/lib/POE/Resource/Events.pm 2007-07-23 01:37:08 UTC (rev 2200) +++ trunk/poe/lib/POE/Resource/Events.pm 2007-07-23 07:22:57 UTC (rev 2201) @@ -272,7 +272,14 @@ } } - $self->loop_reset_time_watcher($next_time); + # Tell the event loop to wait for the next event, if there is one. + # Otherwise we're going to wait indefinitely for some other event. + if (defined $next_time) { + $self->loop_reset_time_watcher($next_time); + } + else { + $self->loop_pause_time_watcher(); + } } 1; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |