summaryrefslogtreecommitdiff
path: root/osi
diff options
context:
space:
mode:
authorMarie Janssen <jamuraa@google.com>2016-01-29 13:37:12 -0800
committerMarie Janssen <jamuraa@google.com>2016-02-04 20:09:13 +0000
commit1910a80f533ece8669e5f62175422365f8abf270 (patch)
tree47e3ec7116a81d9edf43ab97c1b52e11eb25d942 /osi
parentf94e67c2d96d25f221e0503f334f4a0a277bc68c (diff)
downloadandroid-system-bt-1910a80f533ece8669e5f62175422365f8abf270.tar.gz
android-system-bt-1910a80f533ece8669e5f62175422365f8abf270.tar.xz
osi: add native wakelocks to metrics
Metrics were only being counted for callout wakelocks. Move metrics collection to the wrapping functions to account more centrally. Change-Id: I772198c3ae05bcb83965420931ddee87b1996b6b
Diffstat (limited to 'osi')
-rw-r--r--osi/src/wakelock.c63
1 files changed, 31 insertions, 32 deletions
diff --git a/osi/src/wakelock.c b/osi/src/wakelock.c
index db997e9..dd8b8f7 100644
--- a/osi/src/wakelock.c
+++ b/osi/src/wakelock.c
@@ -71,10 +71,10 @@ static wakelock_stats_t wakelock_stats;
// are executed serially.
static pthread_mutex_t monitor;
-static bool wakelock_acquire_callout(void);
-static bool wakelock_acquire_native(void);
-static bool wakelock_release_callout(void);
-static bool wakelock_release_native(void);
+static bt_status_t wakelock_acquire_callout(void);
+static bt_status_t wakelock_acquire_native(void);
+static bt_status_t wakelock_release_callout(void);
+static bt_status_t wakelock_release_native(void);
static void wakelock_initialize(void);
static void wakelock_initialize_native(void);
static void reset_wakelock_stats(void);
@@ -92,33 +92,34 @@ void wakelock_set_os_callouts(bt_os_callouts_t *callouts)
bool wakelock_acquire(void) {
pthread_once(&initialized, wakelock_initialize);
+ bt_status_t status = BT_STATUS_FAIL;
+
if (is_native)
- return wakelock_acquire_native();
+ status = wakelock_acquire_native();
else
- return wakelock_acquire_callout();
-}
+ status = wakelock_acquire_callout();
-static bool wakelock_acquire_callout(void)
-{
- const bt_status_t status =
- wakelock_os_callouts->acquire_wake_lock(WAKE_LOCK_ID);
update_wakelock_acquired_stats(status);
+
if (status != BT_STATUS_SUCCESS)
LOG_ERROR(LOG_TAG, "%s unable to acquire wake lock: %d", __func__, status);
return (status == BT_STATUS_SUCCESS);
}
-static bool wakelock_acquire_native(void)
-{
+static bt_status_t wakelock_acquire_callout(void) {
+ return wakelock_os_callouts->acquire_wake_lock(WAKE_LOCK_ID);
+}
+
+static bt_status_t wakelock_acquire_native(void) {
if (wake_lock_fd == INVALID_FD) {
LOG_ERROR(LOG_TAG, "%s lock not acquired, invalid fd", __func__);
- return false;
+ return BT_STATUS_PARM_INVALID;
}
if (wake_unlock_fd == INVALID_FD) {
LOG_ERROR(LOG_TAG, "%s not acquiring lock: can't release lock", __func__);
- return false;
+ return BT_STATUS_PARM_INVALID;
}
long lock_name_len = strlen(WAKE_LOCK_ID);
@@ -126,38 +127,38 @@ static bool wakelock_acquire_native(void)
if (locked_id_len == -1) {
LOG_ERROR(LOG_TAG, "%s wake lock not acquired: %s",
__func__, strerror(errno));
- return false;
+ return BT_STATUS_FAIL;
} else if (locked_id_len < lock_name_len) {
// TODO (jamuraa): this is weird. maybe we should release and retry.
LOG_WARN(LOG_TAG, "%s wake lock truncated to %zd chars",
__func__, locked_id_len);
}
- return true;
+ return BT_STATUS_SUCCESS;
}
bool wakelock_release(void) {
pthread_once(&initialized, wakelock_initialize);
+ bt_status_t status = BT_STATUS_FAIL;
+
if (is_native)
- return wakelock_release_native();
+ status = wakelock_release_native();
else
- return wakelock_release_callout();
-}
+ status = wakelock_release_callout();
-static bool wakelock_release_callout(void)
-{
- const bt_status_t status =
- wakelock_os_callouts->release_wake_lock(WAKE_LOCK_ID);
update_wakelock_released_stats(status);
return (status == BT_STATUS_SUCCESS);
}
-static bool wakelock_release_native(void)
-{
+static bt_status_t wakelock_release_callout(void) {
+ return wakelock_os_callouts->release_wake_lock(WAKE_LOCK_ID);
+}
+
+static bt_status_t wakelock_release_native(void) {
if (wake_unlock_fd == INVALID_FD) {
LOG_ERROR(LOG_TAG, "%s lock not released, invalid fd", __func__);
- return false;
+ return BT_STATUS_PARM_INVALID;
}
ssize_t wrote_name_len = write(wake_unlock_fd, WAKE_LOCK_ID, locked_id_len);
@@ -168,11 +169,10 @@ static bool wakelock_release_native(void)
LOG_ERROR(LOG_TAG, "%s lock release only wrote %zd, assuming released",
__func__, wrote_name_len);
}
- return true;
+ return BT_STATUS_SUCCESS;
}
-static void wakelock_initialize(void)
-{
+static void wakelock_initialize(void) {
pthread_mutex_init(&monitor, NULL);
reset_wakelock_stats();
@@ -180,8 +180,7 @@ static void wakelock_initialize(void)
wakelock_initialize_native();
}
-static void wakelock_initialize_native(void)
-{
+static void wakelock_initialize_native(void) {
LOG_DEBUG(LOG_TAG, "%s opening wake locks", __func__);
if (!wake_lock_path)