Changeset 4092


Ignore:
Timestamp:
Nov 9, 2009, 8:31:04 PM (11 years ago)
Author:
yura
Message:
Location:
to-imperative/trunk
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • to-imperative/trunk/java/java/org/refal/plus/objects/Box.java

    r4015 r4092  
    44
    55import java.io.Serializable;
     6import java.util.concurrent.locks.Lock;
     7import java.util.concurrent.locks.ReentrantLock;
    68
    79import org.refal.plus.Expr;
     
    1113
    1214    public Expr expr;
     15    public final Lock lock;
    1316
    1417    public Box () {
    1518        expr = Expr.empty;
     19        lock = new ReentrantLock();
    1620    }
    1721
  • to-imperative/trunk/java/java/refal/plus/Box.java

    r4083 r4092  
    22
    33package refal.plus;
     4
     5import java.util.concurrent.locks.Lock;
    46
    57import org.refal.plus.Expr;
     
    5355    }
    5456
     57    @RefalFormat("$func? AtomicApply s.func s.box e.arg = e.res;")
     58    public static boolean AtomicApply (Expr func, Expr box, Expr arg, Result res) throws RefalException {
     59        try {
     60            final Lock lock = getBox(box).lock;
     61            lock.lock();
     62            try {
     63                return Apply.Apply(func, Expr.concat(box, arg), res);
     64            } finally {
     65                lock.unlock();
     66            }
     67        } catch (ClassCastException _) {
     68            throw new RefalException("refal.plus.Box.AtomicApply", "Invalid argument");
     69        }
     70    }
    5571}
Note: See TracChangeset for help on using the changeset viewer.