Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(47)

Side by Side Diff: webrtc/sdk/android/src/jni/jni_helpers.cc

Issue 3003213002: Android: Add common function for adding/releasing native reference (Closed)
Patch Set: Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. 2 * Copyright 2015 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 #include "webrtc/sdk/android/src/jni/jni_helpers.h" 10 #include "webrtc/sdk/android/src/jni/jni_helpers.h"
11 11
12 #include "webrtc/sdk/android/src/jni/classreferenceholder.h"
13
14 #include <asm/unistd.h> 12 #include <asm/unistd.h>
15 #include <sys/prctl.h> 13 #include <sys/prctl.h>
16 #include <sys/syscall.h> 14 #include <sys/syscall.h>
17 #include <unistd.h> 15 #include <unistd.h>
18 #include <vector> 16 #include <vector>
19 17
18 #include "webrtc/rtc_base/refcount.h"
19 #include "webrtc/sdk/android/src/jni/classreferenceholder.h"
20
20 namespace webrtc_jni { 21 namespace webrtc_jni {
21 22
22 static JavaVM* g_jvm = nullptr; 23 static JavaVM* g_jvm = nullptr;
23 24
24 static pthread_once_t g_jni_ptr_once = PTHREAD_ONCE_INIT; 25 static pthread_once_t g_jni_ptr_once = PTHREAD_ONCE_INIT;
25 26
26 // Key for per-thread JNIEnv* data. Non-NULL in threads attached to |g_jvm| by 27 // Key for per-thread JNIEnv* data. Non-NULL in threads attached to |g_jvm| by
27 // AttachCurrentThreadIfNeeded(), NULL in unattached threads and threads that 28 // AttachCurrentThreadIfNeeded(), NULL in unattached threads and threads that
28 // were attached by the JVM because of a Java->native call. 29 // were attached by the JVM because of a Java->native call.
29 static pthread_key_t g_jni_ptr; 30 static pthread_key_t g_jni_ptr;
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 jobject Iterable::Iterator::operator*() { 379 jobject Iterable::Iterator::operator*() {
379 RTC_CHECK(!AtEnd()); 380 RTC_CHECK(!AtEnd());
380 return value_; 381 return value_;
381 } 382 }
382 383
383 bool Iterable::Iterator::AtEnd() const { 384 bool Iterable::Iterator::AtEnd() const {
384 RTC_CHECK(thread_checker_.CalledOnValidThread()); 385 RTC_CHECK(thread_checker_.CalledOnValidThread());
385 return jni_ == nullptr || IsNull(jni_, iterator_); 386 return jni_ == nullptr || IsNull(jni_, iterator_);
386 } 387 }
387 388
389 JOW(void, JniCommon_nativeAddRef)
sakal 2017/08/25 13:19:39 nit: I don't really like adding these here, can yo
magjed_webrtc 2017/08/27 20:44:32 Done.
390 (JNIEnv* jni, jclass, jlong j_native_ref_counted_pointer) {
391 reinterpret_cast<rtc::RefCountInterface*>(j_native_ref_counted_pointer)
392 ->AddRef();
393 }
394
395 JOW(void, JniCommon_nativeReleaseRef)
396 (JNIEnv* jni, jclass, jlong j_native_ref_counted_pointer) {
397 reinterpret_cast<rtc::RefCountInterface*>(j_native_ref_counted_pointer)
398 ->Release();
399 }
400
388 } // namespace webrtc_jni 401 } // namespace webrtc_jni
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698