Skip to content

Commit

Permalink
Removed synchronized() around Average{MinMax}
Browse files Browse the repository at this point in the history
  • Loading branch information
belaban committed Dec 10, 2024
1 parent 213966c commit f75552e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 34 deletions.
8 changes: 2 additions & 6 deletions src/org/jgroups/blocks/RequestCorrelator.java
Original file line number Diff line number Diff line change
Expand Up @@ -361,19 +361,15 @@ protected void dispatch(final Message msg, final Header hdr) {
long start=System.nanoTime();
handleRequest(msg, hdr);
long time=(long)((System.nanoTime() - start) / 1000.0);
synchronized(avg_req_delivery) {
avg_req_delivery.add(time);
}
avg_req_delivery.add(time);
break;

case Header.RSP:
case Header.EXC_RSP:
start=System.nanoTime();
handleResponse(msg, hdr);
time=(long)((System.nanoTime() - start) / 1000.0);
synchronized(avg_rsp_delivery) {
avg_rsp_delivery.add(time);
}
avg_rsp_delivery.add(time);
break;

default:
Expand Down
12 changes: 3 additions & 9 deletions src/org/jgroups/protocols/THREAD_COUNT.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ public Object down(Message msg) {
return down_prot.down(msg);
try {
int cnt=down_count.incrementAndGet();
synchronized(avg_down) {
avg_down.add(cnt);
}
avg_down.add(cnt);
return down_prot.down(msg);
}
finally {
Expand All @@ -55,9 +53,7 @@ public Object up(Message msg) {
return up_prot.up(msg);
try {
int cnt=up_count.incrementAndGet();
synchronized(avg_up) {
avg_up.add(cnt);
}
avg_up.add(cnt);
return up_prot.up(msg);
}
finally {
Expand All @@ -73,9 +69,7 @@ public void up(MessageBatch batch) {
}
try {
int cnt=up_count.incrementAndGet();
synchronized(avg_up) {
avg_up.add(cnt);
}
avg_up.add(cnt);
up_prot.up(batch);
}
finally {
Expand Down
4 changes: 1 addition & 3 deletions tests/junit-functional/org/jgroups/blocks/CounterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,7 @@ public void testAsyncIncrement() throws TimeoutException {
.thenAccept(v -> {
values[(int)v.longValue()]=v;
long time=Util.micros()-start;
synchronized(avg) {
avg.add(time);
}
avg.add(time);
});
}
Util.waitUntil(50000, 1, () -> IntStream.rangeClosed(1, 999).allMatch(i -> values[i] > 0));
Expand Down
22 changes: 6 additions & 16 deletions tests/util/org/jgroups/util/ProtPerfHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -277,25 +277,15 @@ protected static class Entry {
protected final AverageMinMax avg_up=new AverageMinMax().unit(NANOSECONDS);

protected void add(long value, boolean down) {
if(down) {
synchronized(avg_down) {
avg_down.add(value);
}
}
else {
synchronized(avg_up) {
avg_up.add(value);
}
}
if(down)
avg_down.add(value);
else
avg_up.add(value);
}

protected void clear() {
synchronized(avg_down) {
avg_down.clear();
}
synchronized(avg_up) {
avg_up.clear();
}
avg_down.clear();
avg_up.clear();
}

public String toString() {
Expand Down

0 comments on commit f75552e

Please sign in to comment.