inline ScopedThreadStateChange::ScopedThreadStateChange(Thread* self, ThreadState new_thread_state)
: self_(self), thread_state_(new_thread_state), expected_has_no_thread_(false) { if (UNLIKELY(self_ == nullptr)) { // Value chosen arbitrarily and won't be used in the destructor since thread_ == null.
old_thread_state_ = ThreadState::kTerminated;
Runtime* runtime = Runtime::Current();
CHECK(runtime == nullptr || !runtime->IsStarted() || runtime->IsShuttingDown(self_));
} else {
DCHECK_EQ(self, Thread::Current()); // Read state without locks, ok as state is effectively thread local and we're not interested // in the suspend count (this will be handled in the runnable transitions).
old_thread_state_ = self->GetState(); if (old_thread_state_ != new_thread_state) { if (new_thread_state == ThreadState::kRunnable) {
self_->TransitionFromSuspendedToRunnable();
} elseif (old_thread_state_ == ThreadState::kRunnable) {
self_->TransitionFromRunnableToSuspended(new_thread_state);
} else { // A transition between suspended states.
self_->SetState(new_thread_state);
}
}
}
}
inline ScopedThreadStateChange::~ScopedThreadStateChange() { if (UNLIKELY(self_ == nullptr)) {
ScopedThreadChangeDestructorCheck();
} else { if (old_thread_state_ != thread_state_) { if (old_thread_state_ == ThreadState::kRunnable) {
self_->TransitionFromSuspendedToRunnable();
} elseif (thread_state_ == ThreadState::kRunnable) {
self_->TransitionFromRunnableToSuspended(old_thread_state_);
} else { // A transition between suspended states.
self_->SetState(old_thread_state_);
}
}
}
}
template<typename T> inline T ScopedObjectAccessAlreadyRunnable::AddLocalReference(ObjPtr<mirror::Object> obj) const {
Locks::mutator_lock_->AssertSharedHeld(Self()); if (kIsDebugBuild) {
CHECK(IsRunnable()); // Don't work with raw objects in non-runnable states.
DCheckObjIsNotClearedJniWeakGlobal(obj);
} return obj == nullptr ? nullptr : Env()->AddLocalReference<T>(obj);
}
template<typename T> inline ObjPtr<T> ScopedObjectAccessAlreadyRunnable::Decode(jobject obj) const {
Locks::mutator_lock_->AssertSharedHeld(Self());
DCHECK(IsRunnable()); // Don't work with raw objects in non-runnable states. return ObjPtr<T>::DownCast(Self()->DecodeJObject(obj));
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.