コード例 #1
0
ファイル: RubyThread.java プロジェクト: nahi/jruby
  public static RubyClass createThreadClass(Ruby runtime) {
    // FIXME: In order for Thread to play well with the standard 'new' behavior,
    // it must provide an allocator that can create empty object instances which
    // initialize then fills with appropriate data.
    RubyClass threadClass =
        runtime.defineClass(
            "Thread", runtime.getObject(), ObjectAllocator.NOT_ALLOCATABLE_ALLOCATOR);
    runtime.setThread(threadClass);

    threadClass.index = ClassIndex.THREAD;
    threadClass.setReifiedClass(RubyThread.class);

    threadClass.defineAnnotatedMethods(RubyThread.class);

    RubyThread rubyThread = new RubyThread(runtime, threadClass);
    // TODO: need to isolate the "current" thread from class creation
    rubyThread.threadImpl = new NativeThread(rubyThread, Thread.currentThread());
    runtime.getThreadService().setMainThread(Thread.currentThread(), rubyThread);

    // set to default thread group
    runtime.getDefaultThreadGroup().addDirectly(rubyThread);

    threadClass.setMarshal(ObjectMarshal.NOT_MARSHALABLE_MARSHAL);

    return threadClass;
  }
コード例 #2
0
ファイル: RubyThread.java プロジェクト: nahi/jruby
 /**
  * Try to acquire the given lock, adding it to a list of held locks for cleanup on thread
  * termination if it is acquired. Return immediately if the lock cannot be acquired.
  *
  * @param lock the lock to acquire, released on thread termination
  */
 public boolean tryLock(Lock lock) {
   assert Thread.currentThread() == getNativeThread();
   boolean locked = lock.tryLock();
   if (locked) {
     heldLocks.add(lock);
   }
   return locked;
 }
コード例 #3
0
ファイル: RubyThread.java プロジェクト: nahi/jruby
 private static void debug(RubyThread thread, String message) {
   if (DEBUG) LOG.debug(Thread.currentThread() + "(" + thread.status + "): " + message);
 }
コード例 #4
0
ファイル: RubyThread.java プロジェクト: nahi/jruby
 /** Release all locks held. */
 public void unlockAll() {
   assert Thread.currentThread() == getNativeThread();
   for (Lock lock : heldLocks) {
     lock.unlock();
   }
 }
コード例 #5
0
ファイル: RubyThread.java プロジェクト: nahi/jruby
 /**
  * Release the given lock and remove it from the list of locks to be released on thread
  * termination.
  *
  * @param lock the lock to release and dereferences
  */
 public void unlock(Lock lock) {
   assert Thread.currentThread() == getNativeThread();
   lock.unlock();
   heldLocks.remove(lock);
 }
コード例 #6
0
ファイル: RubyThread.java プロジェクト: nahi/jruby
 /**
  * Acquire the given lock interruptibly, holding a reference to it for cleanup on thread
  * termination.
  *
  * @param lock the lock to acquire, released on thread termination
  * @throws InterruptedException if the lock acquisition is interrupted
  */
 public void lockInterruptibly(Lock lock) throws InterruptedException {
   assert Thread.currentThread() == getNativeThread();
   lock.lockInterruptibly();
   heldLocks.add(lock);
 }
コード例 #7
0
ファイル: RubyThread.java プロジェクト: nahi/jruby
 /**
  * Acquire the given lock, holding a reference to it for cleanup on thread termination.
  *
  * @param lock the lock to acquire, released on thread termination
  */
 public void lock(Lock lock) {
   assert Thread.currentThread() == getNativeThread();
   lock.lock();
   heldLocks.add(lock);
 }
コード例 #8
0
 /**
  * Perform pre-execution tasks once the native thread is running, but we have not yet called the
  * Ruby code for the thread.
  */
 public void beforeStart() {
   // store initial priority, for restoring pooled threads to normal
   this.initialPriority = Thread.currentThread().getPriority();
 }