• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ruby-concurrency / concurrent-ruby / #2835

05 Oct 2014 10:16PM UTC coverage: 45.201% (-49.6%) from 94.81%
#2835

push

jdantonio
Merge pull request #158 from obrok/promise-composition

Promise composition

2 of 15 new or added lines in 1 file covered. (13.33%)

1514 existing lines in 84 files now uncovered.

1375 of 3042 relevant lines covered (45.2%)

0.66 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

53.57
/lib/concurrent/atomic_reference/mutex_atomic.rb
1
require 'thread'
1✔
2
require 'concurrent/atomic_reference/direct_update'
1✔
3
require 'concurrent/atomic_reference/numeric_cas_wrapper'
1✔
4

5
module Concurrent
1✔
6

7
  # @!macro atomic_reference
8
  class MutexAtomic
1✔
9
    include Concurrent::AtomicDirectUpdate
1✔
10
    include Concurrent::AtomicNumericCompareAndSetWrapper
1✔
11

12
    # @!macro [attach] atomic_reference_method_initialize
13
    def initialize(value = nil)
1✔
UNCOV
14
      @mutex = Mutex.new
×
UNCOV
15
      @value = value
×
16
    end
17

18
    # @!macro [attach] atomic_reference_method_get
19
    #
20
    #   Gets the current value.
21
    #
22
    #   @return [Object] the current value
23
    def get
1✔
UNCOV
24
      @mutex.synchronize { @value }
×
25
    end
26
    alias_method :value, :get
1✔
27

28
    # @!macro [attach] atomic_reference_method_set
29
    #
30
    #   Sets to the given value.
31
    #
32
    #   @param [Object] new_value the new value
33
    #
34
    #   @return [Object] the new value
35
    def set(new_value)
1✔
UNCOV
36
      @mutex.synchronize { @value = new_value }
×
37
    end
38
    alias_method :value=, :set
1✔
39

40
    # @!macro [attach] atomic_reference_method_get_and_set
41
    #
42
    #   Atomically sets to the given value and returns the old value.
43
    #
44
    #   @param [Object] new_value the new value
45
    #
46
    #   @return [Object] the old value
47
    def get_and_set(new_value)
1✔
UNCOV
48
      @mutex.synchronize do
×
UNCOV
49
        old_value = @value
×
UNCOV
50
        @value = new_value
×
UNCOV
51
        old_value
×
52
      end
53
    end
54
    alias_method :swap, :get_and_set
1✔
55

56
    # @!macro [attach] atomic_reference_method_compare_and_set
57
    #
58
    #   Atomically sets the value to the given updated value if
59
    #   the current value == the expected value.
60
    #
61
    #   @param [Object] old_value the expected value
62
    #   @param [Object] new_value the new value
63
    #
64
    #   @return [Boolean] `true` if successful. A `false` return indicates
65
    #   that the actual value was not equal to the expected value.
66
    def _compare_and_set(old_value, new_value) #:nodoc:
1✔
UNCOV
67
      return false unless @mutex.try_lock
×
68
      begin
UNCOV
69
        return false unless @value.equal? old_value
×
UNCOV
70
        @value = new_value
×
71
      ensure
UNCOV
72
        @mutex.unlock
×
73
      end
UNCOV
74
      true
×
75
    end
76
  end
77
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc