changeset 1360:ee0f0e6c89a0

fix reset_luan
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 21 Apr 2019 02:32:41 -0600
parents 9721d4709bfb
children 9eba6bf0163b
files src/luan/modules/http/LuanHandler.java
diffstat 1 files changed, 16 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/src/luan/modules/http/LuanHandler.java	Fri Apr 19 00:58:18 2019 -0600
+++ b/src/luan/modules/http/LuanHandler.java	Sun Apr 21 02:32:41 2019 -0600
@@ -33,7 +33,7 @@
 public final class LuanHandler implements Handler, Luan.OnClose {
 	private final Luan luanInit;
 	private final Logger logger;
-	private final ReadWriteLock lock = new ReentrantReadWriteLock();
+	private final ReadWriteLock rwLock = new ReentrantReadWriteLock();
 	private final List<Reference<Closeable>> onClose = new ArrayList<Reference<Closeable>>();
 	private volatile Luan currentLuan;
 	private volatile boolean isDisabled = false;
@@ -100,7 +100,7 @@
 		Thread thread = Thread.currentThread();
 		String oldName = thread.getName();
 		thread.setName(request.headers.get("host")+request.path);
-		lock.readLock().lock();
+		rwLock.readLock().lock();
 		try {
 			return service(request,notFound);
 		} catch(LuanException e) {
@@ -109,7 +109,7 @@
 			String msg = "Internel Server Error\n\n" + err;
 			return Response.errorResponse( Status.INTERNAL_SERVER_ERROR, msg );
 		} finally {
-			lock.readLock().unlock();
+			rwLock.readLock().unlock();
 			thread.setName(oldName);
 		}
 	}
@@ -137,7 +137,7 @@
 	}
 
 	public Object call_rpc(String fnName,Object... args) throws LuanException {
-		lock.readLock().lock();
+		rwLock.readLock().lock();
 		try {
 			LuanFunction fn;
 			synchronized(luanInit) {
@@ -152,18 +152,20 @@
 			}
 			return fn.call(args);
 		} finally {
-			lock.readLock().unlock();
+			rwLock.readLock().unlock();
 		}
 	}
 
 	public void reset_luan() {
-		lock.writeLock().lock();
-		try {
-			close();
-			currentLuan = newLuan();
-		} finally {
-			lock.writeLock().unlock();
-		}
+		new Thread() {public void run(){
+			rwLock.writeLock().lock();
+			try {
+				close();
+				currentLuan = newLuan();
+			} finally {
+				rwLock.writeLock().unlock();
+			}
+		}}.start();
 	}
 
 	public void disable_luan() {
@@ -171,7 +173,7 @@
 	}
 
 	public Object runLuan(String sourceText,String sourceName) throws LuanException {
-		lock.readLock().lock();
+		rwLock.readLock().lock();
 		try {
 			Luan luan = currentLuan;
 			synchronized(luanInit) {
@@ -181,7 +183,7 @@
 				return fn.call();
 			}
 		} finally {
-			lock.readLock().unlock();
+			rwLock.readLock().unlock();
 		}
 	}