Skip to content

Commit f94339e

Browse files
committed
Encapsulate RubyThread#ioBuffer
1 parent b05feef commit f94339e

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

src/main/java/org/truffleruby/core/support/IONodes.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -523,8 +523,7 @@ protected RubyPointer getThreadBuffer(long size,
523523

524524
public static Pointer getBuffer(RubyContext context, RubyThread rubyThread, long size,
525525
ConditionProfile sizeProfile) {
526-
Pointer.checkNativeAccess(context);
527-
return rubyThread.ioBuffer.allocate(context, rubyThread, size, sizeProfile);
526+
return rubyThread.getIoBuffer(context).allocate(context, rubyThread, size, sizeProfile);
528527
}
529528
}
530529

@@ -535,8 +534,7 @@ public abstract static class IOThreadBufferFreeNode extends PrimitiveArrayArgume
535534
protected Object getThreadBuffer(RubyPointer pointer,
536535
@Cached ConditionProfile freeProfile) {
537536
RubyThread thread = getLanguage().getCurrentThread();
538-
Pointer.checkNativeAccess(getContext());
539-
thread.ioBuffer.free(thread, pointer.pointer, freeProfile);
537+
thread.getIoBuffer(getContext()).free(thread, pointer.pointer, freeProfile);
540538
return nil;
541539
}
542540
}

src/main/java/org/truffleruby/core/thread/RubyThread.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.truffleruby.core.support.PRNGRandomizerNodes;
3232
import org.truffleruby.core.support.RubyPRNGRandomizer;
3333
import org.truffleruby.core.tracepoint.TracePointState;
34+
import org.truffleruby.extra.ffi.Pointer;
3435
import org.truffleruby.language.Nil;
3536
import org.truffleruby.language.RubyDynamicObject;
3637
import org.truffleruby.language.objects.ObjectGraph;
@@ -62,7 +63,7 @@ public final class RubyThread extends RubyDynamicObject implements ObjectGraphNo
6263
volatile Object value = null;
6364
public final AtomicBoolean wakeUp = new AtomicBoolean(false);
6465
volatile int priority = Thread.NORM_PRIORITY;
65-
public ThreadLocalBuffer ioBuffer;
66+
ThreadLocalBuffer ioBuffer;
6667
Object threadGroup;
6768
public String sourceLocation;
6869
Object name = Nil.INSTANCE;
@@ -132,6 +133,11 @@ public void setCurrentFiber(RubyFiber fiber) {
132133
currentFiber = fiber;
133134
}
134135

136+
public ThreadLocalBuffer getIoBuffer(RubyContext context) {
137+
Pointer.checkNativeAccess(context);
138+
return ioBuffer;
139+
}
140+
135141
@Override
136142
public void getAdjacentObjects(Set<Object> reachable) {
137143
ObjectGraph.addProperty(reachable, threadLocalVariables);

src/main/java/org/truffleruby/language/loader/FeatureLoader.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ private String initializeWorkingDirectory() {
225225
final Encoding localeEncoding = context.getEncodingManager().getLocaleEncoding().jcoding;
226226
return new String(bytes, EncodingManager.charsetForEncoding(localeEncoding));
227227
} finally {
228-
rubyThread.ioBuffer.free(rubyThread, buffer, ConditionProfile.getUncached());
228+
rubyThread.getIoBuffer(context).free(rubyThread, buffer, ConditionProfile.getUncached());
229229
}
230230
}
231231

0 commit comments

Comments
 (0)