Factor out common code for SetPendingNext.
Change-Id: I6c1f9cd6da7b2c21714175455e61479273d3669f
diff --git a/runtime/gc/reference_processor.cc b/runtime/gc/reference_processor.cc
index 5e7f1a2..8356814 100644
--- a/runtime/gc/reference_processor.cc
+++ b/runtime/gc/reference_processor.cc
@@ -277,11 +277,7 @@
MutexLock mu2(self, *Locks::reference_queue_finalizer_references_lock_);
if (!reference->IsEnqueued()) {
CHECK(reference->IsFinalizerReferenceInstance());
- if (Runtime::Current()->IsActiveTransaction()) {
- reference->SetPendingNext<true>(reference);
- } else {
- reference->SetPendingNext<false>(reference);
- }
+ reference->SetPendingNext(reference);
return true;
}
return false;
diff --git a/runtime/gc/reference_queue.cc b/runtime/gc/reference_queue.cc
index 56957ba..67dcc2d 100644
--- a/runtime/gc/reference_queue.cc
+++ b/runtime/gc/reference_queue.cc
@@ -49,17 +49,9 @@
list_ = ref;
} else {
mirror::Reference* head = list_->GetPendingNext();
- if (Runtime::Current()->IsActiveTransaction()) {
- ref->SetPendingNext<true>(head);
- } else {
- ref->SetPendingNext<false>(head);
- }
+ ref->SetPendingNext(head);
}
- if (Runtime::Current()->IsActiveTransaction()) {
- list_->SetPendingNext<true>(ref);
- } else {
- list_->SetPendingNext<false>(ref);
- }
+ list_->SetPendingNext(ref);
}
mirror::Reference* ReferenceQueue::DequeuePendingReference() {
@@ -74,18 +66,10 @@
list_ = nullptr;
} else {
mirror::Reference* next = head->GetPendingNext();
- if (Runtime::Current()->IsActiveTransaction()) {
- list_->SetPendingNext<true>(next);
- } else {
- list_->SetPendingNext<false>(next);
- }
+ list_->SetPendingNext(next);
ref = head;
}
- if (Runtime::Current()->IsActiveTransaction()) {
- ref->SetPendingNext<true>(nullptr);
- } else {
- ref->SetPendingNext<false>(nullptr);
- }
+ ref->SetPendingNext(nullptr);
Heap* heap = Runtime::Current()->GetHeap();
if (kUseBakerOrBrooksReadBarrier && heap->CurrentCollectorType() == kCollectorTypeCC &&
heap->ConcurrentCopyingCollector()->IsActive()) {
diff --git a/runtime/mirror/reference.h b/runtime/mirror/reference.h
index 51ae760..5e467ab 100644
--- a/runtime/mirror/reference.h
+++ b/runtime/mirror/reference.h
@@ -22,6 +22,7 @@
#include "object.h"
#include "object_callbacks.h"
#include "read_barrier_option.h"
+#include "runtime.h"
#include "thread.h"
namespace art {
@@ -80,9 +81,14 @@
Reference* GetPendingNext() SHARED_REQUIRES(Locks::mutator_lock_) {
return GetFieldObject<Reference>(PendingNextOffset());
}
- template<bool kTransactionActive>
- void SetPendingNext(Reference* pending_next) SHARED_REQUIRES(Locks::mutator_lock_) {
- SetFieldObject<kTransactionActive>(PendingNextOffset(), pending_next);
+
+ void SetPendingNext(Reference* pending_next)
+ SHARED_REQUIRES(Locks::mutator_lock_) {
+ if (Runtime::Current()->IsActiveTransaction()) {
+ SetFieldObject<true>(PendingNextOffset(), pending_next);
+ } else {
+ SetFieldObject<false>(PendingNextOffset(), pending_next);
+ }
}
bool IsEnqueued() SHARED_REQUIRES(Locks::mutator_lock_) {