Skip to content

Commit

Permalink
Showing 5 changed files with 48 additions and 8 deletions.
6 changes: 0 additions & 6 deletions spec/truffle/tags/core/thread/name_tags.txt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -46,7 +46,8 @@ DynamicObject createThread(
@Nullable @Volatile Object value,
AtomicBoolean wakeUp,
@Volatile int priority,
@Nullable DynamicObject threadGroup);
@Nullable DynamicObject threadGroup,
DynamicObject name);

boolean isThread(ObjectType objectType);
boolean isThread(DynamicObject object);
@@ -86,4 +87,7 @@ DynamicObject createThread(
DynamicObject getThreadGroup(DynamicObject object);
void setThreadGroup(DynamicObject object, DynamicObject value);

DynamicObject getName(DynamicObject object);
void setName(DynamicObject object, DynamicObject value);

}
Original file line number Diff line number Diff line change
@@ -70,6 +70,7 @@ public static DynamicObject createRubyThread(RubyContext context) {
null,
new AtomicBoolean(false),
0,
context.getCoreLibrary().getNilObject(),
context.getCoreLibrary().getNilObject());

Layouts.THREAD.setFiberManagerUnsafe(object, new FiberManager(context, object)); // Because it is cyclic
Original file line number Diff line number Diff line change
@@ -435,7 +435,8 @@ public DynamicObject allocate(
new AtomicReference<>(null),
new AtomicBoolean(false),
new AtomicInteger(0),
currentGroup);
currentGroup,
nil());

Layouts.THREAD.setFiberManagerUnsafe(object, new FiberManager(getContext(), object)); // Because it is cyclic

@@ -485,6 +486,31 @@ public void run(DynamicObject currentThread, Node currentNode) {

}

@Primitive(name = "thread_get_name")
public static abstract class ThreadGetNamePrimitiveNode extends PrimitiveArrayArgumentsNode {
public ThreadGetNamePrimitiveNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

@Specialization(guards = "isRubyThread(thread)")
public DynamicObject getName(DynamicObject thread) {
return Layouts.THREAD.getName(thread);
}
}

@Primitive(name = "thread_set_name")
public static abstract class ThreadSetNamePrimitiveNode extends PrimitiveArrayArgumentsNode {
public ThreadSetNamePrimitiveNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

@Specialization(guards = "isRubyThread(thread)")
public DynamicObject setName(DynamicObject thread, DynamicObject name) {
Layouts.THREAD.setName(thread, name);
return name;
}
}

@Primitive(name = "thread_get_priority", unsafe = UnsafeGroup.THREADS)
public static abstract class ThreadGetPriorityPrimitiveNode extends PrimitiveArrayArgumentsNode {
public ThreadGetPriorityPrimitiveNode(RubyContext context, SourceSection sourceSection) {
15 changes: 15 additions & 0 deletions truffle/src/main/ruby/core/thread.rb
Original file line number Diff line number Diff line change
@@ -193,6 +193,21 @@ def priority=(val)
Kernel.raise ThreadError, "Thread#priority= primitive failed"
end

def name
Truffle.primitive :thread_get_name
Kernel.raise ThreadError, "Thread#priority primitive failed"
end

def name=(val)
unless val.nil?
val = Rubinius::Type.check_null_safe(StringValue(val))
raise ArgumentError, "ASCII incompatible encoding #{val.encoding.name}" unless val.encoding.ascii_compatible?
# TODO BJF Aug 27, 2016 Need to rb_str_new_frozen the val here and SET_ANOTHER_THREAD_NAME
end
Truffle.invoke_primitive :thread_set_name, self, val
val
end

def inspect
stat = status()
stat = "dead" unless stat

0 comments on commit 6e1fed0

Please sign in to comment.