C0 code coverage information

Generated on Tue Oct 16 11:40:48 -0400 2007 with rcov 0.8.0


Code reported as executed by Ruby looks like this...
and this: this line is also marked as covered.
Lines considered as run by rcov, but not reported by Ruby, look like this,
and this: these lines were inferred by rcov (using simple heuristics).
Finally, here's a line marked as not executed.
Name Total lines Lines of code Total coverage Code coverage
lib/alexandria/execution_queue.rb 96 56
53.1% 
19.6% 
 1 # Copyright (C) 2005-2006 Laurent Sansonetti
 2 #
 3 # Alexandria is free software; you can redistribute it and/or
 4 # modify it under the terms of the GNU General Public License as
 5 # published by the Free Software Foundation; either version 2 of the
 6 # License, or (at your option) any later version.
 7 #
 8 # Alexandria is distributed in the hope that it will be useful,
 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 # General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public
14 # License along with Alexandria; see the file COPYING.  If not,
15 # write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16 # Boston, MA 02111-1307, USA.
17 
18 require 'thread'
19 
20 # Provides a way for two threads to communicate via Proc objects.
21 #
22 # Thread A can request calls, providing a Proc object and runtime arguments, 
23 # and thread B can iterate through the queue and execute the first call it
24 # founds.
25 #
26 # It is also possible to synchronize the calls (useful if a return value is 
27 # required from the receiving thread).
28 #
29 # This class does not depend of the GLib/GTK main loop idea.
30 
31 module Alexandria
32     class ExecutionQueue
33         def initialize
34             @pending_calls = []
35             @pending_retvals = []
36             @protect_pending_calls = Mutex.new
37             @protect_pending_retvals = Mutex.new
38             @id = 0
39             @@current_queue = self
40         end
41 
42         def self.current
43             @@current_queue rescue nil
44         end
45 
46         # For the requesting thread.
47         def call(procedure, *args)
48             push(procedure, args, false)
49         end
50 
51         def sync_call(procedure, *args)
52             push(procedure, args, true)
53         end
54 
55         # For the executing thread.
56         def iterate
57             ary = @protect_pending_calls.synchronize do 
58                 break @pending_calls.pop
59             end
60             return if ary.nil?
61             id, procedure, args, need_retval = ary
62             retval = procedure.call(*args)
63             if need_retval
64                 @protect_pending_retvals.synchronize do
65                     @pending_retvals << [id, retval]
66                 end
67             end
68         end
69 
70         def stop
71             @@current_queue = nil
72         end
73         
74         #######
75         private
76         #######
77 
78         def push(procedure, args, need_retval=false)
79             @protect_pending_calls.synchronize do
80                 @id += 1
81                 @pending_calls << [@id, procedure, args, need_retval]
82             end
83             if need_retval
84                 while true
85                     @protect_pending_retvals.synchronize do
86                         ary = @pending_retvals.find { |id, retval| id == @id }
87                         if ary
88                             @pending_retvals.delete(ary)
89                             return ary[1]
90                         end
91                     end
92                 end
93             end
94         end
95     end
96 end

Generated using the rcov code coverage analysis tool for Ruby version 0.8.0.

Valid XHTML 1.0! Valid CSS!