summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorJaikumar Ganesh <jaikumar@google.com>2010-03-31 18:36:35 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2010-03-31 18:36:35 -0700
commit3a0d1d11eba05d74d0461083eb6f31321588a0f6 (patch)
treec68661dc753bed0deb9739cbad366c4d998a2729 /core
parent058e385b8bca0376c27a24a54f3b00777ef30e0a (diff)
parentb8aa037602eff1fe5fbc9cce07a6f9bc34d19a3e (diff)
downloadframeworks_base-3a0d1d11eba05d74d0461083eb6f31321588a0f6.zip
frameworks_base-3a0d1d11eba05d74d0461083eb6f31321588a0f6.tar.gz
frameworks_base-3a0d1d11eba05d74d0461083eb6f31321588a0f6.tar.bz2
Merge "Fix crash while turning bluetooth on, due to a race condition." into froyo
Diffstat (limited to 'core')
-rw-r--r--core/jni/android_bluetooth_common.h2
-rw-r--r--core/jni/android_server_BluetoothEventLoop.cpp9
2 files changed, 9 insertions, 2 deletions
diff --git a/core/jni/android_bluetooth_common.h b/core/jni/android_bluetooth_common.h
index ef9b66b..378bb6f 100644
--- a/core/jni/android_bluetooth_common.h
+++ b/core/jni/android_bluetooth_common.h
@@ -88,6 +88,8 @@ struct event_loop_native_data_t {
int envVer;
/* reference to our java self */
jobject me;
+ /* flag to indicate if the event loop thread is running */
+ bool running;
};
struct _Properties {
diff --git a/core/jni/android_server_BluetoothEventLoop.cpp b/core/jni/android_server_BluetoothEventLoop.cpp
index 0e7fd66..259cc01 100644
--- a/core/jni/android_server_BluetoothEventLoop.cpp
+++ b/core/jni/android_server_BluetoothEventLoop.cpp
@@ -548,6 +548,8 @@ static void *eventLoopMain(void *ptr) {
dbus_connection_set_watch_functions(nat->conn, dbusAddWatch,
dbusRemoveWatch, dbusToggleWatch, ptr, NULL);
+ nat->running = true;
+
while (1) {
for (int i = 0; i < nat->pollMemberCount; i++) {
if (!nat->pollData[i].revents) {
@@ -591,7 +593,7 @@ static void *eventLoopMain(void *ptr) {
break;
}
}
- while (dbus_connection_dispatch(nat->conn) ==
+ while (dbus_connection_dispatch(nat->conn) ==
DBUS_DISPATCH_DATA_REMAINS) {
}
@@ -607,6 +609,8 @@ static jboolean startEventLoopNative(JNIEnv *env, jobject object) {
pthread_mutex_lock(&(nat->thread_mutex));
+ nat->running = false;
+
if (nat->pollData) {
LOGW("trying to start EventLoop a second time!");
pthread_mutex_unlock( &(nat->thread_mutex) );
@@ -703,6 +707,7 @@ static void stopEventLoopNative(JNIEnv *env, jobject object) {
nat->controlFdW = 0;
close(fd);
}
+ nat->running = false;
pthread_mutex_unlock(&(nat->thread_mutex));
#endif // HAVE_BLUETOOTH
}
@@ -713,7 +718,7 @@ static jboolean isEventLoopRunningNative(JNIEnv *env, jobject object) {
native_data_t *nat = get_native_data(env, object);
pthread_mutex_lock(&(nat->thread_mutex));
- if (nat->pollData) {
+ if (nat->running) {
result = JNI_TRUE;
}
pthread_mutex_unlock(&(nat->thread_mutex));