barney 0.4.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/ChangeLog +7 -1
- data/README.md +2 -4
- data/Rakefile +1 -0
- data/lib/barney/share.rb +13 -14
- data/lib/barney.rb +1 -1
- data/test/suite/lib/barney/share#fork.rb +1 -1
- data/test/suite/lib/barney/share#synchronize.rb +19 -0
- metadata +4 -20
data/ChangeLog
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
2011-03-04 Robert Gleeson <rob@flowof.info> v0.5.0
|
2
|
+
|
3
|
+
* Solve Github Issue no. 3
|
4
|
+
* Solve Github Issue no. 2
|
5
|
+
* Write a more efficient and easier to understand Barney::Share#sync method.
|
6
|
+
|
1
7
|
2011-02-16 Robert Gleeson <rob@flowof.info> v0.4.1
|
2
8
|
|
3
9
|
* Add http://www.gem-testers.org support.
|
@@ -9,7 +15,7 @@
|
|
9
15
|
|
10
16
|
2011-01-16 Robert Gleeson <rob@flowof.info> v0.3.1
|
11
17
|
|
12
|
-
* Solve Github Issue
|
18
|
+
* Solve Github Issue no. 1.
|
13
19
|
* Add Barney::Share#pid.
|
14
20
|
|
15
21
|
2011-01-04 Robert Gleeson <rob@flowof.info> v0.2.0
|
data/README.md
CHANGED
@@ -88,6 +88,7 @@ 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.5.0](http://rubydoc.info/gems/barney/0.5.0)
|
91
92
|
* [0.4.1](http://rubydoc.info/gems/barney/0.4.1)
|
92
93
|
* [0.4.0](http://rubydoc.info/gems/barney/0.4.0)
|
93
94
|
* [0.3.1](http://rubydoc.info/gems/barney/0.3.1)
|
@@ -96,10 +97,7 @@ Okay, now that we've got that out of the way, let's see what using Barney is lik
|
|
96
97
|
|
97
98
|
## License
|
98
99
|
|
99
|
-
Barney is released under the LGPL.
|
100
|
-
You are free to **use** this library in free or commercial software, and license that software however you want,
|
101
|
-
but as soon as you modify the library itself,
|
102
|
-
you must share your changes under the same license. :)
|
100
|
+
Barney is released under the Lesser GPL(LGPL).
|
103
101
|
|
104
102
|
## Install
|
105
103
|
|
data/Rakefile
CHANGED
data/lib/barney/share.rb
CHANGED
@@ -68,16 +68,15 @@ module Barney
|
|
68
68
|
# @return [Fixnum] Returns the Process ID(PID) of the spawned child process.
|
69
69
|
def fork &blk
|
70
70
|
raise ArgumentError, "A block or Proc object is expected" unless block_given?
|
71
|
-
|
72
71
|
share *@shared.keys if @pid
|
73
72
|
|
74
73
|
@context = blk.binding
|
75
74
|
@pid = Kernel.fork do
|
76
75
|
blk.call
|
77
|
-
@shared.each do |variable,
|
78
|
-
|
79
|
-
|
80
|
-
|
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
80
|
end
|
82
81
|
end
|
83
82
|
|
@@ -89,16 +88,16 @@ module Barney
|
|
89
88
|
# It will block until the spawned child process has exited.
|
90
89
|
# @return [void]
|
91
90
|
def synchronize
|
92
|
-
@shared.each do |variable,
|
91
|
+
@shared.each do |variable, pipes|
|
93
92
|
Barney::Share.mutex.synchronize do
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
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
|
98
|
+
object = eval "#{variable} = Barney::Share.value", @context
|
99
|
+
@history[seq] = (@history[seq] || {}).merge({ variable => object })
|
100
|
+
pipes.delete seq
|
102
101
|
end
|
103
102
|
end
|
104
103
|
end
|
data/lib/barney.rb
CHANGED
@@ -50,6 +50,25 @@ describe Barney::Share do
|
|
50
50
|
assert_equal 6, $times
|
51
51
|
end
|
52
52
|
|
53
|
+
it 'should fix Github Issue #2' do
|
54
|
+
a,b = 4,5
|
55
|
+
@object.share :a
|
56
|
+
@object.fork { }
|
57
|
+
Process.wait @object.pid
|
58
|
+
@object.share :b
|
59
|
+
@object.fork { b = 6 }
|
60
|
+
@object.sync # will raise NoMethodError if fails.
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'should fix GitHub Issue #3' do
|
64
|
+
a,b = 4,5
|
65
|
+
@object.share :a, :b
|
66
|
+
@object.fork { }
|
67
|
+
Process.wait @object.pid
|
68
|
+
@object.sync
|
69
|
+
assert_equal({ 0 => { :a => 4, :b => 5 } }, @object.history)
|
70
|
+
end
|
71
|
+
|
53
72
|
end
|
54
73
|
end
|
55
74
|
|
metadata
CHANGED
@@ -1,12 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: barney
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
|
6
|
-
- 0
|
7
|
-
- 4
|
8
|
-
- 1
|
9
|
-
version: 0.4.1
|
4
|
+
prerelease:
|
5
|
+
version: 0.5.0
|
10
6
|
platform: ruby
|
11
7
|
authors:
|
12
8
|
- Robert Gleeson
|
@@ -14,7 +10,7 @@ autorequire:
|
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
12
|
|
17
|
-
date: 2011-
|
13
|
+
date: 2011-03-04 00:00:00 +00:00
|
18
14
|
default_executable:
|
19
15
|
dependencies:
|
20
16
|
- !ruby/object:Gem::Dependency
|
@@ -25,8 +21,6 @@ dependencies:
|
|
25
21
|
requirements:
|
26
22
|
- - ">="
|
27
23
|
- !ruby/object:Gem::Version
|
28
|
-
segments:
|
29
|
-
- 0
|
30
24
|
version: "0"
|
31
25
|
type: :development
|
32
26
|
version_requirements: *id001
|
@@ -38,8 +32,6 @@ dependencies:
|
|
38
32
|
requirements:
|
39
33
|
- - ">="
|
40
34
|
- !ruby/object:Gem::Version
|
41
|
-
segments:
|
42
|
-
- 0
|
43
35
|
version: "0"
|
44
36
|
type: :development
|
45
37
|
version_requirements: *id002
|
@@ -79,25 +71,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
79
71
|
requirements:
|
80
72
|
- - ">="
|
81
73
|
- !ruby/object:Gem::Version
|
82
|
-
segments:
|
83
|
-
- 1
|
84
|
-
- 9
|
85
|
-
- 1
|
86
74
|
version: 1.9.1
|
87
75
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
76
|
none: false
|
89
77
|
requirements:
|
90
78
|
- - ">="
|
91
79
|
- !ruby/object:Gem::Version
|
92
|
-
segments:
|
93
|
-
- 1
|
94
|
-
- 3
|
95
|
-
- 6
|
96
80
|
version: 1.3.6
|
97
81
|
requirements: []
|
98
82
|
|
99
83
|
rubyforge_project: "[none]"
|
100
|
-
rubygems_version: 1.
|
84
|
+
rubygems_version: 1.6.0
|
101
85
|
signing_key:
|
102
86
|
specification_version: 3
|
103
87
|
summary: Barney tries to make the sharing of data between processes as easy and natural as possible.
|