00001 package edu.ksu.cis.bandera.bir;
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 import ca.mcgill.sable.util.*;
00036
00037
00038
00039
00040
00041 public class LockAction extends AbstractAction implements BirConstants {
00042
00043 Expr lockExpr;
00044 int operation;
00045 BirThread thread;
00046
00047
00048
00049
00050
00051
00052
00053 public LockAction(Expr lockExpr, int operation,
00054 BirThread thread) {
00055 this.lockExpr = lockExpr;
00056 this.operation = operation;
00057 this.thread = thread;
00058 }
00059 public void apply(Switch sw)
00060 {
00061 ((ExprSwitch) sw).caseLockAction(this);
00062 }
00063 public boolean canSuspend() {
00064 return (operation == LOCK) || (operation == WAIT);
00065 }
00066 public Expr getLockExpr() { return lockExpr; }
00067 public int getOperation() { return operation; }
00068 public BirThread getThread() { return thread; }
00069 public boolean isLock() {
00070 return operation == LOCK;
00071 }
00072 public boolean isLockAction(int operation) {
00073 return (operation & this.operation) != 0;
00074 }
00075 public boolean isNotify() {
00076 return operation == NOTIFY;
00077 }
00078 public boolean isNotifyAll() {
00079 return operation == NOTIFYALL;
00080 }
00081 public boolean isUnlock() {
00082 return operation == UNLOCK;
00083 }
00084 public boolean isUnwait() {
00085 return operation == UNWAIT;
00086 }
00087 public boolean isWait() {
00088 return operation == WAIT;
00089 }
00090 public static int operationCode(String methodName) {
00091 if (methodName.equals("wait"))
00092 return WAIT;
00093 if (methodName.equals("notify"))
00094 return NOTIFY;
00095 if (methodName.equals("notifyAll"))
00096 return NOTIFYALL;
00097 return INVALID;
00098 }
00099 public static String operationName(int operation) {
00100 switch (operation) {
00101 case LOCK: return "lock";
00102 case UNLOCK: return "unlock";
00103 case WAIT: return "wait";
00104 case UNWAIT: return "unwait";
00105 case NOTIFY: return "notify";
00106 case NOTIFYALL: return "notifyAll";
00107 default: return "?";
00108 }
00109 }
00110 }