1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
| | # -*- encoding: binary -*-
# Copyright (C) 2013, Eric Wong <normalperson@yhbt.net> and all contributors
# License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt)
class Yahns::Worker # :nodoc:
attr_accessor :nr
attr_reader :to_io
def initialize(nr)
@nr = nr
@to_io, @wr = Kgio::Pipe.new
end
def atfork_child
@wr = @wr.close # nil @wr to save space in worker process
end
def atfork_parent
@to_io = @to_io.close
self
end
# used in the worker process.
# This causes the worker to gracefully exit if the master
# dies unexpectedly.
def yahns_step
if @to_io.kgio_tryread(11) == nil
Process.kill(:QUIT, $$)
@to_io.close
end
:ignore
end
# worker objects may be compared to just plain Integers
def ==(other_nr) # :nodoc:
@nr == other_nr
end
end
|