From 977c82020c09f5b3f01dbadde3f416911f831b6d Mon Sep 17 00:00:00 2001 From: Mirko Bonadei Date: Fri, 11 Jan 2019 19:26:40 +0100 Subject: [PATCH] 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 Reviewed-by: Karl Wiberg Cr-Commit-Position: refs/heads/master@{#26229} --- modules/audio_device/android/audio_manager.h | 5 +++-- modules/audio_device/android/audio_record_jni.h | 7 ++++--- modules/audio_device/android/audio_track_jni.h | 7 ++++--- modules/audio_device/android/build_info.h | 2 +- modules/utility/include/jvm_android.h | 8 +++++--- modules/utility/source/jvm_android.cc | 10 +++++----- 6 files changed, 22 insertions(+), 17 deletions(-) diff --git a/modules/audio_device/android/audio_manager.h b/modules/audio_device/android/audio_manager.h index d2d0eb623b..685603d8c8 100644 --- a/modules/audio_device/android/audio_manager.h +++ b/modules/audio_device/android/audio_manager.h @@ -162,9 +162,10 @@ class AudioManager { // 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 j_environment_; diff --git a/modules/audio_device/android/audio_record_jni.h b/modules/audio_device/android/audio_record_jni.h index a700a51b2b..28c8fc466d 100644 --- a/modules/audio_device/android/audio_record_jni.h +++ b/modules/audio_device/android/audio_record_jni.h @@ -39,7 +39,7 @@ namespace webrtc { // 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 @@ class AudioRecordJni { // 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 j_environment_; diff --git a/modules/audio_device/android/audio_track_jni.h b/modules/audio_device/android/audio_track_jni.h index 469aa82bbd..ccbdbe2794 100644 --- a/modules/audio_device/android/audio_track_jni.h +++ b/modules/audio_device/android/audio_track_jni.h @@ -35,7 +35,7 @@ namespace webrtc { // 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 @@ class AudioTrackJni { // 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 j_environment_; diff --git a/modules/audio_device/android/build_info.h b/modules/audio_device/android/build_info.h index 2e292e8f08..7cdf19271f 100644 --- a/modules/audio_device/android/build_info.h +++ b/modules/audio_device/android/build_info.h @@ -69,7 +69,7 @@ class BuildInfo { // 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 eb18cc27f3..3caab87761 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 2d48c2d7be..c861c433a2 100644 --- a/modules/utility/source/jvm_android.cc +++ b/modules/utility/source/jvm_android.cc @@ -67,9 +67,9 @@ jclass LookUpClass(const char* name) { 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() : attached_(false) { } } -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";