Skip to content

Commit 7436287

Browse files
[cpp] implement AtomicObject (#12322)
1 parent c979d08 commit 7436287

File tree

4 files changed

+59
-5
lines changed

4 files changed

+59
-5
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package haxe.atomic;
2+
3+
#if doc_gen
4+
@:coreType
5+
abstract AtomicObject<T:{}> {
6+
public function new(value:T):Void;
7+
8+
public function compareExchange(expected:T, replacement:T):T;
9+
10+
public function exchange(value:T):T;
11+
12+
public function load():T;
13+
14+
public function store(value:T):T;
15+
}
16+
#else
17+
#if cppia
18+
extern
19+
#end
20+
abstract AtomicObject<T: {}>(Dynamic) {
21+
#if cppia
22+
public function new(value:T):Void;
23+
24+
public function compareExchange(expected:T, replacement:T):T;
25+
26+
public function exchange(value:T):T;
27+
28+
public function load():T;
29+
30+
public function store(value:T):T;
31+
#else
32+
public #if !scriptable inline #end function new(value:T) {
33+
this = untyped __global__.__hxcpp_atomic_object_create(value);
34+
}
35+
36+
public #if !scriptable inline #end function compareExchange(expected:T, replacement:T):T {
37+
return untyped __global__.__hxcpp_atomic_object_compare_exchange(this, expected, replacement);
38+
}
39+
40+
public #if !scriptable inline #end function exchange(value:T):T {
41+
return untyped __global__.__hxcpp_atomic_object_exchange(this, value);
42+
}
43+
44+
public #if !scriptable inline #end function load():T {
45+
return untyped __global__.__hxcpp_atomic_object_load(this);
46+
}
47+
48+
public #if !scriptable inline #end function store(value:T):T {
49+
return untyped __global__.__hxcpp_atomic_object_store(this, value);
50+
}
51+
#end
52+
}
53+
#end

std/cpp/cppia/HostClasses.hx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ class HostClasses {
148148
"List",
149149
"Map",
150150
"String",
151-
"haxe.atomic.AtomicInt"
151+
"haxe.atomic.AtomicInt",
152+
"haxe.atomic.AtomicObject",
152153
];
153154

154155
static function parseClassInfo(externs:Map<String, Bool>, filename:String) {

std/haxe/atomic/AtomicObject.hx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ package haxe.atomic;
44
#error "This target does not support atomic operations."
55
#end
66

7-
#if (js || cpp)
8-
#error "JavaScript and Hxcpp do not support AtomicObject"
7+
#if js
8+
#error "JavaScript does not support AtomicObject"
99
#end
1010

1111
/**
1212
Atomic object. Use with care, this does not magically make it thread-safe to mutate objects.
13-
Not supported on JavaScript or C++.
13+
Not supported on JavaScript.
1414
**/
1515
@:coreType
1616
abstract AtomicObject<T:{}> {

tests/unit/src/unitstd/haxe/atomic/AtomicObject.unit.hx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#if (target.atomics && !(js || cpp))
1+
#if (target.atomics && !js)
22
var a = new haxe.atomic.AtomicObject("Hey World!");
33

44
a.load() == "Hey World!";

0 commit comments

Comments
 (0)