src/counter.c \
src/device_class.c \
src/module.c \
+ src/osi_module.c \
src/property.c \
src/uuid.c
--- /dev/null
+/******************************************************************************
+ *
+ * Copyright (C) 2015 Google, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************/
+
+#pragma once
+
+static const char OSI_MODULE[] = "osi_module";
--- /dev/null
+/******************************************************************************
+ *
+ * Copyright (C) 2015 Google, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************/
+
+#define LOG_TAG "bt_osi_module"
+
+#include "btcore/include/module.h"
+#include "btcore/include/osi_module.h"
+#include "osi/include/alarm.h"
+#include "osi/include/future.h"
+#include "osi/include/log.h"
+#include "osi/include/osi.h"
+
+future_t *osi_start_up(void) {
+ return NULL;
+}
+
+future_t *osi_shut_down(void) {
+ alarm_shutdown();
+ 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,
+ .dependencies = {NULL}
+};
#include "btif_common.h"
#include "device/include/controller.h"
#include "btcore/include/module.h"
+#include "btcore/include/osi_module.h"
#include "osi/include/osi.h"
#include "osi/include/log.h"
#include "osi/include/semaphore.h"
LOG_DEBUG("%s is bringing up the stack.", __func__);
hack_future = future_new();
+ module_start_up(get_module(OSI_MODULE));
// Include this for now to put btif config into a shutdown-able state
module_start_up(get_module(BTIF_CONFIG_MODULE));
bte_main_enable();
future_await(hack_future);
module_shut_down(get_module(CONTROLLER_MODULE)); // Doesn't do any work, just puts it in a restartable state
+ module_shut_down(get_module(OSI_MODULE));
+
LOG_DEBUG("%s finished.", __func__);
btif_thread_post(event_signal_stack_down, NULL);
}
#include "btsnoop.h"
#include "bt_utils.h"
#include "btcore/include/counter.h"
+#include "btcore/include/module.h"
#include "osi/include/fixed_queue.h"
#include "osi/include/future.h"
#include "gki.h"
#include "osi/include/hash_functions.h"
#include "osi/include/hash_map.h"
#include "hci_layer.h"
-#include "btcore/include/module.h"
#include "osi/include/osi.h"
#include "osi/include/log.h"
#include "stack_config.h"
// will not be called if it hasn't already been called. This function is idempotent.
// |alarm| may not be NULL.
void alarm_cancel(alarm_t *alarm);
+
+// Shuts down the alarm dispatch callback. To be called during module/stack
+// shutdown only.
+void alarm_shutdown(void);
// All alarm callbacks are dispatched from |callback_thread|
static thread_t *callback_thread;
+static bool callback_thread_active;
static semaphore_t *alarm_expired;
static bool lazy_initialize(void);
pthread_mutex_unlock(&alarm->callback_lock);
}
+void alarm_shutdown(void) {
+ callback_thread_active = false;
+ semaphore_post(alarm_expired);
+ thread_free(callback_thread);
+ callback_thread = NULL;
+
+ semaphore_free(alarm_expired);
+ alarm_expired = NULL;
+ timer_delete(&timer);
+
+ list_free(alarms);
+ alarms = NULL;
+
+ pthread_mutex_destroy(&monitor);
+}
+
static bool lazy_initialize(void) {
assert(alarms == NULL);
return false;
}
+ callback_thread_active = true;
callback_thread = thread_new("alarm_callbacks");
if (!callback_thread) {
LOG_ERROR("%s unable to create alarm callback thread.", __func__);
static void callback_dispatch(UNUSED_ATTR void *context) {
while (true) {
semaphore_wait(alarm_expired);
- pthread_mutex_lock(&monitor);
+ if (!callback_thread_active)
+ break;
+ pthread_mutex_lock(&monitor);
alarm_t *alarm;
// Take into account that the alarm may get cancelled before we get to it.
pthread_mutex_unlock(&alarm->callback_lock);
}
+
+ LOG_DEBUG("%s Callback thread exited", __func__);
}