1 /******************************************************************************
3 * Copyright (C) 2009-2012 Broadcom Corporation
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 ******************************************************************************/
19 #define LOG_TAG "bt_gki"
27 #include "btcore/include/module.h"
28 #include "gki/ulinux/gki_int.h"
29 #include "osi/include/log.h"
30 #include "osi/include/osi.h"
34 static future_t *init(void) {
35 memset(&gki_cb, 0, sizeof(gki_cb));
37 pthread_mutexattr_t attr;
38 pthread_mutexattr_init(&attr);
39 pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE_NP);
40 pthread_mutex_init(&gki_cb.lock, &attr);
46 static future_t *clean_up(void) {
49 pthread_mutex_destroy(&gki_cb.lock);
53 // Temp module until GKI dies
54 EXPORT_SYMBOL const module_t gki_module = {
65 UINT32 GKI_get_os_tick_count(void) {
66 struct timespec timespec;
67 clock_gettime(CLOCK_BOOTTIME, ×pec);
68 return (timespec.tv_sec * 1000) + (timespec.tv_nsec / 1000000);
71 // Sleep the calling thread unconditionally for |timeout_ms| milliseconds.
72 void GKI_delay(UINT32 timeout_ms) {
73 struct timespec delay;
74 delay.tv_sec = timeout_ms / 1000;
75 delay.tv_nsec = 1000 * 1000 * (timeout_ms % 1000);
79 err = nanosleep(&delay, &delay);
80 } while (err == -1 && errno == EINTR);
83 void GKI_enable(void) {
84 pthread_mutex_unlock(&gki_cb.lock);
87 void GKI_disable(void) {
88 pthread_mutex_lock(&gki_cb.lock);