Class: UserfaultFD::Handler
- Inherits:
-
Object
- Object
- UserfaultFD::Handler
- Defined in:
- lib/userfaultfd/handler.rb,
sig/userfaultfd.rbs
Overview
Owns either a Ruby callback thread or a GVL-free native handler thread.
Instance Attribute Summary collapse
-
#error ⇒ StandardError?
readonly
Returns the value of attribute error.
Instance Method Summary collapse
-
#initialize(uffd, mode: nil, io: nil, source: nil, &block) ⇒ Handler
constructor
A new instance of Handler.
- #running? ⇒ Boolean
- #stop ⇒ self
Constructor Details
#initialize(uffd, mode: nil, io: nil, source: nil, &block) ⇒ Handler
Returns a new instance of Handler.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/userfaultfd/handler.rb', line 8 def initialize(uffd, mode: nil, io: nil, source: nil, &block) raise ArgumentError, "choose a block or mode, not both" if mode && block raise ArgumentError, "a block or mode is required" unless mode || block @uffd = uffd if block raise DeadlockError, "strict mode cannot verify raw pointer faults" if UserfaultFD.strict warn "userfaultfd: Ruby handlers require Region#read/write or a separate faulting process" start_ruby_handler(block) else native_source = mode == :backing_file ? io : source @native = uffd.__send__(:start_native_handler, mode, native_source) end end |
Instance Attribute Details
#error ⇒ StandardError? (readonly)
Returns the value of attribute error.
6 7 8 |
# File 'lib/userfaultfd/handler.rb', line 6 def error @error end |
Instance Method Details
#running? ⇒ Boolean
40 41 42 |
# File 'lib/userfaultfd/handler.rb', line 40 def running? @native ? @native.running? : !!@thread&.alive? end |
#stop ⇒ self
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/userfaultfd/handler.rb', line 24 def stop if @native @native.stop return self end return self unless @thread raise Error, "handler cannot stop itself" if Thread.current == @thread @stop_writer.write_nonblock(".") rescue nil @thread.join @thread = nil raise @error if @error self end |