Rename AttachCurrentThreadIfNeeded to avoid clash with function.
A function with the same name exists here [1]. If the two headers are included
together this causes compilation errors.
[1] - https://cs.chromium.org/chromium/src/third_party/webrtc/sdk/android/src/jni/jvm.h?l=27&rcl=82f96e6a56e6230e98ee70de5178d7de69795c26
Bug: None
Change-Id: Icbc680f24a02ec66ea2b5e2b6584a53042cf45c7
Reviewed-on: https://webrtc-review.googlesource.com/c/116662
Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#26229}
diff --git a/modules/audio_device/android/audio_manager.h b/modules/audio_device/android/audio_manager.h
index d2d0eb6..685603d 100644
--- a/modules/audio_device/android/audio_manager.h
+++ b/modules/audio_device/android/audio_manager.h
@@ -162,9 +162,10 @@
// other methods are called from the same thread.
rtc::ThreadChecker thread_checker_;
- // Calls AttachCurrentThread() if this thread is not attached at construction.
+ // Calls JavaVM::AttachCurrentThread() if this thread is not attached at
+ // construction.
// Also ensures that DetachCurrentThread() is called at destruction.
- AttachCurrentThreadIfNeeded attach_thread_if_needed_;
+ JvmThreadConnector attach_thread_if_needed_;
// Wraps the JNI interface pointer and methods associated with it.
std::unique_ptr<JNIEnvironment> j_environment_;
diff --git a/modules/audio_device/android/audio_record_jni.h b/modules/audio_device/android/audio_record_jni.h
index a700a51..28c8fc4 100644
--- a/modules/audio_device/android/audio_record_jni.h
+++ b/modules/audio_device/android/audio_record_jni.h
@@ -39,7 +39,7 @@
// All public methods must also be called on the same thread. A thread checker
// will RTC_DCHECK if any method is called on an invalid thread.
//
-// This class uses AttachCurrentThreadIfNeeded to attach to a Java VM if needed
+// This class uses JvmThreadConnector to attach to a Java VM if needed
// and detach when the object goes out of scope. Additional thread checking
// guarantees that no other (possibly non attached) thread is used.
class AudioRecordJni {
@@ -116,9 +116,10 @@
// thread in Java. Detached during construction of this object.
rtc::ThreadChecker thread_checker_java_;
- // Calls AttachCurrentThread() if this thread is not attached at construction.
+ // Calls JavaVM::AttachCurrentThread() if this thread is not attached at
+ // construction.
// Also ensures that DetachCurrentThread() is called at destruction.
- AttachCurrentThreadIfNeeded attach_thread_if_needed_;
+ JvmThreadConnector attach_thread_if_needed_;
// Wraps the JNI interface pointer and methods associated with it.
std::unique_ptr<JNIEnvironment> j_environment_;
diff --git a/modules/audio_device/android/audio_track_jni.h b/modules/audio_device/android/audio_track_jni.h
index 469aa82..ccbdbe2 100644
--- a/modules/audio_device/android/audio_track_jni.h
+++ b/modules/audio_device/android/audio_track_jni.h
@@ -35,7 +35,7 @@
// All public methods must also be called on the same thread. A thread checker
// will RTC_DCHECK if any method is called on an invalid thread.
//
-// This class uses AttachCurrentThreadIfNeeded to attach to a Java VM if needed
+// This class uses JvmThreadConnector to attach to a Java VM if needed
// and detach when the object goes out of scope. Additional thread checking
// guarantees that no other (possibly non attached) thread is used.
class AudioTrackJni {
@@ -114,9 +114,10 @@
// thread in Java. Detached during construction of this object.
rtc::ThreadChecker thread_checker_java_;
- // Calls AttachCurrentThread() if this thread is not attached at construction.
+ // Calls JavaVM::AttachCurrentThread() if this thread is not attached at
+ // construction.
// Also ensures that DetachCurrentThread() is called at destruction.
- AttachCurrentThreadIfNeeded attach_thread_if_needed_;
+ JvmThreadConnector attach_thread_if_needed_;
// Wraps the JNI interface pointer and methods associated with it.
std::unique_ptr<JNIEnvironment> j_environment_;
diff --git a/modules/audio_device/android/build_info.h b/modules/audio_device/android/build_info.h
index 2e292e8..7cdf192 100644
--- a/modules/audio_device/android/build_info.h
+++ b/modules/audio_device/android/build_info.h
@@ -69,7 +69,7 @@
// Ensures that this class can access a valid JNI interface pointer even
// if the creating thread was not attached to the JVM.
- AttachCurrentThreadIfNeeded attach_thread_if_needed_;
+ JvmThreadConnector attach_thread_if_needed_;
// Provides access to the JNIEnv interface pointer and the JavaToStdString()
// method which is used to translate Java strings to std strings.
diff --git a/modules/utility/include/jvm_android.h b/modules/utility/include/jvm_android.h
index eb18cc2..3caab87 100644
--- a/modules/utility/include/jvm_android.h
+++ b/modules/utility/include/jvm_android.h
@@ -21,15 +21,17 @@
namespace webrtc {
+// RAII JavaVM AttachCurrentThread/DetachCurrentThread object.
+//
// The JNI interface pointer (JNIEnv) is valid only in the current thread.
// Should another thread need to access the Java VM, it must first call
// AttachCurrentThread() to attach itself to the VM and obtain a JNI interface
// pointer. The native thread remains attached to the VM until it calls
// DetachCurrentThread() to detach.
-class AttachCurrentThreadIfNeeded {
+class JvmThreadConnector {
public:
- AttachCurrentThreadIfNeeded();
- ~AttachCurrentThreadIfNeeded();
+ JvmThreadConnector();
+ ~JvmThreadConnector();
private:
rtc::ThreadChecker thread_checker_;
diff --git a/modules/utility/source/jvm_android.cc b/modules/utility/source/jvm_android.cc
index 2d48c2d..c861c43 100644
--- a/modules/utility/source/jvm_android.cc
+++ b/modules/utility/source/jvm_android.cc
@@ -67,9 +67,9 @@
return 0;
}
-// AttachCurrentThreadIfNeeded implementation.
-AttachCurrentThreadIfNeeded::AttachCurrentThreadIfNeeded() : attached_(false) {
- RTC_LOG(INFO) << "AttachCurrentThreadIfNeeded::ctor";
+// JvmThreadConnector implementation.
+JvmThreadConnector::JvmThreadConnector() : attached_(false) {
+ RTC_LOG(INFO) << "JvmThreadConnector::ctor";
JavaVM* jvm = JVM::GetInstance()->jvm();
RTC_CHECK(jvm);
JNIEnv* jni = GetEnv(jvm);
@@ -81,8 +81,8 @@
}
}
-AttachCurrentThreadIfNeeded::~AttachCurrentThreadIfNeeded() {
- RTC_LOG(INFO) << "AttachCurrentThreadIfNeeded::dtor";
+JvmThreadConnector::~JvmThreadConnector() {
+ RTC_LOG(INFO) << "JvmThreadConnector::dtor";
RTC_DCHECK(thread_checker_.CalledOnValidThread());
if (attached_) {
RTC_LOG(INFO) << "Detaching thread from JVM";