23
|
1 package treecms.tree.util;
|
|
2
|
|
3 import java.util.concurrent.locks.ReentrantLock;
|
|
4
|
|
5 public class LockableReference<V>
|
|
6 {
|
|
7 private volatile V m_ref;
|
|
8 private volatile ReentrantLock m_lock;
|
|
9
|
|
10 public LockableReference(V _ref)
|
|
11 {
|
|
12 m_ref = _ref;
|
|
13 m_lock = new ReentrantLock();
|
|
14 }
|
|
15
|
|
16 public V get()
|
|
17 {
|
|
18 m_lock.lock();
|
|
19 V ref = m_ref;
|
|
20 m_lock.unlock();
|
|
21 return ref;
|
|
22 }
|
|
23
|
|
24 public void put(V _ref)
|
|
25 {
|
|
26 m_lock.lock();
|
|
27 m_ref = _ref;
|
|
28 m_lock.unlock();
|
|
29 }
|
|
30
|
|
31 public void lock()
|
|
32 {
|
|
33 m_lock.lock();
|
|
34 }
|
|
35
|
|
36 public void unlock()
|
|
37 {
|
|
38 m_lock.unlock();
|
|
39 }
|
|
40 }
|