Skip to content

Commit

Permalink
Get channel name by finding the match
Browse files Browse the repository at this point in the history
  • Loading branch information
gabilang committed May 21, 2024
1 parent 7e130ed commit f50ebd7
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ public class Strand {
public Scheduler scheduler;
public Strand parent;
public WDChannels wdChannels;
public int wdChannelIndex;
public FlushDetail flushDetail;
public boolean blockedOnExtern;
public Set<ChannelDetails> channelDetails;
Expand Down
2 changes: 1 addition & 1 deletion bvm/ballerina-runtime/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
io.ballerina.lang.regexp;
exports io.ballerina.runtime.internal.values to io.ballerina.testerina.core, io.ballerina.testerina.runtime,
io.ballerina.lang.xml, org.ballerinalang.debugadapter.runtime, io.ballerina.lang.query,
io.ballerina.lang.function, io.ballerina.lang.regexp, io.ballerina.lang.value;
io.ballerina.lang.function, io.ballerina.lang.regexp, io.ballerina.lang.value, io.ballerina.lang.internal;
exports io.ballerina.runtime.internal.configurable to io.ballerina.lang.internal;
exports io.ballerina.runtime.internal.types to io.ballerina.lang.typedesc, io.ballerina.testerina.runtime,
org.ballerinalang.debugadapter.runtime, io.ballerina.lang.function, io.ballerina.lang.regexp, io.ballerina.testerina.core;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ public class MethodGen {
protected static final String FUNCTION_INVOCATION = "functionInvocation";
private static final String INVOCATION_COUNT = "%invocationCount";
private static final String RESUME_INDEX = "resumeIndex";
private static final String WD_CHANNEL_INDEX = "wdChannelIndex";
private final JvmPackageGen jvmPackageGen;
private final SymbolTable symbolTable;
private final Types types;
Expand Down Expand Up @@ -438,10 +437,6 @@ private void setChannelDetailsToStrand(BIRFunction func, int localVarOffset, Met
JvmCodeGenUtil.loadChannelDetails(mv, Arrays.asList(func.workerChannels), invocationVarIndex);
mv.visitMethodInsn(INVOKEVIRTUAL, STRAND_CLASS, "updateChannelDetails",
UPDATE_CHANNEL_DETAILS, false);
// Update wdChannelIndex of the strand.
mv.visitVarInsn(ALOAD, localVarOffset);
mv.visitVarInsn(ILOAD, invocationVarIndex);
mv.visitFieldInsn(PUTFIELD, STRAND_CLASS, WD_CHANNEL_INDEX, "I");
}

private void checkStrandCancelled(MethodVisitor mv, int localVarOffset) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import io.ballerina.runtime.internal.scheduling.Scheduler;
import io.ballerina.runtime.internal.scheduling.Strand;
import io.ballerina.runtime.internal.scheduling.WorkerDataChannel;
import io.ballerina.runtime.internal.values.ChannelDetails;

import java.util.Objects;

Expand All @@ -40,9 +41,20 @@ public static void autoClose(BString[] channelIds) {
Strand currentStrand = Scheduler.getStrand();
Strand channelHoldingStrand = Objects.requireNonNullElse(currentStrand.parent, currentStrand);
for (BString channelId : channelIds) {
String channelName = channelId.getValue() + ":" + currentStrand.wdChannelIndex;
String channelName = getMatchingChannelName(channelId.getValue(), currentStrand);
WorkerDataChannel workerDataChannel = channelHoldingStrand.wdChannels.getWorkerDataChannel(channelName);
workerDataChannel.autoClose();
}
}

private static String getMatchingChannelName(String channelId, Strand currentStrand) {
String channelName = null;
for (ChannelDetails channelDetail : currentStrand.channelDetails) {
if (channelDetail.name.contains(channelId)) {
channelName = channelDetail.name;
break;
}
}
return channelName;
}
}

0 comments on commit f50ebd7

Please sign in to comment.