diff options
author | Zach Johnson <zachoverflow@google.com> | 2015-03-11 01:55:27 -0700 |
---|---|---|
committer | Andre Eisenbach <eisenbach@google.com> | 2015-03-16 16:51:48 -0700 |
commit | 71864f490d4dc31857df0b31924cd62a337e9f1a (patch) | |
tree | 7ff3676bca24b790a2b59bcb0f77fe8b6b1ca31b /btif | |
parent | d44d6401d2c0e0309f0d28a1412c295ea9fa6d7e (diff) | |
download | android_system_bt-71864f490d4dc31857df0b31924cd62a337e9f1a.tar.gz android_system_bt-71864f490d4dc31857df0b31924cd62a337e9f1a.tar.bz2 android_system_bt-71864f490d4dc31857df0b31924cd62a337e9f1a.zip |
Add ability to set periodic alarms
Adds alarm_set_periodic so the alarm code can have more
contextual information when rescheduling alarms.
Problem: A2DP would stream for a few seconds and then
stop working.
Cause: The Java garbage collector. Bluedroid reaches out
to javaland to acquire and release the wake lock. Alarm was
always reaching out to get the wake lock when it scheduled a
short timeout. If GC kicked in during that call out to make
sure we have the wake lock, it could take more than 100ms to
get back us. That would screw over the alarm implementation
particularly for small 20ms timers.
So now if the wake lock was already acquired, we don't try to
reacquire it.
Cool. But we still have thrashing. Why? Because the alarm code
doesn't know the alarm is actually being used in a periodic way.
Here's what used to happen:
alarm expires
alarm is removed
reschedule
alarm callback is called
alarm callback sets the alarm again
alarm is added
reschedule
The problem is the first reschedule will get rid of the wake lock
if the next alarm is too far out or doesn't exist, meaning the next
reschedule needs to get the wake lock again.
With the extra periodicity information we can eliminate the
unnecessary intermediate reschedule, meaning no thrashing on the
wake lock. yay!
Diffstat (limited to 'btif')
-rw-r--r-- | btif/src/btif_media_task.c | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/btif/src/btif_media_task.c b/btif/src/btif_media_task.c index 1a03b6a3a..30ef3a4cd 100644 --- a/btif/src/btif_media_task.c +++ b/btif/src/btif_media_task.c @@ -1899,11 +1899,10 @@ void btif_a2dp_set_peer_sep(UINT8 sep) { static void btif_decode_alarm_cb(UNUSED_ATTR void *context) { thread_post(worker_thread, btif_media_task_avk_handle_timer, NULL); - alarm_set(btif_media_cb.decode_alarm, BTIF_SINK_MEDIA_TIME_TICK, btif_decode_alarm_cb, NULL); } static void btif_media_task_aa_handle_stop_decoding(void) { - alarm_cancel(btif_media_cb.decode_alarm); + alarm_free(btif_media_cb.decode_alarm); btif_media_cb.decode_alarm = NULL; } @@ -1917,7 +1916,7 @@ static void btif_media_task_aa_handle_start_decoding(void) { return; } - alarm_set(btif_media_cb.decode_alarm, BTIF_SINK_MEDIA_TIME_TICK, btif_decode_alarm_cb, NULL); + alarm_set_periodic(btif_media_cb.decode_alarm, BTIF_SINK_MEDIA_TIME_TICK, btif_decode_alarm_cb, NULL); } #if (BTA_AV_SINK_INCLUDED == TRUE) @@ -2098,7 +2097,6 @@ static void btif_media_task_feeding_state_reset(void) static void btif_media_task_alarm_cb(UNUSED_ATTR void *context) { thread_post(worker_thread, btif_media_task_aa_handle_timer, NULL); - alarm_set(btif_media_cb.media_alarm, BTIF_MEDIA_TIME_TICK, btif_media_task_alarm_cb, NULL); } /******************************************************************************* @@ -2134,7 +2132,7 @@ static void btif_media_task_aa_start_tx(void) return; } - alarm_set(btif_media_cb.media_alarm, BTIF_MEDIA_TIME_TICK, btif_media_task_alarm_cb, NULL); + alarm_set_periodic(btif_media_cb.media_alarm, BTIF_MEDIA_TIME_TICK, btif_media_task_alarm_cb, NULL); } /******************************************************************************* |