Skip to content

Commit

Permalink
- workaround for HL on Haxe 3.4 which is missing native thread support
Browse files Browse the repository at this point in the history
  • Loading branch information
sebthom committed Oct 9, 2018
1 parent f963b98 commit bc4d7d3
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ env:
- HAXE_TARGET=cpp
- HAXE_TARGET=cs
- HAXE_TARGET=flash
- HAXE_TARGET=hl
- HAXE_TARGET=lua
- HAXE_TARGET=neko
- HAXE_TARGET=node
Expand All @@ -30,6 +31,7 @@ matrix:
- haxe: development
- env: HAXE_TARGET=flash # https://github.com/travis-ci/travis-ci/issues/8481
- env: HAXE_TARGET=cs # C# fails because of https://github.com/HaxeFoundation/haxe/issues/6533
- env: HAXE_TARGET=hl
- os: osx
exclude:
- haxe: development
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

### Fixed
- class hx.concurrent.lock.RWLock not working on JS target
- workaround for HL on Haxe 3.4 which is missing native thread support


## [2.0.0] - 2018-09-20
Expand Down
10 changes: 5 additions & 5 deletions src/hx/concurrent/collection/Queue.hx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Queue<T> {

#if cpp
var _queue = new cpp.vm.Deque<T>();
#elseif hl
#elseif (hl && haxe_ver >= 4)
var _queue = new hl.vm.Deque<T>();
#elseif neko
var _queue = new neko.vm.Deque<T>();
Expand Down Expand Up @@ -56,7 +56,7 @@ class Queue<T> {
throw "[timeoutMS] must be >= -1";

if (timeoutMS == 0) {
#if (cpp||hl||neko)
#if (cpp||(hl && haxe_ver >= 4)||neko)
msg = _queue.pop(false);
#elseif java
msg = _queue.poll();
Expand All @@ -69,7 +69,7 @@ class Queue<T> {
#end
} else {
Threads.await(function() {
#if (cpp||hl||neko)
#if (cpp||(hl && haxe_ver >= 4)||neko)
msg = _queue.pop(false);
#elseif java
msg = _queue.poll();
Expand Down Expand Up @@ -104,7 +104,7 @@ class Queue<T> {
if (msg == null)
throw "[msg] must not be null";

#if (cpp||hl||neko)
#if (cpp||(hl && haxe_ver >= 4)||neko)
_queue.push(msg);
#elseif java
_queue.addFirst(msg);
Expand All @@ -127,7 +127,7 @@ class Queue<T> {
if (msg == null)
throw "[msg] must not be null";

#if (cpp||hl||neko)
#if (cpp||(hl && haxe_ver >= 4)||neko)
_queue.add(msg);
#elseif java
_queue.addLast(msg);
Expand Down
5 changes: 3 additions & 2 deletions src/hx/concurrent/internal/Macros.hx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package hx.concurrent.internal;

import haxe.macro.Compiler;
import haxe.macro.Context;

/**
* @author Sebastian Thomschke, Vegard IT GmbH
Expand All @@ -13,8 +14,8 @@ class Macros {

macro
public static function addDefines() {
var def = haxe.macro.Context.getDefines();
if(def.exists("cpp") || def.exists("cs") || def.exists("hl") || def.exists("java") || def.exists("neko") || def.exists("python")) {
var def = Context.getDefines();
if(def.exists("cpp") || def.exists("cs") || (def.exists("hl") && Std.parseFloat(def["haxe_ver"]) >= 4) || def.exists("java") || def.exists("neko") || def.exists("python")) {
trace("[INFO] Setting compiler define 'threads'.");
Compiler.define("threads");
} else {
Expand Down
8 changes: 4 additions & 4 deletions src/hx/concurrent/lock/RLock.hx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class RLock implements Acquirable {
// flash.concurrent.Mutex requries swf-version >= 11.4
// flash.concurrent.Condition requries swf-version >= 11.5
var _cond = new flash.concurrent.Condition(new flash.concurrent.Mutex());
#elseif hl
#elseif (hl && haxe_ver >= 4)
var _rlock = new hl.vm.Mutex();
#elseif java
var _rlock = new java.util.concurrent.locks.ReentrantLock();
Expand Down Expand Up @@ -115,7 +115,7 @@ class RLock implements Acquirable {
public function acquire():Void {
#if cs
cs.system.threading.Monitor.Enter(this);
#elseif (cpp||hl||neko||python)
#elseif (cpp||(hl && haxe_ver >= 4)||neko||python)
_rlock.acquire();
#elseif java
_rlock.lock();
Expand Down Expand Up @@ -157,7 +157,7 @@ class RLock implements Acquirable {
private function tryAcquireInternal(timeoutMS = 0):Bool {
#if cs
return cs.system.threading.Monitor.TryEnter(this, timeoutMS);
#elseif (cpp||hl||neko)
#elseif (cpp||(hl && haxe_ver >= 4)||neko)
return Threads.await(function() return _rlock.tryAcquire(), timeoutMS);
#elseif java
return _rlock.tryLock(timeoutMS, java.util.concurrent.TimeUnit.MILLISECONDS);
Expand Down Expand Up @@ -203,7 +203,7 @@ class RLock implements Acquirable {

#if cs
cs.system.threading.Monitor.Exit(this);
#elseif (cpp||hl||neko||python)
#elseif (cpp||(hl && haxe_ver >= 4)||neko||python)
_rlock.release();
#elseif java
_rlock.unlock();
Expand Down
2 changes: 1 addition & 1 deletion src/hx/concurrent/thread/Threads.hx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Threads {
#elseif flash
var worker = flash.system.Worker.current;
return worker == null ? "MainThread" : worker;
#elseif hl
#elseif (hl && haxe_ver >= 4)
return Std.string(hl.vm.Thread.current());
#elseif java
return java.vm.Thread.current();
Expand Down

0 comments on commit bc4d7d3

Please sign in to comment.