changeset 582:31926755689e

add Thread.synchronized
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 31 Jul 2015 06:20:17 -0600
parents 5d4652d78ce0
children 1368ca798ccc
files core/src/luan/modules/Thread.luan core/src/luan/modules/ThreadLuan.java core/src/luan/modules/Utils.java
diffstat 3 files changed, 18 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
diff -r 5d4652d78ce0 -r 31926755689e core/src/luan/modules/Thread.luan
--- a/core/src/luan/modules/Thread.luan	Thu Jul 30 20:56:53 2015 -0600
+++ b/core/src/luan/modules/Thread.luan	Fri Jul 31 06:20:17 2015 -0600
@@ -4,5 +4,6 @@
 local M = {}
 
 M.fork = ThreadLuan.fork
+M.synchronized = ThreadLuan.synchronized_
 
 return M
diff -r 5d4652d78ce0 -r 31926755689e core/src/luan/modules/ThreadLuan.java
--- a/core/src/luan/modules/ThreadLuan.java	Thu Jul 30 20:56:53 2015 -0600
+++ b/core/src/luan/modules/ThreadLuan.java	Fri Jul 31 06:20:17 2015 -0600
@@ -26,4 +26,16 @@
 			}
 		}});
 	}
+
+	public static LuanFunction synchronized_(final LuanState luan,final LuanFunction fn) throws LuanException {
+		Utils.checkNotNull(luan,fn);
+		return new LuanFunction() {
+			@Override public Object call(LuanState ingored,Object[] args) throws LuanException {
+				synchronized(luan) {
+					return fn.call(luan,args);
+				}
+			}
+		};
+	}
+
 }
diff -r 5d4652d78ce0 -r 31926755689e core/src/luan/modules/Utils.java
--- a/core/src/luan/modules/Utils.java	Thu Jul 30 20:56:53 2015 -0600
+++ b/core/src/luan/modules/Utils.java	Fri Jul 31 06:20:17 2015 -0600
@@ -11,6 +11,7 @@
 import luan.LuanState;
 import luan.LuanException;
 import luan.LuanTable;
+import luan.LuanFunction;
 
 
 public final class Utils {
@@ -39,6 +40,10 @@
 		checkNotNull(luan,n,"number");
 	}
 
+	public static void checkNotNull(LuanState luan,LuanFunction fn) throws LuanException {
+		checkNotNull(luan,fn,"function");
+	}
+
 	public static String readAll(Reader in)
 		throws IOException
 	{