1 |
| package org.jboss.cache.lock; |
2 |
| |
3 |
| import java.util.concurrent.Semaphore; |
4 |
| import java.util.concurrent.TimeUnit; |
5 |
| import java.util.concurrent.locks.Condition; |
6 |
| import java.util.concurrent.locks.Lock; |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| public class SemaphoreLock extends Semaphore implements Lock |
12 |
| { |
13 |
| |
14 |
| |
15 |
| |
16 |
| |
17 |
| private static final long serialVersionUID = -15293253129957476L; |
18 |
| |
19 |
24736
| public SemaphoreLock(int permits)
|
20 |
| { |
21 |
24736
| super(permits);
|
22 |
| } |
23 |
| |
24 |
0
| public void lock()
|
25 |
| { |
26 |
0
| try
|
27 |
| { |
28 |
0
| acquire();
|
29 |
| } |
30 |
| catch (InterruptedException e) |
31 |
| { |
32 |
0
| lock();
|
33 |
| } |
34 |
| } |
35 |
| |
36 |
0
| public void lockInterruptibly() throws InterruptedException
|
37 |
| { |
38 |
0
| acquire();
|
39 |
| } |
40 |
| |
41 |
0
| public Condition newCondition()
|
42 |
| { |
43 |
0
| throw new UnsupportedOperationException();
|
44 |
| } |
45 |
| |
46 |
0
| public boolean tryLock()
|
47 |
| { |
48 |
0
| return tryAcquire();
|
49 |
| } |
50 |
| |
51 |
514362
| public boolean tryLock(long arg0, TimeUnit arg1) throws InterruptedException
|
52 |
| { |
53 |
514362
| return tryAcquire(arg0, arg1);
|
54 |
| } |
55 |
| |
56 |
514320
| public void unlock()
|
57 |
| { |
58 |
514320
| release();
|
59 |
| } |
60 |
| |
61 |
| } |