OSDN Git Service

Add back timer list entry in_use field
authorChris Manton <cmanton@google.com>
Wed, 17 Sep 2014 20:30:13 +0000 (13:30 -0700)
committerAndre Eisenbach <eisenbach@google.com>
Mon, 16 Mar 2015 23:51:34 +0000 (16:51 -0700)
I thought this field was used for internal
bookkeeping, but it turns the higher layer
protocols use it to condition if a timer
should be started or stopped.

stack/btu/btu_task.c

index 157d0c2..3daa167 100644 (file)
@@ -670,6 +670,9 @@ void btu_start_timer(TIMER_LIST_ENT *p_tle, UINT16 type, UINT32 timeout_sec) {
   p_tle->event = type;
   // NOTE: This value is in seconds but stored in a ticks field.
   p_tle->ticks = timeout_sec;
+  if (p_tle->in_use == TRUE)
+    ALOGW("%s Starting alarm already in use\n", __func__);
+  p_tle->in_use = TRUE;
   alarm_set(alarm, (period_ms_t)(timeout_sec * 1000), btu_general_alarm_cb, (void *)p_tle);
 }
 
@@ -699,6 +702,10 @@ UINT32 btu_remaining_time (TIMER_LIST_ENT *p_tle)
 void btu_stop_timer(TIMER_LIST_ENT *p_tle) {
   assert(p_tle != NULL);
 
+  if (p_tle->in_use == FALSE)
+    return;
+  p_tle->in_use = FALSE;
+
   // Get the alarm for the timer list entry.
   alarm_t *alarm = hash_map_get(btu_general_alarm_hash_map, p_tle);
   if (alarm == NULL) {
@@ -759,6 +766,9 @@ void btu_start_quick_timer(TIMER_LIST_ENT *p_tle, UINT16 type, UINT32 timeout_ti
 
   p_tle->event = type;
   p_tle->ticks = timeout_ticks;
+  if (p_tle->in_use == TRUE)
+    ALOGW("%s Starting alarm already in use\n", __func__);
+  p_tle->in_use = TRUE;
   // The quick timer ticks are 100ms long.
   alarm_set(alarm, (period_ms_t)(timeout_ticks * 100), btu_l2cap_alarm_cb, (void *)p_tle);
 }
@@ -775,6 +785,10 @@ void btu_start_quick_timer(TIMER_LIST_ENT *p_tle, UINT16 type, UINT32 timeout_ti
 void btu_stop_quick_timer(TIMER_LIST_ENT *p_tle) {
   assert(p_tle != NULL);
 
+  if (p_tle->in_use == FALSE)
+    return;
+  p_tle->in_use = FALSE;
+
   // Get the alarm for the timer list entry.
   alarm_t *alarm = hash_map_get(btu_l2cap_alarm_hash_map, p_tle);
   if (alarm == NULL) {
@@ -816,6 +830,9 @@ void btu_start_timer_oneshot(TIMER_LIST_ENT *p_tle, UINT16 type, UINT32 timeout_
   alarm_cancel(alarm);
 
   p_tle->event = type;
+  if (p_tle->in_use == TRUE)
+    ALOGW("%s Starting alarm already in use\n", __func__);
+  p_tle->in_use = TRUE;
   // NOTE: This value is in seconds but stored in a ticks field.
   p_tle->ticks = timeout_sec;
   alarm_set(alarm, (period_ms_t)(timeout_sec * 1000), btu_oneshot_alarm_cb, (void *)p_tle);
@@ -824,6 +841,10 @@ void btu_start_timer_oneshot(TIMER_LIST_ENT *p_tle, UINT16 type, UINT32 timeout_
 void btu_stop_timer_oneshot(TIMER_LIST_ENT *p_tle) {
   assert(p_tle != NULL);
 
+  if (p_tle->in_use == FALSE)
+    return;
+  p_tle->in_use = FALSE;
+
   // Get the alarm for the timer list entry.
   alarm_t *alarm = hash_map_get(btu_oneshot_alarm_hash_map, p_tle);
   if (alarm == NULL) {