Lines Matching defs:thread
32 #include "thread.h"
63 * Only one thread can own the monitor at any time. There may be several threads waiting on it
83 Monitor::Monitor(Thread* self, Thread* owner, mirror::Object* obj, int32_t hash_code)
105 Monitor::Monitor(Thread* self, Thread* owner, mirror::Object* obj, int32_t hash_code,
137 bool Monitor::Install(Thread* self) {
153 // The owner_ is suspended but another thread beat us to install a monitor.
182 * Links a thread into a monitor's wait set. The monitor lock must be
185 void Monitor::AppendToWaitSet(Thread* thread) {
186 DCHECK(owner_ == Thread::Current());
187 DCHECK(thread != NULL);
188 DCHECK(thread->GetWaitNext() == nullptr) << thread->GetWaitNext();
190 wait_set_ = thread;
195 Thread* t = wait_set_;
199 t->SetWaitNext(thread);
203 * Unlinks a thread from a monitor's wait set. The monitor lock must
206 void Monitor::RemoveFromWaitSet(Thread *thread) {
207 DCHECK(owner_ == Thread::Current());
208 DCHECK(thread != NULL);
212 if (wait_set_ == thread) {
213 wait_set_ = thread->GetWaitNext();
214 thread->SetWaitNext(nullptr);
218 Thread* t = wait_set_;
220 if (t->GetWaitNext() == thread) {
221 t->SetWaitNext(thread->GetWaitNext());
222 thread->SetWaitNext(nullptr);
233 void Monitor::Lock(Thread* self) {
301 Thread* self = Thread::Current();
313 static std::string ThreadToString(Thread* thread) {
314 if (thread == NULL) {
318 // TODO: alternatively, we could just return the thread's name.
319 oss << *thread;
323 void Monitor::FailedUnlock(mirror::Object* o, Thread* expected_owner, Thread* found_owner,
325 Thread* current_owner = NULL;
331 // Acquire thread list lock so threads won't disappear from under us.
332 MutexLock mu(Thread::Current(), *Locks::thread_list_lock_);
343 " on thread '%s'",
349 " (where now the monitor appears unowned) on thread '%s'",
358 " (originally believed to be unowned) on thread '%s'",
366 " owned by '%s') on object of type '%s' on thread '%s'",
373 " on thread '%s",
382 bool Monitor::Unlock(Thread* self) {
385 Thread* owner = owner_;
409 * Object.wait() and (somewhat indirectly) Thread.sleep() and Thread.join().
411 * If another thread calls Thread.interrupt(), we throw InterruptedException
414 * - blocked in join(), join(long), or join(long, int) methods of Thread
415 * - blocked in sleep(long), or sleep(long, int) methods of Thread
430 void Monitor::Wait(Thread* self, int64_t ms, int32_t ns,
440 ThrowIllegalMonitorStateExceptionF("object not locked by thread before wait()");
465 * fields so the subroutine can check that the calling thread owns
480 * Update thread state. If the GC wakes up, it'll ignore us, knowing
492 // non-NULL a notifying or interrupting thread must signal the thread's wait_cond_ to wake it
501 // Handle the case where the thread was interrupted before we called wait().
523 // We reset the thread's wait_monitor_ field after transitioning back to runnable so
524 // that a thread in a waiting/sleeping state has a non-null wait_monitor_ for debugging
538 * We remove our thread from wait set after restoring the count
540 * thread owns the monitor. Aside from that, the order of member
555 * un-interruptible thread earlier and we're bailing out immediately.
557 * The doc sayeth: "The interrupted status of the current thread is
571 void Monitor::Notify(Thread* self) {
576 ThrowIllegalMonitorStateExceptionF("object not locked by thread before notify()");
579 // Signal the first waiting thread in the wait set.
581 Thread* thread = wait_set_;
582 wait_set_ = thread->GetWaitNext();
583 thread->SetWaitNext(nullptr);
585 // Check to see if the thread is still waiting.
586 MutexLock mu(self, *thread->GetWaitMutex());
587 if (thread->GetWaitMonitor() != nullptr) {
588 thread->GetWaitConditionVariable()->Signal(self);
594 void Monitor::NotifyAll(Thread* self) {
599 ThrowIllegalMonitorStateExceptionF("object not locked by thread before notifyAll()");
604 Thread* thread = wait_set_;
605 wait_set_ = thread->GetWaitNext();
606 thread->SetWaitNext(nullptr);
607 thread->Notify();
611 bool Monitor::Deflate(Thread* self, mirror::Object* obj) {
624 Thread* owner = monitor->owner_;
653 void Monitor::Inflate(Thread* self, Thread* owner, mirror::Object* obj, int32_t hash_code) {
661 VLOG(monitor) << "monitor: thread" << owner->GetThreadId()
674 void Monitor::InflateThinLocked(Thread* self, Handle<mirror::Object> obj, LockWord lock_word,
686 Thread* owner;
689 // Take suspend thread lock to avoid races with threads trying to suspend this one.
694 // We succeeded in suspending the thread, check the lock's status didn't change.
719 mirror::Object* Monitor::MonitorEnter(Thread* self, mirror::Object* obj) {
756 // TODO: Consider switching the thread state to kBlocked when we are yielding.
758 // parameter you pass in. This can cause thread suspension to take excessively long
785 bool Monitor::MonitorExit(Thread* self, mirror::Object* obj) {
803 Thread* owner =
833 void Monitor::Wait(Thread* self, mirror::Object *obj, int64_t ms, int32_t ns,
843 ThrowIllegalMonitorStateExceptionF("object not locked by thread before wait()");
849 ThrowIllegalMonitorStateExceptionF("object not locked by thread before wait()");
870 void Monitor::DoNotify(Thread* self, mirror::Object* obj, bool notify_all) {
878 ThrowIllegalMonitorStateExceptionF("object not locked by thread before notify()");
884 ThrowIllegalMonitorStateExceptionF("object not locked by thread before notify()");
928 void Monitor::DescribeWait(std::ostream& os, const Thread* thread) {
933 ThreadState state = thread->GetState();
936 Thread* self = Thread::Current();
937 MutexLock mu(self, *thread->GetWaitMutex());
938 Monitor* monitor = thread->GetWaitMonitor();
944 pretty_object = thread->GetMonitorEnterObject();
955 Locks::mutator_lock_->IsExclusiveHeld(Thread::Current())) {
957 // current thread, which isn't safe if this is the only runnable thread.
967 // - waiting to lock <0x613f83d8> (a java.lang.Object) held by thread 5
969 os << " held by thread " << lock_owner;
975 mirror::Object* Monitor::GetContendedMonitor(Thread* thread) {
977 // definition of contended that includes a monitor a thread is trying to enter...
978 mirror::Object* result = thread->GetMonitorEnterObject();
980 // ...but also a monitor that the thread is waiting on.
981 MutexLock mu(Thread::Current(), *thread->GetWaitMutex());
982 Monitor* monitor = thread->GetWaitMonitor();
1066 MutexLock mu(Thread::Current(), list->monitor_list_lock_);
1083 MutexLock mu(Thread::Current(), monitor_lock_);
1103 MutexLock mu(Thread::Current(), monitor_lock_);
1104 Thread* owner = owner_;
1118 Thread* self = Thread::Current();
1127 MutexLock mu(Thread::Current(), monitor_list_lock_);
1132 Thread* self = Thread::Current();
1139 Thread* self = Thread::Current();
1148 Thread* self = Thread::Current();
1169 MonitorDeflateArgs() : self(Thread::Current()), deflate_count(0) {}
1170 Thread* const self;
1212 for (Thread* waiter = mon->wait_set_; waiter != NULL; waiter = waiter->GetWaitNext()) {