Lines Matching refs:Thread
47 * lock count thread id hash state 0
66 * Only one thread can own the monitor at any time. There may be several
73 Thread* owner; /* which thread currently owns the lock? */
77 Thread* waitSet; /* threads currently waiting on this monitor */
148 * Returns the thread id of the thread owning the given lock.
152 Thread *owner;
170 * Get the thread that holds the lock on the specified object. The
173 * The caller must lock the thread list before calling here.
175 Thread* dvmGetObjectLockHolder(Object* obj)
185 * Checks whether the given thread holds the given
188 bool dvmHoldsLock(Thread* thread, Object* obj)
190 if (thread == NULL || obj == NULL) {
193 return thread->threadId == lockOwner(obj);
266 static void logContentionEvent(Thread *self, u4 waitMs, u4 samplePercent,
294 /* Emit the sensitive thread ("main thread") status, 5 bytes. */
301 /* Emit self thread name string, <= 37 bytes. */
342 static void lockMonitor(Thread* self, Monitor* mon)
413 static bool tryLockMonitor(Thread* self, Monitor* mon)
436 static bool unlockMonitor(Thread* self, Monitor* mon)
471 Thread *fast, *slow;
489 * Links a thread into a monitor's wait set. The monitor lock must be
492 static void waitSetAppend(Monitor *mon, Thread *thread)
494 Thread *elt;
498 assert(thread != NULL);
499 assert(thread->waitNext == NULL);
502 mon->waitSet = thread;
509 elt->waitNext = thread;
513 * Unlinks a thread from a monitor's wait set. The monitor lock must
516 static void waitSetRemove(Monitor *mon, Thread *thread)
518 Thread *elt;
522 assert(thread != NULL);
527 if (mon->waitSet == thread) {
528 mon->waitSet = thread->waitNext;
529 thread->waitNext = NULL;
534 if (elt->waitNext == thread) {
535 elt->waitNext = thread->waitNext;
536 thread->waitNext = NULL;
592 * Object.wait() and (somewhat indirectly) Thread.sleep() and Thread.join().
594 * If another thread calls Thread.interrupt(), we throw InterruptedException
597 * - blocked in join(), join(long), or join(long, int) methods of Thread
598 * - blocked in sleep(long), or sleep(long, int) methods of Thread
613 static void waitMonitor(Thread* self, Monitor* mon, s8 msec, s4 nsec,
629 "object not locked by thread before wait()");
657 * fields so the subroutine can check that the calling thread owns
671 * Update thread status. If the GC wakes up, it'll ignore us, knowing
684 * When waitMonitor is non-NULL a notifying or interrupting thread
685 * must signal the thread's waitCond to wake it up.
691 * Handle the case where the thread was interrupted before we called
732 * We remove our thread from wait set after restoring the count
734 * thread owns the monitor. Aside from that, the order of member
749 * un-interruptible thread earlier and we're bailing out immediately.
751 * The doc sayeth: "The interrupted status of the current thread is
762 * Notify one thread waiting on this monitor.
764 static void notifyMonitor(Thread* self, Monitor* mon)
766 Thread* thread;
774 "object not locked by thread before notify()");
777 /* Signal the first waiting thread in the wait set. */
779 thread = mon->waitSet;
780 mon->waitSet = thread->waitNext;
781 thread->waitNext = NULL;
782 dvmLockMutex(&thread->waitMutex);
783 /* Check to see if the thread is still waiting. */
784 if (thread->waitMonitor != NULL) {
785 pthread_cond_signal(&thread->waitCond);
786 dvmUnlockMutex(&thread->waitMutex);
789 dvmUnlockMutex(&thread->waitMutex);
796 static void notifyAllMonitor(Thread* self, Monitor* mon)
798 Thread* thread;
806 "object not locked by thread before notifyAll()");
811 thread = mon->waitSet;
812 mon->waitSet = thread->waitNext;
813 thread->waitNext = NULL;
814 dvmLockMutex(&thread->waitMutex);
815 /* Check to see if the thread is still waiting. */
816 if (thread->waitMonitor != NULL) {
817 pthread_cond_signal(&thread->waitCond);
819 dvmUnlockMutex(&thread->waitMutex);
825 * internal lock state. The calling thread must own the lock.
827 static void inflateMonitor(Thread *self, Object *obj)
854 void dvmLockObject(Thread* self, Object *obj)
877 * The calling thread owns the lock. Increment the
891 * The lock is unowned. Install the thread id of the
892 * calling thread into the owner field. This is the
908 * The lock is owned by another thread. Notify the VM
919 * Check the shape of the lock word. Another thread
926 * thread id of the calling thread into the
941 * the owning thread can run.
963 * The thin lock was inflated by another thread.
1000 bool dvmUnlockObject(Thread* self, Object *obj)
1015 * by the given thread before unlocking it.
1064 void dvmObjectWait(Thread* self, Object *obj, s8 msec, s4 nsec,
1077 "object not locked by thread before wait()");
1081 /* This thread holds the lock. We need to fatten the lock
1084 * any other thread gets a chance.
1096 void dvmObjectNotify(Thread* self, Object *obj)
1108 "object not locked by thread before notify()");
1124 void dvmObjectNotifyAll(Thread* self, Object *obj)
1136 "object not locked by thread before notifyAll()");
1150 * This implements java.lang.Thread.sleep(long msec, int nsec).
1165 Thread* self = dvmThreadSelf();
1178 * Implement java.lang.Thread.interrupt().
1180 void dvmThreadInterrupt(Thread* thread)
1182 assert(thread != NULL);
1184 dvmLockMutex(&thread->waitMutex);
1190 if (thread->interrupted == true) {
1191 dvmUnlockMutex(&thread->waitMutex);
1200 thread->interrupted = true;
1203 * Is the thread waiting?
1206 * is only set when a thread actually waits on a monitor,
1209 if (thread->waitMonitor != NULL) {
1210 pthread_cond_signal(&thread->waitCond);
1213 dvmUnlockMutex(&thread->waitMutex);
1227 Thread *self, *thread;
1278 * this fail, we must suspend the owning thread.
1310 * identify the owning thread and suspend it.
1320 * Find the thread with the corresponding thread id.
1326 * thread list and fall through to the failure handler.
1328 thread = owner ? gDvm.threadList : NULL;
1329 while (thread != NULL) {
1330 if (thread->threadId == owner) {
1333 thread = thread->next;
1336 thread = LW_MONITOR(lock)->owner;
1339 * If thread is NULL the object has been released since the
1340 * thread list lock was acquired. Try again.
1342 if (thread == NULL) {
1347 * Wait for the owning thread to suspend.
1349 dvmSuspendThread(thread);
1350 if (dvmHoldsLock(thread, obj)) {
1352 * The owning thread has been suspended. We can safely
1356 dvmResumeThread(thread);
1361 * The wrong thread has been suspended. Try again.
1363 dvmResumeThread(thread);