Mercurial > hg > Members > shoshi > TreeCMSv2
comparison src/treecms/tree/util/LockableReference.java @ 23:77a894c0b919
commit
author | shoshi |
---|---|
date | Thu, 09 Jun 2011 01:03:48 +0900 |
parents | |
children | 68021f7091e1 |
comparison
equal
deleted
inserted
replaced
22:fa784faafc78 | 23:77a894c0b919 |
---|---|
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 } |