| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/android/java_handler_thread.h" | 5 #include "base/android/java_handler_thread.h" |
| 6 | 6 |
| 7 #include <jni.h> | 7 #include <jni.h> |
| 8 | 8 |
| 9 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
| 10 #include "base/android/jni_string.h" | 10 #include "base/android/jni_string.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 } | 25 } |
| 26 | 26 |
| 27 JavaHandlerThread::~JavaHandlerThread() { | 27 JavaHandlerThread::~JavaHandlerThread() { |
| 28 } | 28 } |
| 29 | 29 |
| 30 void JavaHandlerThread::Start() { | 30 void JavaHandlerThread::Start() { |
| 31 // Check the thread has not already been started. | 31 // Check the thread has not already been started. |
| 32 DCHECK(!message_loop_); | 32 DCHECK(!message_loop_); |
| 33 | 33 |
| 34 JNIEnv* env = base::android::AttachCurrentThread(); | 34 JNIEnv* env = base::android::AttachCurrentThread(); |
| 35 base::WaitableEvent initialize_event(false, false); | 35 base::WaitableEvent initialize_event( |
| 36 WaitableEvent::ResetPolicy::AUTOMATIC, |
| 37 WaitableEvent::InitialState::NOT_SIGNALED); |
| 36 Java_JavaHandlerThread_start(env, | 38 Java_JavaHandlerThread_start(env, |
| 37 java_thread_.obj(), | 39 java_thread_.obj(), |
| 38 reinterpret_cast<intptr_t>(this), | 40 reinterpret_cast<intptr_t>(this), |
| 39 reinterpret_cast<intptr_t>(&initialize_event)); | 41 reinterpret_cast<intptr_t>(&initialize_event)); |
| 40 // Wait for thread to be initialized so it is ready to be used when Start | 42 // Wait for thread to be initialized so it is ready to be used when Start |
| 41 // returns. | 43 // returns. |
| 42 base::ThreadRestrictions::ScopedAllowWait wait_allowed; | 44 base::ThreadRestrictions::ScopedAllowWait wait_allowed; |
| 43 initialize_event.Wait(); | 45 initialize_event.Wait(); |
| 44 } | 46 } |
| 45 | 47 |
| 46 void JavaHandlerThread::Stop() { | 48 void JavaHandlerThread::Stop() { |
| 47 JNIEnv* env = base::android::AttachCurrentThread(); | 49 JNIEnv* env = base::android::AttachCurrentThread(); |
| 48 base::WaitableEvent shutdown_event(false, false); | 50 base::WaitableEvent shutdown_event(WaitableEvent::ResetPolicy::AUTOMATIC, |
| 51 WaitableEvent::InitialState::NOT_SIGNALED); |
| 49 Java_JavaHandlerThread_stop(env, | 52 Java_JavaHandlerThread_stop(env, |
| 50 java_thread_.obj(), | 53 java_thread_.obj(), |
| 51 reinterpret_cast<intptr_t>(this), | 54 reinterpret_cast<intptr_t>(this), |
| 52 reinterpret_cast<intptr_t>(&shutdown_event)); | 55 reinterpret_cast<intptr_t>(&shutdown_event)); |
| 53 // Wait for thread to shut down before returning. | 56 // Wait for thread to shut down before returning. |
| 54 base::ThreadRestrictions::ScopedAllowWait wait_allowed; | 57 base::ThreadRestrictions::ScopedAllowWait wait_allowed; |
| 55 shutdown_event.Wait(); | 58 shutdown_event.Wait(); |
| 56 } | 59 } |
| 57 | 60 |
| 58 void JavaHandlerThread::InitializeThread(JNIEnv* env, | 61 void JavaHandlerThread::InitializeThread(JNIEnv* env, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 71 reinterpret_cast<base::WaitableEvent*>(event)->Signal(); | 74 reinterpret_cast<base::WaitableEvent*>(event)->Signal(); |
| 72 } | 75 } |
| 73 | 76 |
| 74 // static | 77 // static |
| 75 bool JavaHandlerThread::RegisterBindings(JNIEnv* env) { | 78 bool JavaHandlerThread::RegisterBindings(JNIEnv* env) { |
| 76 return RegisterNativesImpl(env); | 79 return RegisterNativesImpl(env); |
| 77 } | 80 } |
| 78 | 81 |
| 79 } // namespace android | 82 } // namespace android |
| 80 } // namespace base | 83 } // namespace base |
| OLD | NEW |