From e17b17787c56975507b9081033c75b40d9ac8556 Mon Sep 17 00:00:00 2001 From: Mattias Agren Date: Fri, 28 Sep 2012 12:23:32 +0200 Subject: Ensure timer thread stops when inactivity timer expires Bug 7243062 Change-Id: Ib9d85f65adce364f5a75c85d3cc55ab387a8efd5 --- gki/ulinux/gki_ulinux.c | 33 ++++++++++++++++++++++++--------- 1 file 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 ); } -- cgit v1.1