forked from LeenkxTeam/LNXSDK
Update
This commit is contained in:
@ -1,20 +1,26 @@
|
||||
package haxe;
|
||||
|
||||
import haxe.iterators.RestIterator;
|
||||
import haxe.iterators.RestKeyValueIterator;
|
||||
import cs.NativeArray;
|
||||
import cs.system.Array as CsArray;
|
||||
import haxe.iterators.RestIterator;
|
||||
import haxe.iterators.RestKeyValueIterator;
|
||||
|
||||
private typedef NativeRest<T> = #if erase_generics NativeArray<Dynamic> #else NativeArray<T> #end;
|
||||
|
||||
@:coreApi
|
||||
abstract Rest<T>(NativeRest<T>) {
|
||||
public var length(get,never):Int;
|
||||
public var length(get, never):Int;
|
||||
|
||||
inline function get_length():Int
|
||||
return this.Length;
|
||||
|
||||
@:from static public inline function of<T>(array:Array<T>):Rest<T>
|
||||
#if erase_generics
|
||||
// This is wrong but so is everything else in my life
|
||||
return new Rest(@:privateAccess array.__a);
|
||||
#else
|
||||
return new Rest(cs.Lib.nativeArray(array, false));
|
||||
#end
|
||||
|
||||
inline function new(a:NativeRest<T>):Void
|
||||
this = a;
|
||||
@ -51,4 +57,4 @@ abstract Rest<T>(NativeRest<T>) {
|
||||
public function toString():String {
|
||||
return toArray().toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
61
Kha/Tools/windows_x64/std/cs/_std/haxe/atomic/AtomicInt.hx
Normal file
61
Kha/Tools/windows_x64/std/cs/_std/haxe/atomic/AtomicInt.hx
Normal file
@ -0,0 +1,61 @@
|
||||
package haxe.atomic;
|
||||
|
||||
private class IntWrapper {
|
||||
public var value:Int;
|
||||
|
||||
public function new(value:Int) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
abstract AtomicInt(IntWrapper) {
|
||||
public inline function new(value:Int) {
|
||||
this = new IntWrapper(value);
|
||||
}
|
||||
|
||||
private inline function cas_loop(value:Int, op:(a:Int, b:Int) -> Int):Int {
|
||||
var oldValue;
|
||||
var newValue;
|
||||
do {
|
||||
oldValue = load();
|
||||
newValue = op(oldValue, value);
|
||||
} while(compareExchange(oldValue, newValue) != oldValue);
|
||||
return oldValue;
|
||||
}
|
||||
|
||||
public inline function add(b:Int):Int {
|
||||
return cas_loop(b, (a, b) -> a + b);
|
||||
}
|
||||
|
||||
public inline function sub(b:Int):Int {
|
||||
return cas_loop(b, (a, b) -> a - b);
|
||||
}
|
||||
|
||||
public inline function and(b:Int):Int {
|
||||
return cas_loop(b, (a, b) -> cast a & b);
|
||||
}
|
||||
|
||||
public inline function or(b:Int):Int {
|
||||
return cas_loop(b, (a, b) -> cast a | b);
|
||||
}
|
||||
|
||||
public inline function xor(b:Int):Int {
|
||||
return cas_loop(b, (a, b) -> cast a ^ b);
|
||||
}
|
||||
|
||||
public inline function compareExchange(expected:Int, replacement:Int):Int {
|
||||
return cs.Syntax.code("System.Threading.Interlocked.CompareExchange(ref ({0}).value, {1}, {2})", this, replacement, expected);
|
||||
}
|
||||
|
||||
public inline function exchange(value:Int):Int {
|
||||
return cs.Syntax.code("System.Threading.Interlocked.Exchange(ref ({0}).value, {1})", this, value);
|
||||
}
|
||||
|
||||
public inline function load():Int {
|
||||
return this.value; // according to the CLI spec reads and writes are atomic
|
||||
}
|
||||
|
||||
public inline function store(value:Int):Int {
|
||||
return this.value = value; // according to the CLI spec reads and writes are atomic
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,33 @@
|
||||
package haxe.atomic;
|
||||
|
||||
import cs.system.threading.Interlocked.*;
|
||||
|
||||
private class ObjectWrapper<T:{}> {
|
||||
public var value:T;
|
||||
|
||||
public function new(value:T) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
extern abstract AtomicObject<T:{}>(ObjectWrapper<T>) {
|
||||
public inline function new(value:T) {
|
||||
this = new ObjectWrapper(value);
|
||||
}
|
||||
|
||||
public inline function compareExchange(expected:T, replacement:T):T {
|
||||
return cs.Syntax.code("System.Threading.Interlocked.CompareExchange(ref ({0}).value, {1}, {2})", this, replacement, expected);
|
||||
}
|
||||
|
||||
public inline function exchange(value:T):T {
|
||||
return cs.Syntax.code("System.Threading.Interlocked.Exchange(ref ({0}).value, {1})", this, value);
|
||||
}
|
||||
|
||||
public inline function load():T {
|
||||
return this.value; // according to the CLI spec reads and writes are atomic
|
||||
}
|
||||
|
||||
public inline function store(value:T):T {
|
||||
return this.value = value; // according to the CLI spec reads and writes are atomic
|
||||
}
|
||||
}
|
||||
@ -364,7 +364,7 @@ import cs.NativeArray;
|
||||
|
||||
public function toString():String {
|
||||
var s = new StringBuf();
|
||||
s.add("{");
|
||||
s.add("[");
|
||||
var it = keys();
|
||||
for (i in it) {
|
||||
s.add(i);
|
||||
@ -373,7 +373,7 @@ import cs.NativeArray;
|
||||
if (it.hasNext())
|
||||
s.add(", ");
|
||||
}
|
||||
s.add("}");
|
||||
s.add("]");
|
||||
return s.toString();
|
||||
}
|
||||
|
||||
|
||||
@ -378,7 +378,7 @@ import cs.NativeArray;
|
||||
|
||||
public function toString():String {
|
||||
var s = new StringBuf();
|
||||
s.add("{");
|
||||
s.add("[");
|
||||
var it = keys();
|
||||
for (i in it) {
|
||||
s.add(Std.string(i));
|
||||
@ -387,7 +387,7 @@ import cs.NativeArray;
|
||||
if (it.hasNext())
|
||||
s.add(", ");
|
||||
}
|
||||
s.add("}");
|
||||
s.add("]");
|
||||
return s.toString();
|
||||
}
|
||||
|
||||
|
||||
@ -377,7 +377,7 @@ import cs.NativeArray;
|
||||
|
||||
public function toString():String {
|
||||
var s = new StringBuf();
|
||||
s.add("{");
|
||||
s.add("[");
|
||||
var it = keys();
|
||||
for (i in it) {
|
||||
s.add(i);
|
||||
@ -386,7 +386,7 @@ import cs.NativeArray;
|
||||
if (it.hasNext())
|
||||
s.add(", ");
|
||||
}
|
||||
s.add("}");
|
||||
s.add("]");
|
||||
return s.toString();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user