Simon Krajewski пре 6 година
родитељ
комит
9b171780e6

+ 19 - 9
std/hl/_std/sys/thread/Deque.hx

@@ -19,14 +19,23 @@
  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  * DEALINGS IN THE SOFTWARE.
  * DEALINGS IN THE SOFTWARE.
  */
  */
+
 package sys.thread;
 package sys.thread;
 
 
+#if doc_gen
+@:coreApi extern class Deque<T> {
+	public function new():Void;
+	public function add(i:T):Void;
+	public function push(i:T):Void;
+	public function pop(block:Bool):Null<T>;
+}
+#else
+
 /**
 /**
 	A message queue for multithread access.
 	A message queue for multithread access.
-*/
-@:hlNative("std","deque_")
+ */
+@:hlNative("std", "deque_")
 abstract Deque<T>(hl.Abstract<"hl_deque">) {
 abstract Deque<T>(hl.Abstract<"hl_deque">) {
-
 	/**
 	/**
 		Create a message queue for multithread access.
 		Create a message queue for multithread access.
 	**/
 	**/
@@ -37,22 +46,23 @@ abstract Deque<T>(hl.Abstract<"hl_deque">) {
 	/**
 	/**
 		Add a message at the end of the queue.
 		Add a message at the end of the queue.
 	**/
 	**/
-	public function add( i : T ) {
-	}
+	public function add(i:T) {}
 
 
 	/**
 	/**
 		Add a message at the head of the queue.
 		Add a message at the head of the queue.
 	**/
 	**/
-	public function push( i : T ) {
-	}
+	public function push(i:T) {}
 
 
 	/**
 	/**
 		Pop a message from the queue head. Either block until a message
 		Pop a message from the queue head. Either block until a message
 		is available or return immediately with `null`.
 		is available or return immediately with `null`.
 	**/
 	**/
-	public function pop( block : Bool ) : Null<T> {
+	public function pop(block:Bool):Null<T> {
 		return null;
 		return null;
 	}
 	}
 
 
-	static function alloc() { return null; }
+	static function alloc() {
+		return null;
+	}
 }
 }
+#end

+ 16 - 8
std/hl/_std/sys/thread/Mutex.hx

@@ -19,15 +19,25 @@
  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  * DEALINGS IN THE SOFTWARE.
  * DEALINGS IN THE SOFTWARE.
  */
  */
+
 package sys.thread;
 package sys.thread;
 
 
+#if doc_gen
+@:coreApi
+extern class Mutex {
+	public function new():Void;
+	public function acquire():Void;
+	public function tryAcquire():Bool;
+	public function release():Void;
+}
+#else
+
 /**
 /**
 	Creates a mutex, which can be used to acquire a temporary lock
 	Creates a mutex, which can be used to acquire a temporary lock
 	to access some ressource. The main difference with a lock is
 	to access some ressource. The main difference with a lock is
 	that a mutex must always be released by the owner thread.
 	that a mutex must always be released by the owner thread.
 **/
 **/
 abstract Mutex(hl.Abstract<"hl_mutex">) {
 abstract Mutex(hl.Abstract<"hl_mutex">) {
-
 	/**
 	/**
 		Creates a mutex.
 		Creates a mutex.
 	**/
 	**/
@@ -40,14 +50,13 @@ abstract Mutex(hl.Abstract<"hl_mutex">) {
 		The same thread can acquire several times the same mutex but
 		The same thread can acquire several times the same mutex but
 		must release it as many times it has been acquired.
 		must release it as many times it has been acquired.
 	**/
 	**/
-	@:hlNative("std","mutex_acquire") public function acquire() {
-	}
+	@:hlNative("std", "mutex_acquire") public function acquire() {}
 
 
 	/**
 	/**
 		Try to acquire the mutex, returns true if acquire or false
 		Try to acquire the mutex, returns true if acquire or false
 		if it's already locked by another thread.
 		if it's already locked by another thread.
 	**/
 	**/
-	@:hlNative("std","mutex_try_acquire") public function tryAcquire() : Bool {
+	@:hlNative("std", "mutex_try_acquire") public function tryAcquire():Bool {
 		return false;
 		return false;
 	}
 	}
 
 
@@ -56,11 +65,10 @@ abstract Mutex(hl.Abstract<"hl_mutex">) {
 		The behavior is undefined if the current thread does not own
 		The behavior is undefined if the current thread does not own
 		the mutex.
 		the mutex.
 	**/
 	**/
-	@:hlNative("std","mutex_release") public function release() {
-	}
+	@:hlNative("std", "mutex_release") public function release() {}
 
 
-	@:hlNative("std","mutex_alloc") public static function alloc( b : Bool ) {
+	@:hlNative("std", "mutex_alloc") public static function alloc(b:Bool) {
 		return null;
 		return null;
 	}
 	}
-
 }
 }
+#end

+ 26 - 16
std/hl/_std/sys/thread/Thread.hx

@@ -19,50 +19,60 @@
  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  * DEALINGS IN THE SOFTWARE.
  * DEALINGS IN THE SOFTWARE.
  */
  */
+
 package sys.thread;
 package sys.thread;
 
 
+#if doc_gen
+@:coreApi
+extern class Thread {
+	public function sendMessage(msg:Dynamic):Void;
+	public static function current():Thread;
+	public static function create(callb:Void->Void):Thread;
+	public static function readMessage(block:Bool):Dynamic;
+}
+#else
 typedef ThreadHandle = hl.Abstract<"hl_thread">;
 typedef ThreadHandle = hl.Abstract<"hl_thread">;
 
 
 abstract Thread(ThreadHandle) {
 abstract Thread(ThreadHandle) {
-
-	public function sendMessage( msg : Dynamic ) {
+	public function sendMessage(msg:Dynamic) {
 		getQueue(this).add(msg);
 		getQueue(this).add(msg);
 	}
 	}
 
 
-	public static function readMessage( block = true ) : Dynamic {
+	public static function readMessage(block = true):Dynamic {
 		return getQueue(cast current()).pop(block);
 		return getQueue(cast current()).pop(block);
 	}
 	}
 
 
-	static var queue_mutex : Mutex = null;
-	static var threads_queues : Array<{ t : ThreadHandle, q : Deque<Dynamic> }> = null;
-	static function getQueue( t : ThreadHandle ) {
-		if( queue_mutex == null ) {
+	static var queue_mutex:Mutex = null;
+	static var threads_queues:Array<{t:ThreadHandle, q:Deque<Dynamic>}> = null;
+
+	static function getQueue(t:ThreadHandle) {
+		if (queue_mutex == null) {
 			queue_mutex = new Mutex();
 			queue_mutex = new Mutex();
 			threads_queues = [];
 			threads_queues = [];
 		}
 		}
 		queue_mutex.acquire();
 		queue_mutex.acquire();
 		var q = null;
 		var q = null;
-		for( tq in threads_queues )
-			if( tq.t == t ) {
+		for (tq in threads_queues)
+			if (tq.t == t) {
 				q = tq.q;
 				q = tq.q;
 				break;
 				break;
 			}
 			}
-		if( q == null ) {
+		if (q == null) {
 			q = new Deque<Dynamic>();
 			q = new Deque<Dynamic>();
-			threads_queues.push({ t : t, q : q });
+			threads_queues.push({t: t, q: q});
 		}
 		}
 		queue_mutex.release();
 		queue_mutex.release();
 		return q;
 		return q;
 	}
 	}
 
 
-	@:hlNative("std","thread_create")
-	public static function create( callb : Void -> Void ) : Thread {
+	@:hlNative("std", "thread_create")
+	public static function create(callb:Void->Void):Thread {
 		return null;
 		return null;
 	}
 	}
 
 
-	@:hlNative("std","thread_current")
-	public static function current() : Thread {
+	@:hlNative("std", "thread_current")
+	public static function current():Thread {
 		return null;
 		return null;
 	}
 	}
-
 }
 }
+#end

+ 21 - 8
std/hl/_std/sys/thread/Tls.hx

@@ -19,16 +19,24 @@
  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  * DEALINGS IN THE SOFTWARE.
  * DEALINGS IN THE SOFTWARE.
  */
  */
+
 package sys.thread;
 package sys.thread;
 
 
+#if doc_gen
+@:coreApi
+extern class Tls<T> {
+	public var value(get, set):T;
+	public function new():Void;
+}
+#else
+
 /**
 /**
 	Creates thread local storage.
 	Creates thread local storage.
 	Warning : ATM Tls does not protect the value from being GC'ed. Keep the value reachable to avoid crashes.
 	Warning : ATM Tls does not protect the value from being GC'ed. Keep the value reachable to avoid crashes.
-*/
+ */
 @:hlNative("std")
 @:hlNative("std")
 abstract Tls<T>(hl.Abstract<"hl_tls">) {
 abstract Tls<T>(hl.Abstract<"hl_tls">) {
-
-	public var value(get,set) : T;
+	public var value(get, set):T;
 
 
 	/**
 	/**
 		Creates thread local storage. This is placeholder that can store
 		Creates thread local storage. This is placeholder that can store
@@ -43,19 +51,24 @@ abstract Tls<T>(hl.Abstract<"hl_tls">) {
 	/**
 	/**
 		Returns the value set by tls_set for the local thread.
 		Returns the value set by tls_set for the local thread.
 	**/
 	**/
-	function get_value() : T {
+	function get_value():T {
 		return tls_get(this);
 		return tls_get(this);
 	}
 	}
 
 
 	/**
 	/**
 		Set the value of the TLS for the local thread.
 		Set the value of the TLS for the local thread.
 	**/
 	**/
-	function set_value( v : T ) {
+	function set_value(v:T) {
 		tls_set(this, v);
 		tls_set(this, v);
 		return v;
 		return v;
 	}
 	}
 
 
-	static function tls_alloc( gcValue : Bool ) return null;
-	static function tls_get(t) : Dynamic return null;
-	static function tls_set(t,v:Dynamic) {}
+	static function tls_alloc(gcValue:Bool)
+		return null;
+
+	static function tls_get(t):Dynamic
+		return null;
+
+	static function tls_set(t, v:Dynamic) {}
 }
 }
+#end