|
@@ -21,18 +21,21 @@
|
|
*/
|
|
*/
|
|
package neko.vm;
|
|
package neko.vm;
|
|
|
|
|
|
|
|
+/**
|
|
|
|
+ Creates a mutex, which can be used to acquire a temporary lock
|
|
|
|
+ to access some ressource. The main difference with a lock is
|
|
|
|
+ that a mutex must always be released by the owner thread.
|
|
|
|
+*/
|
|
class Mutex {
|
|
class Mutex {
|
|
var m : Dynamic;
|
|
var m : Dynamic;
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
- Creates a mutex, which can be used to acquire a temporary lock
|
|
|
|
- to access some ressource. The main difference with a lock is
|
|
|
|
- that a mutex must always be released by the owner thread.
|
|
|
|
|
|
+ Creates a mutex.
|
|
*/
|
|
*/
|
|
public function new() {
|
|
public function new() {
|
|
m = mutex_create();
|
|
m = mutex_create();
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
The current thread acquire the mutex or wait if not available.
|
|
The current thread acquire the mutex or wait if not available.
|
|
The same thread can acquire several times the same mutex but
|
|
The same thread can acquire several times the same mutex but
|
|
@@ -41,7 +44,7 @@ class Mutex {
|
|
public function acquire() {
|
|
public function acquire() {
|
|
mutex_acquire(m);
|
|
mutex_acquire(m);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
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.
|
|
@@ -49,7 +52,7 @@ class Mutex {
|
|
public function tryAcquire() : Bool {
|
|
public function tryAcquire() : Bool {
|
|
return mutex_try(m);
|
|
return mutex_try(m);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
Release a mutex that has been acquired by the current thread.
|
|
Release a mutex that has been acquired by the current thread.
|
|
The behavior is undefined if the current thread does not own
|
|
The behavior is undefined if the current thread does not own
|
|
@@ -58,7 +61,7 @@ class Mutex {
|
|
public function release() {
|
|
public function release() {
|
|
mutex_release(m);
|
|
mutex_release(m);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
static var mutex_create = neko.Lib.loadLazy("std","mutex_create",0);
|
|
static var mutex_create = neko.Lib.loadLazy("std","mutex_create",0);
|
|
static var mutex_release = neko.Lib.loadLazy("std","mutex_release",1);
|
|
static var mutex_release = neko.Lib.loadLazy("std","mutex_release",1);
|
|
static var mutex_acquire = neko.Lib.loadLazy("std","mutex_acquire",1);
|
|
static var mutex_acquire = neko.Lib.loadLazy("std","mutex_acquire",1);
|