Android: Remove GetThreadInfo()
This CL is part of merging the helper functions for audio and non-audio JNI code. The GetThreadInfo() function is unrelated to JNI and I would prefer not to keep it in a JNI helper file. Also, GetThreadInfo() is a very small function and inlining it makes it simpler and more transparent IMO, as well as removing a lot of unnecessary std::string creations. Bug: webrtc:8689 Change-Id: I7d238fee826d310c0f5343d18b92d0dff864fd6a Reviewed-on: https://webrtc-review.googlesource.com/36302 Reviewed-by: Henrik Andreassson <henrika@webrtc.org> Commit-Queue: Henrik Andreassson <henrika@webrtc.org> Cr-Commit-Position: refs/heads/master@{#21466}
This commit is contained in:
committed by
Commit Bot
parent
0942b36af1
commit
9185bde7ee
@ -9,7 +9,6 @@
|
||||
*/
|
||||
|
||||
#include "modules/utility/include/helpers_android.h"
|
||||
#include "rtc_base/checks.h"
|
||||
|
||||
#include <android/log.h>
|
||||
#include <assert.h>
|
||||
@ -17,6 +16,9 @@
|
||||
#include <stddef.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "rtc_base/checks.h"
|
||||
#include "rtc_base/platform_thread.h"
|
||||
|
||||
#define TAG "HelpersAndroid"
|
||||
#define ALOGD(...) __android_log_print(ANDROID_LOG_DEBUG, TAG, __VA_ARGS__)
|
||||
|
||||
@ -82,19 +84,6 @@ void DeleteGlobalRef(JNIEnv* jni, jobject o) {
|
||||
CHECK_EXCEPTION(jni) << "Error during DeleteGlobalRef";
|
||||
}
|
||||
|
||||
std::string GetThreadId() {
|
||||
char buf[21]; // Big enough to hold a kuint64max plus terminating NULL.
|
||||
int thread_id = gettid();
|
||||
RTC_CHECK_LT(snprintf(buf, sizeof(buf), "%i", thread_id),
|
||||
static_cast<int>(sizeof(buf)))
|
||||
<< "Thread id is bigger than uint64??";
|
||||
return std::string(buf);
|
||||
}
|
||||
|
||||
std::string GetThreadInfo() {
|
||||
return "@[tid=" + GetThreadId() + "]";
|
||||
}
|
||||
|
||||
AttachThreadScoped::AttachThreadScoped(JavaVM* jvm)
|
||||
: attached_(false), jvm_(jvm), env_(NULL) {
|
||||
env_ = GetEnv(jvm);
|
||||
@ -102,7 +91,7 @@ AttachThreadScoped::AttachThreadScoped(JavaVM* jvm)
|
||||
// Adding debug log here so we can track down potential leaks and figure
|
||||
// out why we sometimes see "Native thread exiting without having called
|
||||
// DetachCurrentThread" in logcat outputs.
|
||||
ALOGD("Attaching thread to JVM%s", GetThreadInfo().c_str());
|
||||
ALOGD("Attaching thread to JVM[tid=%d]", rtc::CurrentThreadId());
|
||||
jint res = jvm->AttachCurrentThread(&env_, NULL);
|
||||
attached_ = (res == JNI_OK);
|
||||
RTC_CHECK(attached_) << "AttachCurrentThread failed: " << res;
|
||||
@ -111,7 +100,7 @@ AttachThreadScoped::AttachThreadScoped(JavaVM* jvm)
|
||||
|
||||
AttachThreadScoped::~AttachThreadScoped() {
|
||||
if (attached_) {
|
||||
ALOGD("Detaching thread from JVM%s", GetThreadInfo().c_str());
|
||||
ALOGD("Detaching thread from JVM[tid=%d]", rtc::CurrentThreadId());
|
||||
jint res = jvm_->DetachCurrentThread();
|
||||
RTC_CHECK(res == JNI_OK) << "DetachCurrentThread failed: " << res;
|
||||
RTC_CHECK(!GetEnv(jvm_));
|
||||
|
||||
Reference in New Issue
Block a user