summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristopher R. Palmer <crpalmer@gmail.com>2016-06-11 06:35:50 -0400
committerChristopher R. Palmer <crpalmer@gmail.com>2016-06-11 06:41:57 -0400
commitc71852721a6c97c020c554639ddea0d0c5b7410c (patch)
tree4bc318604361c50f0bc54615aafe35863ba5c414
parent600e1a9d2a620de62476dfec140385d9233a1f7f (diff)
downloadandroid_system_bt-c71852721a6c97c020c554639ddea0d0c5b7410c.tar.gz
android_system_bt-c71852721a6c97c020c554639ddea0d0c5b7410c.tar.bz2
android_system_bt-c71852721a6c97c020c554639ddea0d0c5b7410c.zip
bt: Unify usage of clock_gettime
This moves all clocks to CLOCK_BOOTTIME and puts this define into a common shared location rather than a smear all over the code. Change-Id: I11dbf557f35f75b3030dc0b6829dbaec70e20a19
-rw-r--r--audio_a2dp_hw/audio_a2dp_hw.c6
-rw-r--r--btif/src/btif_hf.c9
-rw-r--r--btif/src/btif_media_task.c7
-rw-r--r--gki/ulinux/gki_ulinux.c3
-rw-r--r--hci/src/btsnoop.c6
-rw-r--r--utils/include/bt_utils.h16
6 files changed, 25 insertions, 22 deletions
diff --git a/audio_a2dp_hw/audio_a2dp_hw.c b/audio_a2dp_hw/audio_a2dp_hw.c
index 1933d5a75..9cee5d0f2 100644
--- a/audio_a2dp_hw/audio_a2dp_hw.c
+++ b/audio_a2dp_hw/audio_a2dp_hw.c
@@ -188,7 +188,7 @@ static void ts_error_log(char *tag, int val, int buff_size, struct a2dp_config c
unsigned long long now_us;
unsigned long long diff_us;
- clock_gettime(CLOCK_MONOTONIC, &now);
+ time_now_timespec(&now);
now_us = now.tv_sec*USEC_PER_SEC + now.tv_nsec/1000;
@@ -211,7 +211,7 @@ static void ts_log(char *tag, int val, struct timespec *pprev_opt)
UNUSED(tag);
UNUSED(val);
- clock_gettime(CLOCK_MONOTONIC, &now);
+ time_now_timespec(&now);
now_us = now.tv_sec*USEC_PER_SEC + now.tv_nsec/1000;
@@ -991,7 +991,7 @@ static int out_get_presentation_position(const struct audio_stream_out *stream,
uint64_t latency_frames = (uint64_t)out_get_latency(stream) * out->common.cfg.rate / 1000;
if (out->frames_presented >= latency_frames) {
*frames = out->frames_presented - latency_frames;
- clock_gettime(CLOCK_MONOTONIC, timestamp); // could also be associated with out_write().
+ time_now_timespec(timestamp); // could also be associated with out_write().
ret = 0;
}
pthread_mutex_unlock(&out->common.lock);
diff --git a/btif/src/btif_hf.c b/btif/src/btif_hf.c
index 43707adfc..bdaf69ec9 100644
--- a/btif/src/btif_hf.c
+++ b/btif/src/btif_hf.c
@@ -391,7 +391,7 @@ static int btif_hf_latest_connected_idx()
struct timespec now, conn_time_delta;
int latest_conn_idx = BTIF_HF_INVALID_IDX, i;
- clock_gettime(CLOCK_MONOTONIC, &now);
+ time_now_timespec(&now);
conn_time_delta.tv_sec = now.tv_sec;
for (i = 0; i < btif_max_hf_clients; i++)
@@ -555,8 +555,7 @@ static void btif_hf_upstreams_evt(UINT16 event, char* p_param)
break;
case BTA_AG_CONN_EVT:
- clock_gettime(CLOCK_MONOTONIC,
- &btif_hf_cb[idx].connected_timestamp);
+ time_now_timespec(&btif_hf_cb[idx].connected_timestamp);
BTIF_TRACE_DEBUG("%s: BTA_AG_CONN_EVT, idx = %d ",
__FUNCTION__, idx);
btif_hf_cb[idx].peer_feat = p_data->conn.peer_feat;
@@ -1402,7 +1401,7 @@ static bt_status_t phone_state_change(int num_active, int num_held, bthf_call_st
(btif_hf_cb[idx].num_active) ||(btif_hf_cb[idx].num_held))
{
BTIF_TRACE_DEBUG("%s: Record call termination timestamp", __FUNCTION__);
- clock_gettime(CLOCK_MONOTONIC, &btif_hf_cb[0].call_end_timestamp);
+ time_now_timespec(&btif_hf_cb[0].call_end_timestamp);
}
BTA_AgResult (BTA_AG_HANDLE_ALL, BTA_AG_END_CALL_RES, NULL);
hf_idx = BTIF_HF_INVALID_IDX;
@@ -1647,7 +1646,7 @@ BOOLEAN btif_hf_call_terminated_recently()
{
struct timespec now;
- clock_gettime(CLOCK_MONOTONIC, &now);
+ time_now_timespec(&now);
if (now.tv_sec < btif_hf_cb[0].call_end_timestamp.tv_sec +
BTIF_HF_CALL_END_TIMEOUT)
{
diff --git a/btif/src/btif_media_task.c b/btif/src/btif_media_task.c
index 0a2303a65..3b4e2ed31 100644
--- a/btif/src/btif_media_task.c
+++ b/btif/src/btif_media_task.c
@@ -397,13 +397,6 @@ static thread_t *worker_thread;
** Misc helper functions
*****************************************************************************/
-static UINT64 time_now_us()
-{
- struct timespec ts_now;
- clock_gettime(CLOCK_BOOTTIME, &ts_now);
- return ((UINT64)ts_now.tv_sec * USEC_PER_SEC) + ((UINT64)ts_now.tv_nsec / 1000);
-}
-
static void log_tstamps_us(char *comment)
{
#define USEC_PER_MSEC 1000L
diff --git a/gki/ulinux/gki_ulinux.c b/gki/ulinux/gki_ulinux.c
index 72ad479e0..8ffe2b3fb 100644
--- a/gki/ulinux/gki_ulinux.c
+++ b/gki/ulinux/gki_ulinux.c
@@ -28,6 +28,7 @@
#include "gki/ulinux/gki_int.h"
#include "osi/include/log.h"
#include "osi/include/osi.h"
+#include "bt_utils.h"
tGKI_CB gki_cb;
@@ -64,7 +65,7 @@ const module_t gki_module = {
UINT32 GKI_get_os_tick_count(void) {
struct timespec timespec;
- clock_gettime(CLOCK_BOOTTIME, &timespec);
+ time_now_timespec(&timespec);
return (timespec.tv_sec * 1000) + (timespec.tv_nsec / 1000000);
}
diff --git a/hci/src/btsnoop.c b/hci/src/btsnoop.c
index 5164148b7..809e784c8 100644
--- a/hci/src/btsnoop.c
+++ b/hci/src/btsnoop.c
@@ -229,12 +229,6 @@ static void btsnoop_write(const void *data, size_t length) {
write(logfile_fd, data, length);
}
-static uint64_t time_now_us() {
- struct timespec ts_now;
- clock_gettime(CLOCK_BOOTTIME, &ts_now);
- return ((uint64_t)ts_now.tv_sec * USEC_PER_SEC) + ((uint64_t)ts_now.tv_nsec / 1000);
-}
-
static void btsnoop_write_packet(packet_type_t type, const uint8_t *packet, bool is_received) {
int length_he = 0;
int length;
diff --git a/utils/include/bt_utils.h b/utils/include/bt_utils.h
index 80298d77c..623b7da40 100644
--- a/utils/include/bt_utils.h
+++ b/utils/include/bt_utils.h
@@ -67,4 +67,20 @@ bool add_iot_device(const char *filename, char* header,
bool remove_iot_device(const char *filename, char* header,
unsigned char* device_details, tBLACKLIST_METHOD method_type);
#define UNUSED(x) (void)(x)
+
+#include <time.h>
+
+#define USEC_PER_SEC 1000000L
+
+static inline void time_now_timespec(struct timespec *ts)
+{
+ clock_gettime(CLOCK_BOOTTIME, ts);
+}
+
+static inline uint64_t time_now_us()
+{
+ struct timespec ts_now;
+ time_now_timespec(&ts_now);
+ return ((uint64_t)ts_now.tv_sec * USEC_PER_SEC) + ((uint64_t)ts_now.tv_nsec / 1000);
+}
#endif /* BT_UTILS_H */