Go.rb 0.2.0 → 0.3.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.
- checksums.yaml +4 -4
- data/Rakefile +0 -2
- data/lib/go.rb +10 -5
- data/lib/go/kernel.rb +8 -4
- data/lib/go/{process/channel.rb → pipe.rb} +9 -13
- data/lib/go/process.rb +21 -0
- data/lib/go/version.rb +1 -1
- metadata +4 -8
- data/lib/go/concurrency/future.rb +0 -64
- data/lib/go/concurrency/pool.rb +0 -83
- data/lib/go/engine.rb +0 -17
- data/lib/go/goconfig.rb +0 -31
- data/lib/go/process/goprocess.rb +0 -28
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fe407598b9d20a6bf74c4fd07429f179139f209a
|
4
|
+
data.tar.gz: e05d845eb41f6d5fdd2548316a6b9e500abaa02c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 24bb125a575124cb190dd4c68ad10a352176cc50bda80ff42e26c0b69cd38709117b150cfad9e79e2e43816e1d14ca7db31782d6b570ac6a757b1eabdf347e60
|
7
|
+
data.tar.gz: f76a12972ce937eaaf27b2c9fe1a915a9e5deef66ca2f50fabe67769571cce6c64830f09558543e28e533e39f717b2794cf4afb8e830566aec35552c29674666
|
data/Rakefile
CHANGED
data/lib/go.rb
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
require "go/version"
|
2
|
-
require "go/concurrency/pool"
|
3
|
-
require "go/goconfig"
|
4
2
|
require "go/kernel"
|
5
|
-
require "go/
|
6
|
-
require "go/process
|
7
|
-
|
3
|
+
require "go/pipe"
|
4
|
+
require "go/process"
|
5
|
+
|
6
|
+
module Go
|
7
|
+
class Channel < Queue
|
8
|
+
def get nonblock=false
|
9
|
+
pop nonblock
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/lib/go/kernel.rb
CHANGED
@@ -4,12 +4,16 @@
|
|
4
4
|
# Author:: Jaci Brunning
|
5
5
|
module ::Kernel
|
6
6
|
|
7
|
-
def go(&block)
|
8
|
-
|
7
|
+
def go(*channels, &block)
|
8
|
+
Thread.new *channels, &block
|
9
9
|
end
|
10
10
|
|
11
|
-
def gofork(*
|
12
|
-
Go::Process.new *
|
11
|
+
def gofork(*pipes, &block)
|
12
|
+
Go::Process.new *pipes, &block
|
13
|
+
end
|
14
|
+
|
15
|
+
def gopipe
|
16
|
+
Go::Pipe.new
|
13
17
|
end
|
14
18
|
|
15
19
|
def gochan
|
@@ -1,12 +1,12 @@
|
|
1
1
|
module Go
|
2
|
-
class
|
2
|
+
class Pipe
|
3
3
|
|
4
4
|
def initialize
|
5
5
|
@reader, @writer = IO.pipe
|
6
6
|
end
|
7
7
|
|
8
|
-
def puts data
|
9
|
-
|
8
|
+
def puts data=""
|
9
|
+
writer.puts data
|
10
10
|
end
|
11
11
|
|
12
12
|
def << data
|
@@ -14,19 +14,15 @@ module Go
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def gets
|
17
|
-
|
17
|
+
reader.gets
|
18
18
|
end
|
19
19
|
|
20
20
|
def write data
|
21
|
-
|
21
|
+
writer.write data
|
22
22
|
end
|
23
23
|
|
24
|
-
def read length
|
25
|
-
|
26
|
-
@reader.read
|
27
|
-
else
|
28
|
-
@reader.read length
|
29
|
-
end
|
24
|
+
def read length
|
25
|
+
reader.read length
|
30
26
|
end
|
31
27
|
|
32
28
|
def reader
|
@@ -42,8 +38,8 @@ module Go
|
|
42
38
|
end
|
43
39
|
|
44
40
|
def destroy
|
45
|
-
|
46
|
-
|
41
|
+
reader.close
|
42
|
+
writer.close
|
47
43
|
@reader = nil
|
48
44
|
@writer = nil
|
49
45
|
end
|
data/lib/go/process.rb
ADDED
data/lib/go/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: Go.rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- JacisNonsense
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-09-
|
11
|
+
date: 2015-09-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -81,13 +81,9 @@ files:
|
|
81
81
|
- Rakefile
|
82
82
|
- goruby.gemspec
|
83
83
|
- lib/go.rb
|
84
|
-
- lib/go/concurrency/future.rb
|
85
|
-
- lib/go/concurrency/pool.rb
|
86
|
-
- lib/go/engine.rb
|
87
|
-
- lib/go/goconfig.rb
|
88
84
|
- lib/go/kernel.rb
|
89
|
-
- lib/go/
|
90
|
-
- lib/go/process
|
85
|
+
- lib/go/pipe.rb
|
86
|
+
- lib/go/process.rb
|
91
87
|
- lib/go/version.rb
|
92
88
|
homepage: http://www.github.com/JacisNonsense/go.rb
|
93
89
|
licenses: []
|
@@ -1,64 +0,0 @@
|
|
1
|
-
module Go
|
2
|
-
module CC
|
3
|
-
class Future
|
4
|
-
|
5
|
-
def initialize proc
|
6
|
-
@mutex = Mutex.new
|
7
|
-
@cv = ConditionVariable.new
|
8
|
-
@complete = false
|
9
|
-
@work = proc
|
10
|
-
end
|
11
|
-
|
12
|
-
def work; @work end
|
13
|
-
|
14
|
-
def put val
|
15
|
-
@val = val
|
16
|
-
put_complete
|
17
|
-
end
|
18
|
-
|
19
|
-
def ex e
|
20
|
-
@ex = e
|
21
|
-
put_complete
|
22
|
-
end
|
23
|
-
|
24
|
-
def put_complete
|
25
|
-
@complete = true
|
26
|
-
@cv.broadcast
|
27
|
-
end
|
28
|
-
|
29
|
-
def complete?
|
30
|
-
@complete
|
31
|
-
end
|
32
|
-
|
33
|
-
def errored?
|
34
|
-
!@ex.nil?
|
35
|
-
end
|
36
|
-
|
37
|
-
def get
|
38
|
-
unless @complete
|
39
|
-
@mutex.synchronize do
|
40
|
-
unless @complete
|
41
|
-
@cv.wait(@mutex)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
if @ex
|
46
|
-
raise @ex
|
47
|
-
end
|
48
|
-
|
49
|
-
@val
|
50
|
-
end
|
51
|
-
|
52
|
-
def wait
|
53
|
-
unless @complete
|
54
|
-
@mutex.synchronize do
|
55
|
-
unless @complete
|
56
|
-
@cv.wait(@mutex)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
data/lib/go/concurrency/pool.rb
DELETED
@@ -1,83 +0,0 @@
|
|
1
|
-
require 'thread'
|
2
|
-
require 'go/concurrency/future'
|
3
|
-
module Go
|
4
|
-
module CC
|
5
|
-
class ThreadPool
|
6
|
-
|
7
|
-
def initialize(max_size = 10, growing = true)
|
8
|
-
@max = max_size
|
9
|
-
@threadCount = 0
|
10
|
-
@threads = []
|
11
|
-
@growing = growing
|
12
|
-
@workQueue = Queue.new
|
13
|
-
@running = true
|
14
|
-
|
15
|
-
initStatic() unless @growing
|
16
|
-
end
|
17
|
-
|
18
|
-
def initStatic
|
19
|
-
@max.times do
|
20
|
-
pushThread
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def pushThread
|
25
|
-
@threads << Thread.new do
|
26
|
-
while @running
|
27
|
-
future = @workQueue.pop
|
28
|
-
begin
|
29
|
-
future.put future.work().call()
|
30
|
-
rescue Exception => e
|
31
|
-
future.ex e
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
@threadCount+=1
|
36
|
-
end
|
37
|
-
|
38
|
-
def execute(&block)
|
39
|
-
return execute_proc(block)
|
40
|
-
end
|
41
|
-
|
42
|
-
def execute_proc(proc)
|
43
|
-
future = Future.new proc
|
44
|
-
@workQueue << future
|
45
|
-
|
46
|
-
if @threadCount < @max && @growing
|
47
|
-
createNew = false
|
48
|
-
@threads.each do |t|
|
49
|
-
if t.status() != "sleep"
|
50
|
-
createNew = true
|
51
|
-
end
|
52
|
-
end
|
53
|
-
if (@threadCount == 0)
|
54
|
-
createNew = true
|
55
|
-
end
|
56
|
-
pushThread() if createNew
|
57
|
-
end
|
58
|
-
|
59
|
-
return future
|
60
|
-
end
|
61
|
-
|
62
|
-
def shutdown
|
63
|
-
@running = false
|
64
|
-
@threads.each { |t| t.kill }
|
65
|
-
end
|
66
|
-
|
67
|
-
def max; @max end
|
68
|
-
def growing?; @growing end
|
69
|
-
def running?; @running end
|
70
|
-
def workers; @threadCount end
|
71
|
-
def queued; @workQueue.size() end
|
72
|
-
|
73
|
-
def status
|
74
|
-
status = "Thread Pool: \n"
|
75
|
-
status << "\tMax Size: #{max}, Worker Count: #{workers}\n"
|
76
|
-
status << "\tGrowing?: #{growing? ? 'true' : 'false'}, Queued Jobs: #{queued}\n"
|
77
|
-
status << "\tRunning?: #{running? ? 'true' : 'false'}\n"
|
78
|
-
return status
|
79
|
-
end
|
80
|
-
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
data/lib/go/engine.rb
DELETED
data/lib/go/goconfig.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
module Go
|
2
|
-
class Config
|
3
|
-
|
4
|
-
def initialize(max_threads, growing = true)
|
5
|
-
@threads = max_threads
|
6
|
-
@pool = Go::CC::ThreadPool.new(max_threads, growing)
|
7
|
-
end
|
8
|
-
|
9
|
-
def max_thread_count
|
10
|
-
@threads
|
11
|
-
end
|
12
|
-
|
13
|
-
def thread_pool
|
14
|
-
@pool
|
15
|
-
end
|
16
|
-
|
17
|
-
def self.create(max_threads = 10, growing = true)
|
18
|
-
@@config = Config.new(max_threads, growing)
|
19
|
-
end
|
20
|
-
|
21
|
-
def self.maybe_create(max_threads = 10)
|
22
|
-
@@config ||= Config.new(max_threads)
|
23
|
-
end
|
24
|
-
|
25
|
-
def self.get
|
26
|
-
maybe_create
|
27
|
-
@@config
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
31
|
-
end
|
data/lib/go/process/goprocess.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
module Go
|
2
|
-
class Process
|
3
|
-
|
4
|
-
def initialize *channels, &block
|
5
|
-
@channels = channels
|
6
|
-
@pid = fork {
|
7
|
-
block.call *channels
|
8
|
-
}
|
9
|
-
end
|
10
|
-
|
11
|
-
def wait
|
12
|
-
::Process.wait @pid
|
13
|
-
end
|
14
|
-
|
15
|
-
def channels
|
16
|
-
@channels
|
17
|
-
end
|
18
|
-
|
19
|
-
def pid
|
20
|
-
@pid
|
21
|
-
end
|
22
|
-
|
23
|
-
def kill
|
24
|
-
::Process.kill 9, @pid
|
25
|
-
end
|
26
|
-
|
27
|
-
end
|
28
|
-
end
|