Zeta 2 недель назад
Родитель
Сommit
743628773a

+ 53 - 0
std/cpp/_std/haxe/atomic/AtomicObject.hx

@@ -0,0 +1,53 @@
+package haxe.atomic;
+
+#if doc_gen
+@:coreType
+abstract AtomicObject<T:{}> {
+	public function new(value:T):Void;
+
+	public function compareExchange(expected:T, replacement:T):T;
+
+	public function exchange(value:T):T;
+
+	public function load():T;
+
+	public function store(value:T):T;
+}
+#else
+#if cppia
+extern
+#end
+abstract AtomicObject<T: {}>(Dynamic) {
+	#if cppia
+	public function new(value:T):Void;
+
+	public function compareExchange(expected:T, replacement:T):T;
+
+	public function exchange(value:T):T;
+
+	public function load():T;
+
+	public function store(value:T):T;
+	#else
+	public #if !scriptable inline #end function new(value:T) {
+		this = untyped __global__.__hxcpp_atomic_object_create(value);
+	}
+
+	public #if !scriptable inline #end function compareExchange(expected:T, replacement:T):T {
+		return untyped __global__.__hxcpp_atomic_object_compare_exchange(this, expected, replacement);
+	}
+
+	public #if !scriptable inline #end function exchange(value:T):T {
+		return untyped __global__.__hxcpp_atomic_object_exchange(this, value);
+	}
+
+	public #if !scriptable inline #end function load():T {
+		return untyped __global__.__hxcpp_atomic_object_load(this);
+	}
+
+	public #if !scriptable inline #end function store(value:T):T {
+		return untyped __global__.__hxcpp_atomic_object_store(this, value);
+	}
+	#end
+}
+#end

+ 2 - 1
std/cpp/cppia/HostClasses.hx

@@ -148,7 +148,8 @@ class HostClasses {
 		"List",
 		"Map",
 		"String",
-		"haxe.atomic.AtomicInt"
+		"haxe.atomic.AtomicInt",
+		"haxe.atomic.AtomicObject",
 	];
 
 	static function parseClassInfo(externs:Map<String, Bool>, filename:String) {

+ 3 - 3
std/haxe/atomic/AtomicObject.hx

@@ -4,13 +4,13 @@ package haxe.atomic;
 #error "This target does not support atomic operations."
 #end
 
-#if (js || cpp)
-#error "JavaScript and Hxcpp do not support AtomicObject"
+#if js
+#error "JavaScript does not support AtomicObject"
 #end
 
 /**
 	Atomic object. Use with care, this does not magically make it thread-safe to mutate objects.
-	Not supported on JavaScript or C++.
+	Not supported on JavaScript.
 **/
 @:coreType
 abstract AtomicObject<T:{}> {

+ 1 - 1
tests/unit/src/unitstd/haxe/atomic/AtomicObject.unit.hx

@@ -1,4 +1,4 @@
-#if (target.atomics && !(js || cpp))
+#if (target.atomics && !js)
 var a = new haxe.atomic.AtomicObject("Hey World!");
 
 a.load() == "Hey World!";