Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/concurrent/agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def initialize(initial, opts = {})
@rescuers = []
@validator = nil
@timeout = opts[:timeout] || TIMEOUT
init_mutex
set_deref_options(opts)
end

Expand Down
1 change: 1 addition & 0 deletions lib/concurrent/contract.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class Contract

def initialize(opts = {})
@state = :pending
init_mutex
set_deref_options(opts)
end

Expand Down
13 changes: 8 additions & 5 deletions lib/concurrent/dereferenceable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ module Dereferenceable
# returning the value returned from the proc (default: `nil`)
def set_deref_options(opts = {})
mutex.synchronize do
@dup_on_deref = opts[:dup_on_deref] || opts[:dup] || false
@freeze_on_deref = opts[:freeze_on_deref] || opts[:freeze] || false
@dup_on_deref = opts[:dup_on_deref] || opts[:dup]
@freeze_on_deref = opts[:freeze_on_deref] || opts[:freeze]
@copy_on_deref = opts[:copy_on_deref] || opts[:copy]
@do_nothing_on_deref = ! (@dup_on_deref || @freeze_on_deref || @copy_on_deref)
end
Expand All @@ -33,7 +33,7 @@ def set_deref_options(opts = {})
def value
return nil if @value.nil?
return @value if @do_nothing_on_deref
return mutex.synchronize do
mutex.synchronize do
value = @value
value = @copy_on_deref.call(value) if @copy_on_deref
value = value.dup if @dup_on_deref
Expand All @@ -45,9 +45,12 @@ def value

protected

# @private
def mutex # :nodoc:
@mutex ||= Mutex.new
@mutex
end

def init_mutex
@mutex = Mutex.new
end
end
end
1 change: 1 addition & 0 deletions lib/concurrent/future.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Future
include UsesGlobalThreadPool

def initialize(*args, &block)
init_mutex
unless block_given?
@state = :fulfilled
else
Expand Down
1 change: 1 addition & 0 deletions lib/concurrent/promise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def initialize(*args, &block)
@children = []
@rescuers = []

init_mutex
realize(*args) if root?
end

Expand Down
1 change: 1 addition & 0 deletions lib/concurrent/scheduled_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def initialize(schedule_time, opts = {}, &block)
@state = :pending
@schedule_time.freeze
@task = block
init_mutex
set_deref_options(opts)

@thread = Thread.new{ work }
Expand Down
1 change: 1 addition & 0 deletions lib/concurrent/timer_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ def initialize(opts = {}, &block)
@run_now = opts[:now] || opts[:run_now] || false

@task = block
init_mutex
set_deref_options(opts)
end

Expand Down