コード例 #1
0
ファイル: RubyFiber.java プロジェクト: jhominal/jruby
  public void initialize(RubyProc block) {
    RubyNode.notDesignedForCompilation();

    final RubyFiber finalFiber = this;
    final RubyProc finalBlock = block;

    new Thread(
            new Runnable() {

              @Override
              public void run() {
                fiberManager.registerFiber(finalFiber);

                try {
                  try {
                    final Object arg = finalFiber.waitForResume();
                    final Object result = finalBlock.rootCall(arg);
                    finalFiber.lastResumedByFiber.resume(finalFiber, result);
                  } catch (FiberExitException e) {
                    // Naturally exit the thread on catching this
                  }
                } finally {
                  fiberManager.unregisterFiber(finalFiber);
                }
              }
            })
        .start();
  }
コード例 #2
0
ファイル: RubyFiber.java プロジェクト: jhominal/jruby
  /**
   * Send the Java thread that represents this fiber to sleep until it recieves a resume or exit
   * message. On entry, assumes that the GIL is not held. On exit, holding the GIL.
   */
  public Object waitForResume() {
    RubyNode.notDesignedForCompilation();

    FiberMessage message = null;

    do {
      try {
        // TODO(cs) what is a suitable timeout?
        message = messageQueue.poll(1, TimeUnit.SECONDS);
      } catch (InterruptedException e) {
        // Poll again
      }
    } while (message == null);

    if (message instanceof FiberExitMessage) {
      throw new FiberExitException();
    }

    final FiberResumeMessage resumeMessage = (FiberResumeMessage) message;

    threadManager.enterGlobalLock(resumeMessage.getThread());

    fiberManager.setCurrentFiber(this);

    lastResumedByFiber = resumeMessage.getSendingFiber();
    return resumeMessage.getArg();
  }
コード例 #3
0
ファイル: RubyNilClass.java プロジェクト: erippetoe/jruby
  /** Given a reference, produce either {@code nil} or the object. . */
  public static Object instanceOrNil(Object object) {
    RubyNode.notDesignedForCompilation();

    if (object == null) {
      return NilPlaceholder.INSTANCE;
    } else {
      return object;
    }
  }
コード例 #4
0
ファイル: RubyFiber.java プロジェクト: jhominal/jruby
  /**
   * Send a message to a fiber by posting into a message queue. Doesn't explicitly notify the Java
   * thread (although the queue implementation may) and doesn't wait for the message to be received.
   * On entry, assumes the the GIL is held. On exit, not holding the GIL.
   */
  public void resume(RubyFiber sendingFiber, Object... args) {
    RubyNode.notDesignedForCompilation();

    Object arg;

    if (args.length == 0) {
      arg = getContext().getCoreLibrary().getNilObject();
    } else if (args.length == 1) {
      arg = args[0];
    } else {
      arg = RubyArray.fromObjects(getContext().getCoreLibrary().getArrayClass(), args);
    }

    final RubyThread runningThread = threadManager.leaveGlobalLock();

    messageQueue.add(new FiberResumeMessage(runningThread, sendingFiber, arg));
  }
コード例 #5
0
ファイル: RubyFiber.java プロジェクト: jhominal/jruby
  public void shutdown() {
    RubyNode.notDesignedForCompilation();

    messageQueue.add(new FiberExitMessage());
  }
コード例 #6
0
ファイル: RubyNilClass.java プロジェクト: erippetoe/jruby
  public static boolean isNil(Object block) {
    RubyNode.notDesignedForCompilation();

    return block == NilPlaceholder.INSTANCE || block instanceof RubyNilClass;
  }
コード例 #7
0
ファイル: RubyNilClass.java プロジェクト: erippetoe/jruby
  @Override
  public boolean equals(Object other) {
    RubyNode.notDesignedForCompilation();

    return other instanceof RubyNilClass || other instanceof NilPlaceholder;
  }
コード例 #8
0
  public static boolean assignableTo(RubyClass thisClass, RubyModule otherClass) {
    RubyNode.notDesignedForCompilation();

    return includesModule(thisClass, otherClass);
  }