Ejemplo n.º 1
0
  @JRubyMethod(
      name = {"initialize"},
      visibility = PRIVATE)
  public IRubyObject initialize(ThreadContext context, IRubyObject type, IRubyObject address) {
    setMemoryIO(
        address instanceof Pointer
            ? ((Pointer) address).getMemoryIO()
            : Factory.getInstance()
                .wrapDirectMemory(context.runtime, RubyFixnum.num2long(address)));
    size = Long.MAX_VALUE;
    typeSize = calculateTypeSize(context, type);

    return this;
  }
Ejemplo n.º 2
0
  @JRubyMethod(name = "priority=", required = 1)
  public IRubyObject priority_set(IRubyObject priority) {
    // FIXME: This should probably do some translation from Ruby priority levels to Java priority
    // levels (until we have green threads)
    int iPriority = RubyNumeric.fix2int(priority);

    if (iPriority < Thread.MIN_PRIORITY) {
      iPriority = Thread.MIN_PRIORITY;
    } else if (iPriority > Thread.MAX_PRIORITY) {
      iPriority = Thread.MAX_PRIORITY;
    }

    if (threadImpl.isAlive()) {
      threadImpl.setPriority(iPriority);
    }

    return RubyFixnum.newFixnum(getRuntime(), iPriority);
  }
  @JRubyMethod(name = "priority=", required = 1)
  public IRubyObject priority_set(IRubyObject priority) {
    int iPriority = RubyNumeric.fix2int(priority);

    if (iPriority < RUBY_MIN_THREAD_PRIORITY) {
      iPriority = RUBY_MIN_THREAD_PRIORITY;
    } else if (iPriority > RUBY_MAX_THREAD_PRIORITY) {
      iPriority = RUBY_MAX_THREAD_PRIORITY;
    }

    if (threadImpl.isAlive()) {
      int jPriority = rubyPriorityToJavaPriority(iPriority);
      if (jPriority < Thread.MIN_PRIORITY) {
        jPriority = Thread.MIN_PRIORITY;
      } else if (jPriority > Thread.MAX_PRIORITY) {
        jPriority = Thread.MAX_PRIORITY;
      }
      threadImpl.setPriority(jPriority);
    }

    return RubyFixnum.newFixnum(getRuntime(), iPriority);
  }
Ejemplo n.º 4
0
 @JRubyMethod(name = "size", meta = true, visibility = PUBLIC)
 public static IRubyObject size(ThreadContext context, IRubyObject recv) {
   return RubyFixnum.newFixnum(
       context.getRuntime(), Factory.getInstance().sizeOf(NativeType.POINTER));
 }
Ejemplo n.º 5
0
 @JRubyMethod(name = "priority")
 public RubyFixnum priority() {
   return RubyFixnum.newFixnum(getRuntime(), threadImpl.getPriority());
 }