Changeset 194

Show
Ignore:
Timestamp:
06/03/06 15:46:31 (2 years ago)
Author:
blackhedd
Message:

Modified the event-handling loop: on any given call to #iterate,
we now only handle the events present on the queue at the start
of the call. Otherwise we might run forever and starve other
dispatchers.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • experiments/NewMachine/lib/machine/event.rb

    r187 r194  
    5050    end 
    5151 
    52     # Process all of the events in the run queue. 
     52    # Process all of the events that are in the run queue 
     53    # when this method starts. 
     54    # (We can easily add more events to ourself as we process existing 
     55    # ones, but that can lead to infinite loops.) 
    5356    def iterate 
    54       while event = @event_q.shift do  
     57      n_events = @event_q.size 
     58      n_events.times do 
     59        event = @event_q.shift 
    5560        log.debug "running handlers for event:  #{event.class}" 
    5661 
  • experiments/NewMachine/lib/machine/reactor.rb

    r192 r194  
    1717  # Uncomment the implementation when we come up with a test case 
    1818  # that needs it. 
     19  # 
     20  # TODO: There's a big problem with clear_dispatchers: it also 
     21  # clears out the system-dispatchers we need, like TimerContainer and 
     22  # EventableIO. 
     23  # 
    1924  class Reactor 
    2025    include LogSupport 
     
    7479    def iterate 
    7580      log.debug "iterating #{@dispatchers.size} dispatchers..." 
    76       @running = true 
    77       @dispatchers.each {|d| d.iterate if running?} 
    78       #@signalled = false 
     81      @dispatchers.each {|d| d.iterate} 
    7982    end 
    8083