Skip to content

Commit

Permalink
do ... while loop for Java.
Browse files Browse the repository at this point in the history
Add some `inline`, and remove some unneeded `extern`.
  • Loading branch information
Apprentice-Alchemist committed Mar 26, 2022
1 parent f1d4817 commit 1c550d7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
12 changes: 6 additions & 6 deletions std/java/_std/haxe/atomic/AtomicInt.hx
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ package haxe.atomic;
import java.util.concurrent.atomic.AtomicInteger;

abstract AtomicInt(AtomicInteger) {
public function new(value:Int) {
public inline function new(value:Int) {
this = new AtomicInteger(value);
}

private inline function cas_loop(value:Int, op:(a:Int, b:Int) -> Int):Int {
var val = this.get();
var val;

while (!this.compareAndSet(val, op(val, value))) {
do {
val = this.get();
}
} while (!this.compareAndSet(val, op(val, value)));

return val;
}
Expand All @@ -39,7 +39,7 @@ abstract AtomicInt(AtomicInteger) {

public inline function compareExchange(expected:Int, replacement:Int):Int {
final original = this.get();
if (this.compareAndSet(expected, replacement)) {} // TODO: this is probably subject to race conditions and stuff
if (this.compareAndSet(expected, replacement)) {} // TODO: this is probably subject to race conditions
return original;
}

Expand All @@ -51,7 +51,7 @@ abstract AtomicInt(AtomicInteger) {
return this.get();
}

public extern inline function store(value:Int):Int {
public inline function store(value:Int):Int {
this.set(value);
return value;
}
Expand Down
6 changes: 3 additions & 3 deletions std/java/_std/haxe/atomic/AtomicObject.hx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ package haxe.atomic;
import java.util.concurrent.atomic.AtomicReference;

abstract AtomicObject<T:{}>(AtomicReference<T>) {
public function new(value:T) {
public inline function new(value:T) {
this = new AtomicReference(value);
}

public inline function compareExchange(expected:T, replacement:T):T {
final original = this.get();
if (this.compareAndSet(expected, replacement)) {} // TODO: this is probably subject to race conditions and stuff
if (this.compareAndSet(expected, replacement)) {} // TODO: this is probably subject to race conditions
return original;
}

Expand All @@ -21,7 +21,7 @@ abstract AtomicObject<T:{}>(AtomicReference<T>) {
return this.get();
}

public extern inline function store(value:T):T {
public inline function store(value:T):T {
this.set(value);
return value;
}
Expand Down
4 changes: 2 additions & 2 deletions std/js/_std/haxe/atomic/AtomicInt.hx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package haxe.atomic;

import js.lib.Atomics;

extern abstract AtomicInt(js.lib.Int32Array) to js.lib.Int32Array {
abstract AtomicInt(js.lib.Int32Array) to js.lib.Int32Array {
public inline function new(value:Int) {
this = new js.lib.Int32Array(new js.lib.SharedArrayBuffer(4));
this = new js.lib.Int32Array(new js.lib.SharedArrayBuffer(js.lib.Int32Array.BYTES_PER_ELEMENT));
this[0] = value;
}

Expand Down

0 comments on commit 1c550d7

Please sign in to comment.