| 465 | } |
| 466 | |
| 467 | Object doCommute(Ref ref, IFn fn, ISeq args) { |
| 468 | if(!info.running()) |
| 469 | throw retryex; |
| 470 | if(!vals.containsKey(ref)) |
| 471 | { |
| 472 | Object val = null; |
| 473 | try |
| 474 | { |
| 475 | ref.lock.readLock().lock(); |
| 476 | val = ref.tvals == null ? null : ref.tvals.val; |
| 477 | } |
| 478 | finally |
| 479 | { |
| 480 | ref.lock.readLock().unlock(); |
| 481 | } |
| 482 | vals.put(ref, val); |
| 483 | } |
| 484 | ArrayList<CFn> fns = commutes.get(ref); |
| 485 | if(fns == null) |
| 486 | commutes.put(ref, fns = new ArrayList<CFn>()); |
| 487 | fns.add(new CFn(fn, args)); |
| 488 | Object ret = fn.applyTo(RT.cons(vals.get(ref), args)); |
| 489 | vals.put(ref, ret); |
| 490 | return ret; |
| 491 | } |
| 492 | |
| 493 | /* |
| 494 | //for test |