@@ -9,13 +9,17 @@ module Concern
99 #
1010 # @!macro copy_options
1111 module Dereferenceable
12+ # NOTE: This module is going away in 2.0. In the mean time we need it to
13+ # play nicely with the synchronization layer. This means that the
14+ # including class SHOULD be synchronized and it MUST implement a
15+ # `#synchronize` method. Not doing so will lead to runtime errors.
1216
1317 # Return the value this object represents after applying the options specified
1418 # by the `#set_deref_options` method.
1519 #
1620 # @return [Object] the current value of the object
1721 def value
18- mutex . synchronize { apply_deref_options ( @value ) }
22+ synchronize { apply_deref_options ( @value ) }
1923 end
2024 alias_method :deref , :value
2125
@@ -25,43 +29,24 @@ def value
2529 #
2630 # @param [Object] value the new value
2731 def value = ( value )
28- mutex . synchronize { @value = value }
29- end
30-
31- # A mutex lock used for synchronizing thread-safe operations. Methods defined
32- # by `Dereferenceable` are synchronized using the `Mutex` returned from this
33- # method. Operations performed by the including class that operate on the
34- # `@value` instance variable should be locked with this `Mutex`.
35- #
36- # @return [Mutex] the synchronization object
37- def mutex
38- @mutex
39- end
40-
41- # Initializes the internal `Mutex`.
42- #
43- # @note This method *must* be called from within the constructor of the including class.
44- #
45- # @see #mutex
46- def init_mutex ( mutex = Mutex . new )
47- @mutex = mutex
32+ synchronize { @value = value }
4833 end
4934
5035 # @!macro [attach] dereferenceable_set_deref_options
5136 # Set the options which define the operations #value performs before
5237 # returning data to the caller (dereferencing).
53- #
38+ #
5439 # @note Most classes that include this module will call `#set_deref_options`
5540 # from within the constructor, thus allowing these options to be set at
5641 # object creation.
57- #
42+ #
5843 # @param [Hash] opts the options defining dereference behavior.
5944 # @option opts [String] :dup_on_deref (false) call `#dup` before returning the data
6045 # @option opts [String] :freeze_on_deref (false) call `#freeze` before returning the data
6146 # @option opts [String] :copy_on_deref (nil) call the given `Proc` passing
6247 # the internal value and returning the value returned from the proc
6348 def set_deref_options ( opts = { } )
64- mutex . synchronize { ns_set_deref_options ( opts ) }
49+ synchronize { ns_set_deref_options ( opts ) }
6550 end
6651
6752 # @!macro dereferenceable_set_deref_options
0 commit comments