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