comparison src/luan/modules/ThreadLuan.java @ 1381:8d7a39ca2c0c

add Rpc in_backup_read_lock
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 28 Jul 2019 20:15:38 -0600
parents 431d5bec3ca4
children eb8b35dccd99
comparison
equal deleted inserted replaced
1380:04482e2a6ca3 1381:8d7a39ca2c0c
236 } 236 }
237 237
238 238
239 public static final ReadWriteLock backupLock = new ReentrantReadWriteLock(); 239 public static final ReadWriteLock backupLock = new ReentrantReadWriteLock();
240 240
241 public static Object runInLock(Lock lock,LuanFunction fn,Object... args) 241 public static void lock(Lock lock)
242 throws LuanException, InterruptedException 242 throws LuanException, InterruptedException
243 { 243 {
244 if( !lock.tryLock(10,TimeUnit.MINUTES) ) 244 if( !lock.tryLock(10,TimeUnit.MINUTES) )
245 throw new LuanException("failed to acquire lock"); 245 throw new LuanException("failed to acquire lock");
246 }
247
248 public static Object runInLock(Lock lock,LuanFunction fn,Object... args)
249 throws LuanException, InterruptedException
250 {
251 lock(lock);
246 try { 252 try {
247 return fn.call(args); 253 return fn.call(args);
248 } finally { 254 } finally {
249 lock.unlock(); 255 lock.unlock();
250 } 256 }