OSDN Git Service

Add missing clean_up step for the OSI module.
authorPavlin Radoslavov <pavlin@google.com>
Sat, 23 May 2015 02:47:49 +0000 (19:47 -0700)
committerPavlin Radoslavov <pavlin@google.com>
Thu, 28 May 2015 16:34:32 +0000 (16:34 +0000)
Now the OSI module's shut_down processing is split into "shut_down"
and "clean_up".

Previously, there was an ordering issue manipulating some of the
internal state during graceful shutdown/cleanup. Some of the modules
had two steps: shut_down, followed by clean_up, while other had only
shut_down step. This triggered the following assert in file alarm.c

    alarm_cancel: assertion "alarms != NULL" failed

Bug: 21406940
Change-Id: Iab1f033a69cbff646a6b0f346760ae82f8b00b8f

btcore/src/osi_module.c
btif/src/stack_manager.c
osi/include/alarm.h
osi/src/alarm.c
osi/test/AlarmTestHarness.cpp

index 40c27d5..a9fff61 100644 (file)
@@ -34,11 +34,16 @@ future_t *osi_shut_down(void) {
   return NULL;
 }
 
+future_t *osi_clean_up(void) {
+  alarm_cleanup();
+  return NULL;
+}
+
 const module_t osi_module = {
   .name = OSI_MODULE,
   .init = NULL,
   .start_up = osi_start_up,
   .shut_down = osi_shut_down,
-  .clean_up = NULL,
+  .clean_up = osi_clean_up,
   .dependencies = {NULL}
 };
index 3b64648..2fa8fc3 100644 (file)
@@ -186,6 +186,7 @@ static void event_clean_up_stack(UNUSED_ATTR void *context) {
 
   btif_shutdown_bluetooth();
   module_clean_up(get_module(BTIF_CONFIG_MODULE));
+  module_clean_up(get_module(OSI_MODULE));
   module_clean_up(get_module(BT_UTILS_MODULE));
 
   future_await(hack_future);
index 5a372dc..470c482 100644 (file)
@@ -55,3 +55,6 @@ void alarm_cancel(alarm_t *alarm);
 // Shuts down the alarm dispatch callback. To be called during module/stack
 // shutdown only.
 void alarm_shutdown(void);
+
+// Alarm-related state cleanup
+void alarm_cleanup(void);
index 6a10b83..1ec090f 100644 (file)
@@ -190,6 +190,12 @@ void alarm_shutdown(void) {
   semaphore_free(alarm_expired);
   alarm_expired = NULL;
   timer_delete(&timer);
+}
+
+void alarm_cleanup(void) {
+  // If lazy_initialize never ran there is nothing to do
+  if (!alarms)
+    return;
 
   list_free(alarms);
   alarms = NULL;
index ce7a62f..98b25af 100644 (file)
@@ -53,6 +53,7 @@ void AlarmTestHarness::SetUp() {
 
 void AlarmTestHarness::TearDown() {
   alarm_shutdown();
+  alarm_cleanup();
   timer_delete(timer);
   AllocationTestHarness::TearDown();
 }