Class: Concurrent::FiberLocals
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
AbstractLocals
|
|
Instance Chain:
self,
AbstractLocals
|
|
Inherits: |
Concurrent::AbstractLocals
|
Defined in: | lib/concurrent-ruby/concurrent/atomic/locals.rb |
Overview
Note:
**Private Implementation:** This abstraction is a private, internal implementation detail. It should never be used directly.
An array-backed storage of indexed variables per fiber.
Class Method Summary
AbstractLocals
- Inherited
Instance Method Summary
AbstractLocals
- Inherited
#fetch, #free_index, #next_index, #set, #synchronize, | |
#weak_synchronize | Alias for AbstractLocals#synchronize. |
#local_finalizer | When the local goes out of scope, clean up that slot across all locals currently assigned. |
#locals | Returns the locals for the current scope, or nil if none exist. |
#locals! | Returns the locals for the current scope, creating them if necessary. |
#thread_fiber_finalizer | When a thread/fiber goes out of scope, remove the array from @all_arrays. |
Constructor Details
This class inherits a constructor from Concurrent::AbstractLocals
Instance Method Details
#locals
[ GitHub ]# File 'lib/concurrent-ruby/concurrent/atomic/locals.rb', line 167
def locals Thread.current[:concurrent_fiber_locals] end
#locals!
[ GitHub ]# File 'lib/concurrent-ruby/concurrent/atomic/locals.rb', line 171
def locals! thread = Thread.current locals = thread[:concurrent_fiber_locals] unless locals locals = thread[:concurrent_fiber_locals] = [] weak_synchronize do @all_arrays[locals.object_id] = locals end # When the fiber goes out of scope, we should delete the associated locals: ObjectSpace.define_finalizer(Fiber.current, thread_fiber_finalizer(locals.object_id)) end locals end