Class: Caliper::Stats::AtomicWrapper

Inherits:
Concurrent::Atomic
  • Object
show all
Defined in:
lib/caliper/stats/atomic_wrapper.rb

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ AtomicWrapper

Returns a new instance of AtomicWrapper.



27
28
29
# File 'lib/caliper/stats/atomic_wrapper.rb', line 27

def initialize(value)
	super.initialize(value)
end

Instance Method Details

#add_and_get(delta) ⇒ Object

Atomically adds the given value to the current value. Return the updated value



89
90
91
92
93
94
95
# File 'lib/caliper/stats/atomic_wrapper.rb', line 89

def add_and_get(delta)
	current = @value
	new_value = current + delta
	if (compare_and_set(current, new_value))
		new_value
	end
end

#decrement_and_getObject

Atomically decrements by one the current value. Return the updated value



79
80
81
82
83
84
85
# File 'lib/caliper/stats/atomic_wrapper.rb', line 79

def decrement_and_get()
	current = @value
	new_value = current - 1
	if (compare_and_set(current, new_value))
		new_value
	end
end

#get_and_add(delta) ⇒ Object

Atomically adds the given value to the current value Return the old value



59
60
61
62
63
64
65
# File 'lib/caliper/stats/atomic_wrapper.rb', line 59

def get_and_add(delta)
	current = @value
	new_value = current + delta
	if (compare_and_set(current, new_value))
		current
	end
end

#get_and_decrementObject

Atomically decrements by one and returns the old value.



49
50
51
52
53
54
55
# File 'lib/caliper/stats/atomic_wrapper.rb', line 49

def get_and_decrement()
	current = @value
	new_value = current - 1
	if (compare_and_set(current, new_value))
		current
	end
end

#get_and_incrementObject

Atomically increments by one and returns the old value.



40
41
42
43
44
45
46
# File 'lib/caliper/stats/atomic_wrapper.rb', line 40

def get_and_increment()
	current = @value
	new_value = current + 1
	if (compare_and_set(current, new_value))
		current
	end
end

#get_and_set(new_value) ⇒ Object

Atomically sets to the given value and returns the old value.



32
33
34
35
36
37
# File 'lib/caliper/stats/atomic_wrapper.rb', line 32

def get_and_set(new_value)
	current = @value
	if (compare_and_set(current, new_value))
		current
	end
end

#increment_and_getObject

Atomically increments by one the current value. Return the updated value



69
70
71
72
73
74
75
# File 'lib/caliper/stats/atomic_wrapper.rb', line 69

def increment_and_get()
	current = @value
	new_value = current + 1
	if (compare_and_set(current, new_value))
		new_value
	end
end

#to_stringObject

Returns the String representation of the current value.



98
99
100
# File 'lib/caliper/stats/atomic_wrapper.rb', line 98

def to_string()
	return @value.to_s
end