Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
*.n
/bin/*.py
/bin/*.js
/bin/php
/bin/cpp
Expand Down
9 changes: 8 additions & 1 deletion src/tink/concurrent/Mutex.hx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,14 @@ abstract Mutex(Impl) {
Monitor.Exit(this);
}
}
#else
#elseif python
private abstract Impl(python.lib.threading.RLock) {
public inline function new() this = new python.lib.threading.RLock();
public inline function acquire() this.acquire();
public inline function tryAcquire():Bool return this.acquire(false);
public inline function release() try this.release() catch(e:Dynamic) {}
}
#else
private typedef Impl = Thread;//For consistent error messages
#end
#else
Expand Down
14 changes: 14 additions & 0 deletions src/tink/concurrent/Thread.hx
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,20 @@ abstract Thread(Impl) from Impl {
return untyped __global__.__hxcpp_thread_current();
}

#elseif python

private abstract Impl(python.lib.threading.Thread) from python.lib.threading.Thread {

static public inline function create(f:Void->Void):Impl {
var ret = new python.lib.threading.Thread({group: null, target: f});
ret.start();
return ret;
}

static public inline function getCurrent():Impl
return python.lib.Threading.current_thread();
}

#else

#error concurrency not supported on current platform
Expand Down
13 changes: 13 additions & 0 deletions src/tink/concurrent/Tls.hx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,19 @@ abstract Tls<T>(Impl<T>) from Impl<T> {
}
#elseif cs
private typedef Impl<T> = Naive<T>;//TODO: use .NET 4.5's ThreadLocal when possible
#elseif python
private abstract Impl<T>(Dynamic) {
public var value(get,set):T;

inline function get_value():T
return this.value;

inline private function set_value(v:T):T
return this.value = v;

public inline function new()
this = python.lib.Threading.local();
}
#else
private typedef Impl<T> = Naive<T>;
#end
Expand Down
2 changes: 1 addition & 1 deletion tests/TestMutex.hx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class TestMutex extends TestCase {

function testSynchronized() {
var threads = 100,
count = #if cpp 1000 #else 10000 #end,//cpps mutexes are abysmally slow
count = #if (cpp || python) 1000 #else 10000 #end,//cpps/python mutexes are abysmally slow
counter = 0;
for (i in 0...threads)
new Thread(function () {
Expand Down
1 change: 1 addition & 0 deletions tests/build-python.hxml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
tests/common.hxml
-D concurrent
-python bin/RunTests.py