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}
This commit is contained in:
Mirko Bonadei 2019-01-11 19:26:40 +01:00 committed by Commit Bot
parent 07dc1e8594
commit 977c82020c
6 changed files with 22 additions and 17 deletions

View File

@ -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<JNIEnvironment> j_environment_;

View File

@ -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<JNIEnvironment> j_environment_;

View File

@ -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<JNIEnvironment> j_environment_;

View File

@ -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.

View File

@ -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_;

View File

@ -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";