Details
-
Bug
-
Status: Resolved
-
Major
-
Resolution: Fixed
-
3.4.0
-
Reviewed
Description
The current implementation converts the value from int to float, causing the compareAndSet method to get stuck.
private final boolean compareAndSet(float expect, float update) { return value.compareAndSet(Float.floatToIntBits(expect), Float.floatToIntBits(update)); } private void incr(float delta) { while (true) { float current = value.get(); float next = current + delta; if (compareAndSet(current, next)) { setChanged(); return; } } }
Perhaps it could be:
private void incr(float delta) { while (true) { float current = Float.intBitsToFloat(value.get()); float next = current + delta; if (compareAndSet(current, next)) { setChanged(); return; } } }
The unit test looks like this
MutableGaugeFloat mgf = new MutableGaugeFloat(Context,3.2f);
assertEquals(3.2f, mgf.value(), 0.0);
mgf.incr();
assertEquals(4.2f, mgf.value(), 0.0);
Attachments
Issue Links
- links to