Skip to content

Commit

Permalink
Increment stub transport count without synchronization.
Browse files Browse the repository at this point in the history
  • Loading branch information
broneill committed Feb 6, 2025
1 parent 853249e commit f6214c4
Showing 1 changed file with 25 additions and 16 deletions.
41 changes: 25 additions & 16 deletions src/main/java/org/cojen/dirmi/core/StubMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,35 @@ final class StubMap extends ItemMap<StubInvoker> {
*
* @param invoker must be a new instance
*/
synchronized Stub putAndSelectStub(StubInvoker invoker) {
Item[] items = mItems;
int slot = ((int) invoker.id) & (items.length - 1);

for (Item existing = items[slot]; existing != null; existing = existing.mNext) {
if (existing.id == invoker.id) {
Stub selected = ((StubInvoker) existing).select();
if (selected != null) {
selected.invoker().incTransportCount();
return selected;
Stub putAndSelectStub(StubInvoker invoker) {
Stub selected;

existing: {
synchronized (this) {
Item[] items = mItems;
int slot = ((int) invoker.id) & (items.length - 1);

for (Item existing = items[slot]; existing != null; existing = existing.mNext) {
if (existing.id == invoker.id) {
selected = ((StubInvoker) existing).select();
if (selected != null) {
break existing;
}
break;
}
}
break;

// Must init before calling doPut because upon doing so the invoker can be
// obtained by other threads.
selected = invoker.init();

doPut(items, invoker, slot);

return selected;
}
}

// Must init before calling doPut because upon doing so the invoker can be obtained by
// other threads.
Stub selected = invoker.init();

doPut(items, invoker, slot);
selected.invoker().incTransportCount();

return selected;
}
Expand Down

0 comments on commit f6214c4

Please sign in to comment.