@!macro [attach] atomic_fixnum
A numeric value that can be updated atomically. Reads and writes to an atomic fixnum and thread-safe and guaranteed to succeed. Reads and writes may block briefly but no explicit locking is required. Testing with ruby 2.1.2 Testing with Concurrent::MutexAtomicFixnum... 3.130000 0.000000 3.130000 ( 3.136505) Testing with Concurrent::CAtomicFixnum... 0.790000 0.000000 0.790000 ( 0.785550) Testing with jruby 1.9.3 Testing with Concurrent::MutexAtomicFixnum... 5.460000 2.460000 7.920000 ( 3.715000) Testing with Concurrent::JavaAtomicFixnum... 4.520000 0.030000 4.550000 ( 1.187000) @see http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/atomic/AtomicLong.html java.util.concurrent.atomic.AtomicLong
@!visibility private @!macro internal_implementation_note
@!macro [attach] atomic_fixnum_method_initialize
Creates a new `AtomicFixnum` with the given initial value. @param [Fixnum] initial the initial value @raise [ArgumentError] if the initial value is not a `Fixnum`
# File lib/concurrent/atomic/atomic_fixnum.rb, line 40 def initialize(initial = 0) super() synchronize { ns_initialize(initial) } end
@!macro [attach] atomic_fixnum_method_compare_and_set
Atomically sets the value to the given updated value if the current value == the expected value. @param [Fixnum] expect the expected value @param [Fixnum] update the new value @return [Fixnum] true if the value was updated else false
# File lib/concurrent/atomic/atomic_fixnum.rb, line 98 def compare_and_set(expect, update) synchronize do if @value == expect @value = update true else false end end end
@!macro [attach] atomic_fixnum_method_decrement
Decreases the current value by 1. @return [Fixnum] the current value after decrementation
# File lib/concurrent/atomic/atomic_fixnum.rb, line 83 def decrement synchronize { ns_set(@value -1) } end
@!macro [attach] atomic_fixnum_method_increment
Increases the current value by 1. @return [Fixnum] the current value after incrementation
# File lib/concurrent/atomic/atomic_fixnum.rb, line 72 def increment synchronize { ns_set(@value + 1) } end
@!macro [attach] atomic_fixnum_method_value_get
Retrieves the current `Fixnum` value. @return [Fixnum] the current value
# File lib/concurrent/atomic/atomic_fixnum.rb, line 50 def value synchronize { @value } end
@!macro [attach] atomic_fixnum_method_value_set
Explicitly sets the value. @param [Fixnum] value the new value to be set @return [Fixnum] the current value @raise [ArgumentError] if the new value is not a `Fixnum`
# File lib/concurrent/atomic/atomic_fixnum.rb, line 63 def value=(value) synchronize { ns_set(value) } end
Generated with the Darkfish Rdoc Generator 2.