barney 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/ChangeLog +6 -0
  2. data/README.md +2 -3
  3. data/lib/barney/share.rb +19 -14
  4. data/lib/barney.rb +1 -1
  5. metadata +1 -1
data/ChangeLog CHANGED
@@ -1,3 +1,9 @@
1
+ 2011-03-04 Robert Gleeson <rob@flowof.info> v0.6.0
2
+
3
+ * Objects returned by IO.pipe and the current sequence are enclosed in a Struct referenced by StreamPair.
4
+ * @shared stores instances of StreamPair in an Array.
5
+ * No longer store objects returned by IO.pipe and the current sequence in a Hash.
6
+
1
7
  2011-03-04 Robert Gleeson <rob@flowof.info> v0.5.0
2
8
 
3
9
  * Solve Github Issue no. 3
data/README.md CHANGED
@@ -88,12 +88,11 @@ Okay, now that we've got that out of the way, let's see what using Barney is lik
88
88
  **API**
89
89
 
90
90
  * [master (git)](http://rubydoc.info/github/robgleeson/Barney/master/)
91
+ * [0.6.0](http://rubydoc.info/gems/barney/0.6.0)
91
92
  * [0.5.0](http://rubydoc.info/gems/barney/0.5.0)
92
93
  * [0.4.1](http://rubydoc.info/gems/barney/0.4.1)
93
94
  * [0.4.0](http://rubydoc.info/gems/barney/0.4.0)
94
- * [0.3.1](http://rubydoc.info/gems/barney/0.3.1)
95
- * [0.2.0](http://rubydoc.info/gems/barney/0.2.0)
96
- * [0.1.0](http://rubydoc.info/gems/barney/0.1.0)
95
+ *
97
96
 
98
97
  ## License
99
98
 
data/lib/barney/share.rb CHANGED
@@ -2,6 +2,9 @@ module Barney
2
2
 
3
3
  class Share
4
4
 
5
+ # @api private
6
+ StreamPair = Struct.new :seq, :in, :out
7
+
5
8
  @mutex = Mutex.new
6
9
 
7
10
  class << self
@@ -42,7 +45,9 @@ module Barney
42
45
  # @return [Array<Symbol>] Returns a list of all variables that are being shared.
43
46
  def share *variables
44
47
  variables.map(&:to_sym).each do |variable|
45
- @shared.store variable, (@shared[variable] || {}).merge({ @seq => IO.pipe })
48
+ if (@shared[variable].nil?) || (not @shared[variable].find { |struct| struct.seq == @seq })
49
+ @shared.store variable, (@shared[variable] || []) << StreamPair.new(@seq, *IO.pipe)
50
+ end
46
51
  end
47
52
  @shared.keys
48
53
  end
@@ -73,10 +78,11 @@ module Barney
73
78
  @context = blk.binding
74
79
  @pid = Kernel.fork do
75
80
  blk.call
76
- @shared.each do |variable, pipes|
77
- pipes[@seq][0].close
78
- pipes[@seq][1].write Marshal.dump(eval("#{variable}", @context))
79
- pipes[@seq][1].close
81
+ @shared.each do |variable, array|
82
+ stream = array[-1]
83
+ stream.in.close
84
+ stream.out.write Marshal.dump(eval("#{variable}", @context))
85
+ stream.out.close
80
86
  end
81
87
  end
82
88
 
@@ -88,17 +94,16 @@ module Barney
88
94
  # It will block until the spawned child process has exited.
89
95
  # @return [void]
90
96
  def synchronize
91
- @shared.each do |variable, pipes|
92
- Barney::Share.mutex.synchronize do
93
- min, max = pipes.keys.min, pipes.keys.max
94
- min.upto max do |seq|
95
- pipes[seq][1].close
96
- Barney::Share.value = Marshal.load pipes[seq][0].read
97
- pipes[seq][0].close
97
+ Barney::Share.mutex.synchronize do
98
+ @shared.each do |variable, array|
99
+ array.each do |stream|
100
+ stream.out.close
101
+ Barney::Share.value = Marshal.load stream.in.read
102
+ stream.in.close
98
103
  object = eval "#{variable} = Barney::Share.value", @context
99
- @history[seq] = (@history[seq] || {}).merge({ variable => object })
100
- pipes.delete seq
104
+ @history[stream.seq] = (@history[stream.seq] || {}).merge!({ variable => object })
101
105
  end
106
+ array.clear
102
107
  end
103
108
  end
104
109
  end
data/lib/barney.rb CHANGED
@@ -2,7 +2,7 @@ require('barney/share')
2
2
 
3
3
  module Barney
4
4
 
5
- VERSION = '0.5.0'
5
+ VERSION = '0.6.0'
6
6
 
7
7
  end
8
8
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: barney
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.5.0
5
+ version: 0.6.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Robert Gleeson