summaryrefslogtreecommitdiffstats
path: root/osi
diff options
context:
space:
mode:
authorAndre Eisenbach <eisenbach@google.com>2015-05-18 09:41:06 -0700
committerAndre Eisenbach <eisenbach@google.com>2015-05-18 14:20:31 -0700
commit3e3d2a1d3bb9ada4fa612bf9d58c05b629385af2 (patch)
treeb64e22caa7ccc0a62b6c28b6d012519a31bdfd1c /osi
parent1287166da9c34f041d54a78800b79cb2738675a9 (diff)
downloadandroid_system_bt-3e3d2a1d3bb9ada4fa612bf9d58c05b629385af2.tar.gz
android_system_bt-3e3d2a1d3bb9ada4fa612bf9d58c05b629385af2.tar.bz2
android_system_bt-3e3d2a1d3bb9ada4fa612bf9d58c05b629385af2.zip
Shutdown alarm callbacks on stack disable; added OSI module
Change-Id: Iecf1e2258da012bdac69a4f57d38b12a272e3edd
Diffstat (limited to 'osi')
-rw-r--r--osi/Android.mk4
-rw-r--r--osi/include/alarm.h4
-rw-r--r--osi/src/alarm.c24
3 files changed, 29 insertions, 3 deletions
diff --git a/osi/Android.mk b/osi/Android.mk
index 537e91d11..52dc2cf84 100644
--- a/osi/Android.mk
+++ b/osi/Android.mk
@@ -48,7 +48,7 @@ LOCAL_SRC_FILES := \
./src/socket.c \
./src/thread.c
-LOCAL_CFLAGS := -std=c99 -Wall -Werror
+LOCAL_CFLAGS := -std=c99 -Wall -Werror -UNDEBUG
# Many .h files have redefined typedefs
LOCAL_CLANG_CFLAGS += -Wno-error=typedef-redefinition
LOCAL_MODULE := libosi
@@ -86,7 +86,7 @@ LOCAL_SRC_FILES := \
./test/ringbuffer_test.cpp \
./test/thread_test.cpp
-LOCAL_CFLAGS := -Wall
+LOCAL_CFLAGS := -Wall -UNDEBUG
LOCAL_MODULE := net_test_osi
LOCAL_MODULE_TAGS := tests
LOCAL_SHARED_LIBRARIES := liblog
diff --git a/osi/include/alarm.h b/osi/include/alarm.h
index b27e9a4f9..5a372dc57 100644
--- a/osi/include/alarm.h
+++ b/osi/include/alarm.h
@@ -51,3 +51,7 @@ void alarm_set_periodic(alarm_t *alarm, period_ms_t period, alarm_callback_t cb,
// 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);
diff --git a/osi/src/alarm.c b/osi/src/alarm.c
index 55b65d2ee..5730babfe 100644
--- a/osi/src/alarm.c
+++ b/osi/src/alarm.c
@@ -70,6 +70,7 @@ static bool timer_set;
// 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);
@@ -176,6 +177,22 @@ void alarm_cancel(alarm_t *alarm) {
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);
@@ -202,6 +219,7 @@ static bool lazy_initialize(void) {
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__);
@@ -322,8 +340,10 @@ static void timer_callback(UNUSED_ATTR void *ptr) {
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.
@@ -359,4 +379,6 @@ static void callback_dispatch(UNUSED_ATTR void *context) {
pthread_mutex_unlock(&alarm->callback_lock);
}
+
+ LOG_DEBUG("%s Callback thread exited", __func__);
}