Skip to content

Commit

Permalink
Fix placement and add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
pitr-ch committed Feb 10, 2020
1 parent 53e31a5 commit 99dc326
Showing 1 changed file with 10 additions and 0 deletions.
@@ -1,17 +1,26 @@
require 'concurrent/atomic/abstract_thread_local_var'

module Concurrent
# Has the same interface as {ThreadLocalVar} but the value can never be changed.
# The value is always the default provided to the constructor.
class ConstantThreadLocalVar < AbstractThreadLocalVar

# @note the value is always equal to default value
# @!macro thread_local_var_method_get
def value
default
end

# @!macro thread_local_var_method_set
# @raise ArgumentError if the value is not equal to the default
def value=(value)
if value != default
raise ArgumentError, "Constant thread local vars may not be altered"
end
end

# @!macro thread_local_var_method_bind
# @raise ArgumentError if the value is not equal to the default
def bind(value)
self.value = value
if block_given?
Expand All @@ -20,6 +29,7 @@ def bind(value)
end

protected

def allocate_storage
# nothing to do
end
Expand Down

0 comments on commit 99dc326

Please sign in to comment.