diff lucene/src/luan/modules/lucene/LuceneIndex.java @ 756:9092e52f94eb

better synchronization for lucene restore
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 18 Jul 2016 05:14:19 -0600
parents 1a101ac9ea46
children
line wrap: on
line diff
--- a/lucene/src/luan/modules/lucene/LuceneIndex.java	Mon Jul 18 05:01:38 2016 -0600
+++ b/lucene/src/luan/modules/lucene/LuceneIndex.java	Mon Jul 18 05:14:19 2016 -0600
@@ -237,6 +237,20 @@
 		}
 	}
 
+	public void run_in_lock(LuanState luan,LuanFunction fn) throws IOException, LuanException {
+		if( writeLock.isHeldByCurrentThread() )
+			throw new RuntimeException();
+		writeLock.lock();
+		try {
+			synchronized(this) {
+				fn.call(luan);
+			}
+		} finally {
+			wrote();
+			writeLock.unlock();
+		}
+	}
+
 
 	private long id;
 	private long idLim;