Skip to content

Commit 2b8e207

Browse files
pepijndevosstuarthalloway
authored andcommitted
atom interface
Signed-off-by: Stuart Halloway <stu@cognitect.com>
1 parent 8765800 commit 2b8e207

File tree

3 files changed

+34
-7
lines changed

3 files changed

+34
-7
lines changed

src/clj/clojure/core.clj

+6-6
Original file line numberDiff line numberDiff line change
@@ -2231,25 +2231,25 @@
22312231
the value that was swapped in."
22322232
{:added "1.0"
22332233
:static true}
2234-
([^clojure.lang.Atom atom f] (.swap atom f))
2235-
([^clojure.lang.Atom atom f x] (.swap atom f x))
2236-
([^clojure.lang.Atom atom f x y] (.swap atom f x y))
2237-
([^clojure.lang.Atom atom f x y & args] (.swap atom f x y args)))
2234+
([^clojure.lang.IAtom atom f] (.swap atom f))
2235+
([^clojure.lang.IAtom atom f x] (.swap atom f x))
2236+
([^clojure.lang.IAtom atom f x y] (.swap atom f x y))
2237+
([^clojure.lang.IAtom atom f x y & args] (.swap atom f x y args)))
22382238

22392239
(defn compare-and-set!
22402240
"Atomically sets the value of atom to newval if and only if the
22412241
current value of the atom is identical to oldval. Returns true if
22422242
set happened, else false"
22432243
{:added "1.0"
22442244
:static true}
2245-
[^clojure.lang.Atom atom oldval newval] (.compareAndSet atom oldval newval))
2245+
[^clojure.lang.IAtom atom oldval newval] (.compareAndSet atom oldval newval))
22462246

22472247
(defn reset!
22482248
"Sets the value of atom to newval without regard for the
22492249
current value. Returns newval."
22502250
{:added "1.0"
22512251
:static true}
2252-
[^clojure.lang.Atom atom newval] (.reset atom newval))
2252+
[^clojure.lang.IAtom atom newval] (.reset atom newval))
22532253

22542254
(defn set-validator!
22552255
"Sets the validator-fn for a var/ref/agent/atom. validator-fn must be nil or a

src/jvm/clojure/lang/Atom.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import java.util.concurrent.atomic.AtomicReference;
1616

17-
final public class Atom extends ARef{
17+
final public class Atom extends ARef implements IAtom{
1818
final AtomicReference state;
1919

2020
public Atom(Object state){

src/jvm/clojure/lang/IAtom.java

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* Copyright (c) Rich Hickey. All rights reserved.
3+
* The use and distribution terms for this software are covered by the
4+
* Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
5+
* which can be found in the file epl-v10.html at the root of this distribution.
6+
* By using this software in any fashion, you are agreeing to be bound by
7+
* the terms of this license.
8+
* You must not remove this notice, or any other, from this software.
9+
**/
10+
11+
/* rich Aug 2, 2009 */
12+
13+
package clojure.lang;
14+
15+
public interface IAtom{
16+
Object swap(IFn f);
17+
18+
Object swap(IFn f, Object arg);
19+
20+
Object swap(IFn f, Object arg1, Object arg2);
21+
22+
Object swap(IFn f, Object x, Object y, ISeq args);
23+
24+
boolean compareAndSet(Object oldv, Object newv);
25+
26+
Object reset(Object newval);
27+
}

0 commit comments

Comments
 (0)