Class: Innertube::Pool::Element
- Inherits:
-
Object
- Object
- Innertube::Pool::Element
- Defined in:
- lib/innertube.rb
Overview
An element of the pool. Comprises an object with an owning thread. Not usually needed by user code, and should not be modified outside the Innertube::Pool‘s lock.
Instance Attribute Summary collapse
-
#object ⇒ Object
readonly
Returns the value of attribute object.
-
#owner ⇒ Object
readonly
Returns the value of attribute owner.
Instance Method Summary collapse
-
#initialize(object) ⇒ Element
constructor
Creates a pool element.
-
#lock ⇒ Object
Claims this element of the pool for the current Thread.
-
#locked? ⇒ true, false
Is this element locked/claimed?.
-
#unlock ⇒ Object
Releases this element of the pool from the current Thread.
-
#unlocked? ⇒ true, false
Is this element available for use?.
Constructor Details
#initialize(object) ⇒ Element
Creates a pool element
24 25 26 27 |
# File 'lib/innertube.rb', line 24 def initialize(object) @object = object @owner = nil end |
Instance Attribute Details
#object ⇒ Object (readonly)
Returns the value of attribute object.
20 21 22 |
# File 'lib/innertube.rb', line 20 def object @object end |
#owner ⇒ Object (readonly)
Returns the value of attribute owner.
20 21 22 |
# File 'lib/innertube.rb', line 20 def owner @owner end |
Instance Method Details
#lock ⇒ Object
Claims this element of the pool for the current Thread. Do not call this manually, it is only used from inside the pool.
31 32 33 |
# File 'lib/innertube.rb', line 31 def lock @owner = Thread.current end |
#locked? ⇒ true, false
Returns Is this element locked/claimed?.
36 37 38 |
# File 'lib/innertube.rb', line 36 def locked? !unlocked? end |
#unlock ⇒ Object
Releases this element of the pool from the current Thread.
41 42 43 |
# File 'lib/innertube.rb', line 41 def unlock @owner = nil end |
#unlocked? ⇒ true, false
Returns Is this element available for use?.
46 47 48 |
# File 'lib/innertube.rb', line 46 def unlocked? owner.nil? end |