diff options
author | Mattias Agren <magren@broadcom.com> | 2012-09-28 12:23:32 +0200 |
---|---|---|
committer | Matthew Xie <mattx@google.com> | 2012-09-30 14:54:21 -0700 |
commit | e17b17787c56975507b9081033c75b40d9ac8556 (patch) | |
tree | bd39b66aa9d7d2dc42ff51d2adc0789893da3e0a /gki | |
parent | ac895da1906fa13905f9039a2af1e4c4ac6dc5a7 (diff) | |
download | external_bluetooth_bluedroid-e17b17787c56975507b9081033c75b40d9ac8556.zip external_bluetooth_bluedroid-e17b17787c56975507b9081033c75b40d9ac8556.tar.gz external_bluetooth_bluedroid-e17b17787c56975507b9081033c75b40d9ac8556.tar.bz2 |
Ensure timer thread stops when inactivity timer expires
Bug 7243062
Change-Id: Ib9d85f65adce364f5a75c85d3cc55ab387a8efd5
Diffstat (limited to 'gki')
-rwxr-xr-x | gki/ulinux/gki_ulinux.c | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/gki/ulinux/gki_ulinux.c b/gki/ulinux/gki_ulinux.c index e4e0323..4d30bbb 100755 --- a/gki/ulinux/gki_ulinux.c +++ b/gki/ulinux/gki_ulinux.c @@ -199,7 +199,9 @@ void GKI_init(void) * this works too even if GKI_NO_TICK_STOP is defined in btld.txt */ p_os->no_timer_suspend = GKI_TIMER_TICK_RUN_COND; pthread_mutex_init(&p_os->gki_timer_mutex, NULL); +#ifndef NO_GKI_RUN_RETURN pthread_cond_init(&p_os->gki_timer_cond, NULL); +#endif } @@ -543,19 +545,28 @@ void gki_system_tick_start_stop_cback(BOOLEAN start) tGKI_OS *p_os = &gki_cb.os; int *p_run_cond = &p_os->no_timer_suspend; static int wake_lock_count; + if ( FALSE == start ) { - /* this can lead to a race condition. however as we only read this variable in the timer loop - * we should be fine with this approach. otherwise uncomment below mutexes. - */ - /* GKI_disable(); */ - *p_run_cond = GKI_TIMER_TICK_STOP_COND; - /* GKI_enable(); */ + /* gki_system_tick_start_stop_cback() maybe called even so it was already stopped! */ + if (GKI_TIMER_TICK_RUN_COND == *p_run_cond) + { +#ifdef NO_GKI_RUN_RETURN + /* take free mutex to block timer thread */ + pthread_mutex_lock(&p_os->gki_timer_mutex); +#endif + /* this can lead to a race condition. however as we only read this variable in the + * timer loop we should be fine with this approach. otherwise uncomment below mutexes. + */ + /* GKI_disable(); */ + *p_run_cond = GKI_TIMER_TICK_STOP_COND; + /* GKI_enable(); */ - GKI_TIMER_TRACE(">>> STOP GKI_timer_update(), wake_lock_count:%d", --wake_lock_count); + GKI_TIMER_TRACE(">>> STOP GKI_timer_update(), wake_lock_count:%d", --wake_lock_count); - release_wake_lock(WAKE_LOCK_ID); - g_GkiTimerWakeLockOn = 0; + release_wake_lock(WAKE_LOCK_ID); + g_GkiTimerWakeLockOn = 0; + } } else { @@ -565,9 +576,13 @@ void gki_system_tick_start_stop_cback(BOOLEAN start) g_GkiTimerWakeLockOn = 1; *p_run_cond = GKI_TIMER_TICK_RUN_COND; +#ifdef NO_GKI_RUN_RETURN + pthread_mutex_unlock( &p_os->gki_timer_mutex ); +#else pthread_mutex_lock( &p_os->gki_timer_mutex ); pthread_cond_signal( &p_os->gki_timer_cond ); pthread_mutex_unlock( &p_os->gki_timer_mutex ); +#endif GKI_TIMER_TRACE(">>> START GKI_timer_update(), wake_lock_count:%d", ++wake_lock_count ); } |