evt 0.1.4 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +51 -0
- data/.gitignore +1 -0
- data/Gemfile +1 -1
- data/README.md +50 -13
- data/evt.gemspec +2 -2
- data/ext/evt/epoll.h +91 -0
- data/ext/evt/evt.c +22 -206
- data/ext/evt/evt.h +72 -1
- data/ext/evt/extconf.rb +9 -2
- data/ext/evt/iocp.h +126 -0
- data/ext/evt/kqueue.h +97 -0
- data/ext/evt/select.h +36 -0
- data/ext/evt/uring.h +201 -0
- data/lib/evt.rb +1 -2
- data/lib/evt/scheduler.rb +51 -92
- data/lib/evt/version.rb +1 -1
- metadata +10 -7
- data/.travis.yml +0 -25
- data/Gemfile.lock +0 -24
- data/lib/evt/io.rb +0 -9
data/lib/evt.rb
CHANGED
data/lib/evt/scheduler.rb
CHANGED
@@ -2,56 +2,55 @@
|
|
2
2
|
|
3
3
|
require 'fiber'
|
4
4
|
require 'socket'
|
5
|
-
|
6
|
-
begin
|
7
|
-
require 'io/nonblock'
|
8
|
-
rescue LoadError
|
9
|
-
# Ignore.
|
10
|
-
end
|
5
|
+
require 'io/nonblock'
|
11
6
|
|
12
7
|
class Evt::Scheduler
|
13
8
|
def initialize
|
14
9
|
@readable = {}
|
15
10
|
@writable = {}
|
11
|
+
@iovs = {}
|
16
12
|
@waiting = {}
|
17
|
-
|
13
|
+
|
14
|
+
@lock = Mutex.new
|
15
|
+
@locking = 0
|
16
|
+
@ready = []
|
18
17
|
|
19
18
|
@ios = ObjectSpace::WeakMap.new
|
20
19
|
init_selector
|
21
20
|
end
|
22
21
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
attr :blocking
|
22
|
+
attr_reader :readable
|
23
|
+
attr_reader :writable
|
24
|
+
attr_reader :waiting
|
27
25
|
|
28
26
|
def next_timeout
|
29
27
|
_fiber, timeout = @waiting.min_by{|key, value| value}
|
30
28
|
|
31
29
|
if timeout
|
32
30
|
offset = timeout - current_time
|
33
|
-
|
34
|
-
if offset < 0
|
35
|
-
return 0
|
36
|
-
else
|
37
|
-
return offset
|
38
|
-
end
|
31
|
+
offset < 0 ? 0 : offset
|
39
32
|
end
|
40
33
|
end
|
41
34
|
|
42
35
|
def run
|
43
|
-
while @readable.any? or @writable.any? or @waiting.any?
|
44
|
-
readable, writable = self.wait
|
45
|
-
|
46
|
-
# puts "readable: #{readable}" if readable&.any?
|
47
|
-
# puts "writable: #{writable}" if writable&.any?
|
36
|
+
while @readable.any? or @writable.any? or @waiting.any? or @iovs.any? or @locking.positive?
|
37
|
+
readable, writable, iovs = self.wait
|
48
38
|
|
49
39
|
readable&.each do |io|
|
50
|
-
@readable
|
40
|
+
fiber = @readable.delete(io)
|
41
|
+
fiber&.resume
|
51
42
|
end
|
52
43
|
|
53
44
|
writable&.each do |io|
|
54
|
-
@writable
|
45
|
+
fiber = @writable.delete(io)
|
46
|
+
fiber&.resume
|
47
|
+
end
|
48
|
+
|
49
|
+
unless iovs.nil?
|
50
|
+
iovs&.each do |io|
|
51
|
+
fiber = @iovs.delete(io)
|
52
|
+
fiber&.resume
|
53
|
+
end
|
55
54
|
end
|
56
55
|
|
57
56
|
if @waiting.any?
|
@@ -67,96 +66,56 @@ class Evt::Scheduler
|
|
67
66
|
end
|
68
67
|
end
|
69
68
|
end
|
70
|
-
end
|
71
|
-
end
|
72
69
|
|
73
|
-
|
74
|
-
|
75
|
-
end
|
76
|
-
|
77
|
-
def wait_readable(io)
|
78
|
-
@readable[io] = Fiber.current
|
79
|
-
self.register(io, IO::WAIT_READABLE)
|
80
|
-
Fiber.yield
|
81
|
-
@readable.delete(io)
|
82
|
-
self.deregister(io)
|
83
|
-
return true
|
84
|
-
end
|
70
|
+
if @ready.any?
|
71
|
+
ready = nil
|
85
72
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
)
|
90
|
-
end
|
91
|
-
|
92
|
-
def wait_writable(io)
|
93
|
-
@writable[io] = Fiber.current
|
94
|
-
self.register(io, IO::WAIT_WRITABLE)
|
95
|
-
Fiber.yield
|
96
|
-
@writable.delete(io)
|
97
|
-
self.deregister(io)
|
98
|
-
return true
|
99
|
-
end
|
73
|
+
@lock.synchronize do
|
74
|
+
ready, @ready = @ready, []
|
75
|
+
end
|
100
76
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
77
|
+
ready.each do |fiber|
|
78
|
+
fiber.resume
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
105
82
|
end
|
106
83
|
|
107
84
|
def current_time
|
108
85
|
Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
109
86
|
end
|
110
87
|
|
111
|
-
def
|
112
|
-
@
|
113
|
-
|
114
|
-
Fiber.yield
|
115
|
-
|
116
|
-
return true
|
117
|
-
end
|
118
|
-
|
119
|
-
def wait_any(io, events, duration)
|
120
|
-
unless (events & IO::WAIT_READABLE).zero?
|
121
|
-
@readable[io] = Fiber.current
|
122
|
-
end
|
123
|
-
|
124
|
-
unless (events & IO::WAIT_WRITABLE).zero?
|
125
|
-
@writable[io] = Fiber.current
|
126
|
-
end
|
127
|
-
|
88
|
+
def io_wait(io, events, duration)
|
89
|
+
@readable[io] = Fiber.current unless (events & IO::READABLE).zero?
|
90
|
+
@writable[io] = Fiber.current unless (events & IO::WRITABLE).zero?
|
128
91
|
self.register(io, events)
|
129
|
-
|
130
92
|
Fiber.yield
|
131
|
-
|
132
|
-
@readable.delete(io)
|
133
|
-
@writable.delete(io)
|
134
93
|
self.deregister(io)
|
135
|
-
|
136
|
-
return true
|
94
|
+
true
|
137
95
|
end
|
138
96
|
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
events,
|
144
|
-
duration
|
145
|
-
)
|
97
|
+
def kernel_sleep(duration = nil)
|
98
|
+
@waiting[Fiber.current] = current_time + duration if duration.nil?
|
99
|
+
Fiber.yield
|
100
|
+
true
|
146
101
|
end
|
147
102
|
|
148
|
-
def
|
149
|
-
|
103
|
+
def mutex_lock(mutex)
|
104
|
+
@locking += 1
|
105
|
+
Fiber.yield
|
106
|
+
ensure
|
107
|
+
@locking -= 1
|
150
108
|
end
|
151
109
|
|
152
|
-
def
|
153
|
-
|
154
|
-
|
110
|
+
def mutex_unlock(mutex, fiber)
|
111
|
+
@lock.synchronize do
|
112
|
+
@ready << fiber
|
113
|
+
end
|
155
114
|
end
|
156
115
|
|
157
116
|
def fiber(&block)
|
158
117
|
fiber = Fiber.new(blocking: false, &block)
|
159
118
|
fiber.resume
|
160
|
-
|
119
|
+
fiber
|
161
120
|
end
|
162
121
|
end
|
data/lib/evt/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: evt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Delton Ding
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-12-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake-compiler
|
@@ -32,20 +32,23 @@ extensions:
|
|
32
32
|
- ext/evt/extconf.rb
|
33
33
|
extra_rdoc_files: []
|
34
34
|
files:
|
35
|
+
- ".github/workflows/test.yml"
|
35
36
|
- ".gitignore"
|
36
|
-
- ".travis.yml"
|
37
37
|
- CODE_OF_CONDUCT.md
|
38
38
|
- Gemfile
|
39
|
-
- Gemfile.lock
|
40
39
|
- LICENSE
|
41
40
|
- README.md
|
42
41
|
- Rakefile
|
43
42
|
- evt.gemspec
|
43
|
+
- ext/evt/epoll.h
|
44
44
|
- ext/evt/evt.c
|
45
45
|
- ext/evt/evt.h
|
46
46
|
- ext/evt/extconf.rb
|
47
|
+
- ext/evt/iocp.h
|
48
|
+
- ext/evt/kqueue.h
|
49
|
+
- ext/evt/select.h
|
50
|
+
- ext/evt/uring.h
|
47
51
|
- lib/evt.rb
|
48
|
-
- lib/evt/io.rb
|
49
52
|
- lib/evt/scheduler.rb
|
50
53
|
- lib/evt/version.rb
|
51
54
|
homepage: https://github.com/dsh0416/evt
|
@@ -62,14 +65,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
62
65
|
requirements:
|
63
66
|
- - ">="
|
64
67
|
- !ruby/object:Gem::Version
|
65
|
-
version: 2.
|
68
|
+
version: 2.8.0.dev
|
66
69
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
70
|
requirements:
|
68
71
|
- - ">="
|
69
72
|
- !ruby/object:Gem::Version
|
70
73
|
version: '0'
|
71
74
|
requirements: []
|
72
|
-
rubygems_version: 3.
|
75
|
+
rubygems_version: 3.2.2
|
73
76
|
signing_key:
|
74
77
|
specification_version: 4
|
75
78
|
summary: A low-level Event Handler designed for Ruby 3 Scheduler
|
data/.travis.yml
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
---
|
2
|
-
language: ruby
|
3
|
-
cache: bundler
|
4
|
-
rvm: 2.7.1
|
5
|
-
matrix:
|
6
|
-
include:
|
7
|
-
- rvm: 2.7.1
|
8
|
-
os: linux
|
9
|
-
- rvm: 2.7.1
|
10
|
-
os: osx
|
11
|
-
- rvm: ruby-head
|
12
|
-
allow_failures:
|
13
|
-
- rvm: ruby-head
|
14
|
-
fast_finish: true
|
15
|
-
|
16
|
-
before_install: gem install bundler -v 2.1.4
|
17
|
-
script:
|
18
|
-
- gem list -l
|
19
|
-
- bundle exec rake compile
|
20
|
-
- bundle exec rake
|
21
|
-
|
22
|
-
bundler_args: --jobs 1 --retry 3
|
23
|
-
|
24
|
-
notifications:
|
25
|
-
email: false
|
data/Gemfile.lock
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
evt (0.1.1)
|
5
|
-
|
6
|
-
GEM
|
7
|
-
remote: https://rubygems.org/
|
8
|
-
specs:
|
9
|
-
minitest (5.14.1)
|
10
|
-
rake (12.3.3)
|
11
|
-
rake-compiler (1.1.1)
|
12
|
-
rake
|
13
|
-
|
14
|
-
PLATFORMS
|
15
|
-
ruby
|
16
|
-
|
17
|
-
DEPENDENCIES
|
18
|
-
evt!
|
19
|
-
minitest (~> 5.0)
|
20
|
-
rake (~> 12.0)
|
21
|
-
rake-compiler (~> 1.0)
|
22
|
-
|
23
|
-
BUNDLED WITH
|
24
|
-
2.2.0.dev
|