author | Jaroslav Tulach <jtulach@netbeans.org> |
Sat, 14 Jun 2008 09:54:36 +0200 | |
changeset 111 | 3905a2e66b9b |
child 112 | 64308321f7bd |
permissions | -rw-r--r-- |
1 package org.apidesign.reentrant;
3 import java.util.Collection;
4 import java.util.concurrent.atomic.AtomicInteger;
6 public class CriticalSectionReentrant<T extends Comparable<T>> implements CriticalSection<T> {
7 private T pilot;
8 private AtomicInteger cnt = new AtomicInteger();
10 public void assignPilot(T pilot) {
11 this.pilot = pilot;
12 }
14 public int sumBigger(Collection<T> args) {
15 T pilotCopy = this.pilot;
16 int own = 0;
17 for (T cmp : args) {
18 if (pilotCopy.compareTo(cmp) < 0) {
19 own++;
20 }
21 }
22 cnt.addAndGet(own);
23 return own;
26 }
28 public int getCount() {
29 return cnt.get();
30 }
31 }