*** empty log message ***
[IRC.git] / Robust / Transactions / dstm2 / src / dstm2 / SpecialLock.java
1 /*
2  * To change this template, choose Tools | Templates
3  * and open the template in the editor.
4  */
5
6 package dstm2;
7
8
9 import java.util.concurrent.locks.ReentrantLock;
10
11 /**
12  *
13  * @author navid
14  */
15 public class SpecialLock extends ReentrantLock{
16     private static SpecialLock instance = null;
17     private Transaction ownerTransaction = null;
18
19     private SpecialLock() {
20     }
21     
22     
23     public synchronized void lock(Transaction tr){
24         super.lock();
25         setOwnerTransaction(tr);
26     }
27     
28     public synchronized void unlock(Transaction tr){
29         super.unlock();
30         setOwnerTransaction(null);
31     }
32     
33     public synchronized void setOwnerTransaction(Transaction tr){
34         ownerTransaction = tr;
35     }
36     
37     public synchronized Transaction getOwnerTransaction(){
38         return ownerTransaction;
39     }
40     
41     public synchronized static SpecialLock getSpecialLock(){
42         if (instance == null){ 
43             instance = new SpecialLock();
44             return instance;
45         }
46         else
47             return instance;    
48         
49     }
50
51 }