Skip to content

Commit

Permalink
Encapsulate RubyThread#ioBuffer
Browse files Browse the repository at this point in the history
  • Loading branch information
eregon committed Sep 26, 2022
1 parent b05feef commit f94339e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
6 changes: 2 additions & 4 deletions src/main/java/org/truffleruby/core/support/IONodes.java
Original file line number Diff line number Diff line change
Expand Up @@ -523,8 +523,7 @@ protected RubyPointer getThreadBuffer(long size,

public static Pointer getBuffer(RubyContext context, RubyThread rubyThread, long size,
ConditionProfile sizeProfile) {
Pointer.checkNativeAccess(context);
return rubyThread.ioBuffer.allocate(context, rubyThread, size, sizeProfile);
return rubyThread.getIoBuffer(context).allocate(context, rubyThread, size, sizeProfile);
}
}

Expand All @@ -535,8 +534,7 @@ public abstract static class IOThreadBufferFreeNode extends PrimitiveArrayArgume
protected Object getThreadBuffer(RubyPointer pointer,
@Cached ConditionProfile freeProfile) {
RubyThread thread = getLanguage().getCurrentThread();
Pointer.checkNativeAccess(getContext());
thread.ioBuffer.free(thread, pointer.pointer, freeProfile);
thread.getIoBuffer(getContext()).free(thread, pointer.pointer, freeProfile);
return nil;
}
}
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/org/truffleruby/core/thread/RubyThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.truffleruby.core.support.PRNGRandomizerNodes;
import org.truffleruby.core.support.RubyPRNGRandomizer;
import org.truffleruby.core.tracepoint.TracePointState;
import org.truffleruby.extra.ffi.Pointer;
import org.truffleruby.language.Nil;
import org.truffleruby.language.RubyDynamicObject;
import org.truffleruby.language.objects.ObjectGraph;
Expand Down Expand Up @@ -62,7 +63,7 @@ public final class RubyThread extends RubyDynamicObject implements ObjectGraphNo
volatile Object value = null;
public final AtomicBoolean wakeUp = new AtomicBoolean(false);
volatile int priority = Thread.NORM_PRIORITY;
public ThreadLocalBuffer ioBuffer;
ThreadLocalBuffer ioBuffer;
Object threadGroup;
public String sourceLocation;
Object name = Nil.INSTANCE;
Expand Down Expand Up @@ -132,6 +133,11 @@ public void setCurrentFiber(RubyFiber fiber) {
currentFiber = fiber;
}

public ThreadLocalBuffer getIoBuffer(RubyContext context) {
Pointer.checkNativeAccess(context);
return ioBuffer;
}

@Override
public void getAdjacentObjects(Set<Object> reachable) {
ObjectGraph.addProperty(reachable, threadLocalVariables);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ private String initializeWorkingDirectory() {
final Encoding localeEncoding = context.getEncodingManager().getLocaleEncoding().jcoding;
return new String(bytes, EncodingManager.charsetForEncoding(localeEncoding));
} finally {
rubyThread.ioBuffer.free(rubyThread, buffer, ConditionProfile.getUncached());
rubyThread.getIoBuffer(context).free(rubyThread, buffer, ConditionProfile.getUncached());
}
}

Expand Down

0 comments on commit f94339e

Please sign in to comment.