46459
|
1 |
/*
|
|
2 |
* Copyright (c) 2015, 2015, Oracle and/or its affiliates. All rights reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation.
|
|
8 |
*
|
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
13 |
* accompanied this code).
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License version
|
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 |
*
|
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
20 |
* or visit www.oracle.com if you need additional information or have any
|
|
21 |
* questions.
|
|
22 |
*/
|
|
23 |
package org.graalvm.api.word;
|
|
24 |
|
|
25 |
/**
|
|
26 |
* A {@link Unsigned} value that may be updated atomically. See the
|
|
27 |
* {@link java.util.concurrent.atomic} package specification for description of the properties of
|
|
28 |
* atomic variables.
|
|
29 |
*/
|
|
30 |
public class AtomicUnsigned extends AtomicWord<Unsigned> {
|
|
31 |
|
|
32 |
/**
|
|
33 |
* Atomically adds the given value to the current value.
|
|
34 |
*
|
|
35 |
* @param delta the value to add
|
|
36 |
* @return the previous value
|
|
37 |
*/
|
|
38 |
public final Unsigned getAndAdd(Unsigned delta) {
|
|
39 |
return WordFactory.unsigned(value.getAndAdd(delta.rawValue()));
|
|
40 |
}
|
|
41 |
|
|
42 |
/**
|
|
43 |
* Atomically adds the given value to the current value.
|
|
44 |
*
|
|
45 |
* @param delta the value to add
|
|
46 |
* @return the updated value
|
|
47 |
*/
|
|
48 |
public final Unsigned addAndGet(Unsigned delta) {
|
|
49 |
return WordFactory.unsigned(value.addAndGet(delta.rawValue()));
|
|
50 |
}
|
|
51 |
|
|
52 |
/**
|
|
53 |
* Atomically subtracts the given value from the current value.
|
|
54 |
*
|
|
55 |
* @param delta the value to add
|
|
56 |
* @return the previous value
|
|
57 |
*/
|
|
58 |
public final Unsigned getAndSubtract(Unsigned delta) {
|
|
59 |
return WordFactory.unsigned(value.getAndAdd(-delta.rawValue()));
|
|
60 |
}
|
|
61 |
|
|
62 |
/**
|
|
63 |
* Atomically subtracts the given value from the current value.
|
|
64 |
*
|
|
65 |
* @param delta the value to add
|
|
66 |
* @return the updated value
|
|
67 |
*/
|
|
68 |
public final Unsigned subtractAndGet(Unsigned delta) {
|
|
69 |
return WordFactory.unsigned(value.addAndGet(-delta.rawValue()));
|
|
70 |
}
|
|
71 |
}
|