1
2
3
4
5
6
7
8
9
10
11
12
13
14 package org.eclipse.jetty.util;
15
16 import java.util.concurrent.atomic.AtomicInteger;
17 import java.util.concurrent.atomic.AtomicLong;
18
19 public class Atomics
20 {
21 private Atomics()
22 {
23 }
24
25 public static void updateMin(AtomicLong currentMin, long newValue)
26 {
27 long oldValue = currentMin.get();
28 while (newValue < oldValue)
29 {
30 if (currentMin.compareAndSet(oldValue, newValue))
31 break;
32 oldValue = currentMin.get();
33 }
34 }
35
36 public static void updateMax(AtomicLong currentMax, long newValue)
37 {
38 long oldValue = currentMax.get();
39 while (newValue > oldValue)
40 {
41 if (currentMax.compareAndSet(oldValue, newValue))
42 break;
43 oldValue = currentMax.get();
44 }
45 }
46
47 public static void updateMin(AtomicInteger currentMin, int newValue)
48 {
49 int oldValue = currentMin.get();
50 while (newValue < oldValue)
51 {
52 if (currentMin.compareAndSet(oldValue, newValue))
53 break;
54 oldValue = currentMin.get();
55 }
56 }
57
58 public static void updateMax(AtomicInteger currentMax, int newValue)
59 {
60 int oldValue = currentMax.get();
61 while (newValue > oldValue)
62 {
63 if (currentMax.compareAndSet(oldValue, newValue))
64 break;
65 oldValue = currentMax.get();
66 }
67 }
68 }