#--------------------------------------------------------------------# # # # (C) Copyright Rubysophic Inc. 2007-2008 # # All rights reserved. # # # # Use, duplication or disclosure of the code is not permitted # # unless licensed. # # # # Last Updated: 7/09/08 # #--------------------------------------------------------------------# # # # RubyRunBufferMgr__ module is responsible for passing the data # # from the inline execution thread to the monitor thread # # # # Two buffers (primary and secondary) are used and the buffers are # # swapped between the inline execution thread and RubyRunMonitor__ # # thread periodically as defined by REPORT_TIMER. The inline # # execution thread pushes data into the primary buffer, when the # # REPORT_TIMER expires, RubyRunMonitor__ thread then takes it over # # and gives the inline execution thread the secondary buffer via # # a quick swap. The same process keeps repeating as the monitor # # timer pops and the primary and secondary keep switched between # # the two threads. # # # #--------------------------------------------------------------------# module RubyRunBufferMgr__ # Push data into the current buffer # Primary or secondary buffer may be used but it is transparent to the caller def push_current_buffer(metrics) $rubyrun_lock.synchronize { ($rubyrun_current_buffer == 1 ? $rubyrun_prime_buffer : $rubyrun_alt_buffer) << metrics } end # Return the current buffer and swap it with the other one # This method is invoked by the consumer of the data in the buffer def return_and_switch_buffer() $rubyrun_lock.synchronize { if ($rubyrun_current_buffer == 1) $rubyrun_current_buffer == 2 $rubyrun_prime_buffer else $rubyrun_current_buffer == 1 $rubyrun_alt_buffer end } end end