Class: LLDB::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/lldb/context.rb

Constant Summary collapse

OPEN =
:open
CLOSING =
:closing
CLOSED =
:closed

Instance Method Summary collapse

Constructor Details

#initializeContext

Returns a new instance of Context.

RBS:

  • return: void



14
15
16
17
18
# File 'lib/lldb/context.rb', line 14

def initialize
  @mutex = Mutex.new
  @state = OPEN
  @handles = [] # : Array[WeakRef]
end

Instance Method Details

#close(except: nil) ⇒ Object

RBS:

  • except: NativeHandle?

  • return: void



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/lldb/context.rb', line 58

def close(except: nil)
  handles = @mutex.synchronize do
    next nil if @state == CLOSED || @state == CLOSING

    @state = CLOSING
    @handles.filter_map do |reference|
      begin
        handle = reference.__getobj__
        handle unless handle.equal?(except)
      rescue WeakRef::RefError
        nil
      end
    end
  end
  return unless handles

  begin
    handles.each(&:close)
  ensure
    @mutex.synchronize { @state = CLOSED }
  end
end

#closed?Boolean

RBS:

  • return: bool

Returns:

  • (Boolean)


47
48
49
# File 'lib/lldb/context.rb', line 47

def closed?
  state == CLOSED
end

#closing?Boolean

RBS:

  • return: bool

Returns:

  • (Boolean)


42
43
44
# File 'lib/lldb/context.rb', line 42

def closing?
  state == CLOSING
end

#ensure_open!Object

RBS:

  • return: void

Raises:



52
53
54
# File 'lib/lldb/context.rb', line 52

def ensure_open!
  raise ClosedObjectError, 'LLDB context is closed' unless open?
end

#open?Boolean

RBS:

  • return: bool

Returns:

  • (Boolean)


37
38
39
# File 'lib/lldb/context.rb', line 37

def open?
  state == OPEN
end

#register(handle) ⇒ Object

RBS:

  • handle: NativeHandle

  • return: NativeHandle



22
23
24
25
26
27
28
29
# File 'lib/lldb/context.rb', line 22

def register(handle)
  @mutex.synchronize do
    raise LifecycleError, 'LLDB context is closed' unless @state == OPEN

    @handles << WeakRef.new(handle)
  end
  handle
end

#stateObject

RBS:

  • return: ::Symbol



32
33
34
# File 'lib/lldb/context.rb', line 32

def state
  @mutex.synchronize { @state }
end