CVS update: JGroups/src/org/jgroups/util CreditMap.java
"Bela Ban" <[email protected]>
| Newsgroups | gmane.comp.java.javagroups.cvs |
|---|---|
| Message-ID | <[email protected]> |
User: belaban
Date: 10/09/07 14:00:51
Modified: src/org/jgroups/util CreditMap.java
Log:
ns
Revision Changes Path
1.4 +19 -5 JGroups/src/org/jgroups/util/CreditMap.java
Index: CreditMap.java
===================================================================
RCS file: /cvsroot/javagroups/JGroups/src/org/jgroups/util/CreditMap.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- CreditMap.java 7 Sep 2010 13:25:21 -0000 1.3
+++ CreditMap.java 7 Sep 2010 14:00:51 -0000 1.4
@@ -14,7 +14,7 @@
/**
* Maintains credits for senders, when credits fall below 0, a sender blocks until new credits have been received.
* @author Bela Ban
- * @version $Id: CreditMap.java,v 1.3 2010/09/07 13:25:21 belaban Exp $
+ * @version $Id: CreditMap.java,v 1.4 2010/09/07 14:00:51 belaban Exp $
*/
public class CreditMap {
protected final long max_credits;
@@ -63,6 +63,7 @@
public Long putIfAbsent(Address key) {
lock.lock();
try {
+ flushAccumulatedCredits();
Long val=credits.get(key);
return val != null? val : credits.put(key, max_credits);
}
@@ -111,11 +112,14 @@
if(val == null)
return;
- boolean update_min_credits=val.longValue() <= min_credits;
+ boolean potential_update=val.longValue() - accumulated_credits <= min_credits;
decrementAndAdd(sender, new_credits);
- if(update_min_credits) {
- min_credits=computeLowestCredit();
- credits_available.signalAll();
+ if(potential_update) {
+ long new_min=computeLowestCredit();
+ if(new_min > min_credits) {
+ min_credits=new_min;
+ credits_available.signalAll();
+ }
}
}
finally {
@@ -196,5 +200,15 @@
}
}
+ // Called with lock held
+ protected void flushAccumulatedCredits() {
+ if(accumulated_credits > 0) {
+ for(Map.Entry<Address,Long> entry: this.credits.entrySet()) {
+ entry.setValue(Math.max(0, entry.getValue().longValue() - accumulated_credits));
+ }
+ accumulated_credits=0;
+ }
+ }
+
}
------------------------------------------------------------------------------
This SF.net Dev2Dev email is sponsored by:
Show off your parallel programming skills.
Enter the Intel(R) Threading Challenge 2010.
http://p.sf.net/sfu/intel-thread-sfd