#include "osi/include/alarm.h"
#include "osi/include/future.h"
#include "osi/include/log.h"
+#include "osi/include/mutex.h"
#include "osi/include/osi.h"
+future_t *osi_init(void) {
+ mutex_init();
+ return future_new_immediate(FUTURE_SUCCESS);
+}
+
future_t *osi_clean_up(void) {
alarm_cleanup();
- return NULL;
+ mutex_cleanup();
+ return future_new_immediate(FUTURE_SUCCESS);
}
const module_t osi_module = {
.name = OSI_MODULE,
- .init = NULL,
+ .init = osi_init,
.start_up = NULL,
.shut_down = NULL,
.clean_up = osi_clean_up,
#include "sbc_encoder.h"
#include "btif_av_co.h"
#include "btif_util.h"
+#include "osi/include/mutex.h"
/*****************************************************************************
APPL_TRACE_DEBUG("bta_av_audio_sink_getconfig last SRC reached");
/* Protect access to bta_av_co_cb.codec_cfg */
- GKI_disable();
+ mutex_global_lock();
/* Find a src that matches the codec config */
if (bta_av_co_audio_peer_src_supports_codec(p_peer, &index))
}
}
/* Protect access to bta_av_co_cb.codec_cfg */
- GKI_enable();
+ mutex_global_unlock();
}
return result;
}
APPL_TRACE_DEBUG("bta_av_co_audio_getconfig last sink reached");
/* Protect access to bta_av_co_cb.codec_cfg */
- GKI_disable();
+ mutex_global_lock();
/* Find a sink that matches the codec config */
if (bta_av_co_audio_peer_supports_codec(p_peer, &index))
}
}
/* Protect access to bta_av_co_cb.codec_cfg */
- GKI_enable();
+ mutex_global_unlock();
}
return result;
}
{
/* Protect access to bta_av_co_cb.codec_cfg */
- GKI_disable();
+ mutex_global_lock();
/* Check if the configuration matches the current codec config */
switch (bta_av_co_cb.codec_cfg.id)
break;
}
/* Protect access to bta_av_co_cb.codec_cfg */
- GKI_enable();
+ mutex_global_unlock();
}
else
{
*******************************************************************************/
void bta_av_co_audio_codec_reset(void)
{
- GKI_disable();
+ mutex_global_lock();
FUNC_TRACE();
/* Reset the current configuration to SBC */
APPL_TRACE_ERROR("bta_av_co_audio_codec_reset A2D_BldSbcInfo failed");
}
- GKI_enable();
+ mutex_global_unlock();
}
/*******************************************************************************
/* Minimum MTU is by default very large */
*p_minmtu = 0xFFFF;
- GKI_disable();
+ mutex_global_lock();
if (bta_av_co_cb.codec_cfg.id == BTIF_AV_CODEC_SBC)
{
if (A2D_ParsSbcInfo(p_sbc_config, bta_av_co_cb.codec_cfg.info, FALSE) == A2D_SUCCESS)
/* Not SBC, still return the default values */
*p_sbc_config = btif_av_sbc_default_config;
}
- GKI_enable();
+ mutex_global_unlock();
return result;
}
#include "osi/include/alarm.h"
#include "osi/include/fixed_queue.h"
#include "osi/include/log.h"
+#include "osi/include/mutex.h"
#include "osi/include/thread.h"
#if (BTA_AV_INCLUDED == TRUE)
APPL_TRACE_EVENT("## A2DP SETUP CODEC ##");
- GKI_disable();
+ mutex_global_lock();
/* for now hardcode 44.1 khz 16 bit stereo PCM format */
media_feeding.cfg.pcm.sampling_freq = 44100;
btif_media_task_audio_feeding_init_req(&mfeed);
}
- GKI_enable();
+ mutex_global_unlock();
}
*/
typedef struct _tle
{
- struct _tle *p_next;
- struct _tle *p_prev;
TIMER_CBACK *p_cback;
INT32 ticks;
INT32 ticks_initial;
UINT16 _count;
} BUFFER_Q;
-#define GKI_PUBLIC_POOL 0 /* General pool accessible to GKI_getbuf() */
-#define GKI_RESTRICTED_POOL 1 /* Inaccessible pool to GKI_getbuf() */
-
/***********************************************************************
** Function prototypes
*/
UINT16 GKI_queue_length(BUFFER_Q *);
BOOLEAN GKI_queue_is_empty(BUFFER_Q *);
void *GKI_remove_from_queue (BUFFER_Q *, void *);
-
-/* Disable Interrupts, Enable Interrupts
-*/
-void GKI_enable(void);
-void GKI_disable(void);
#include <stdlib.h>
#include "osi/include/allocator.h"
+#include "osi/include/mutex.h"
#include "gki_int.h"
#if (GKI_NUM_TOTAL_BUF_POOLS > 16)
** Description Called by an application to get a free buffer which
** is of size greater or equal to the requested size.
**
-** Note: This routine only takes buffers from public pools.
-** It will not use any buffers from pools
-** marked GKI_RESTRICTED_POOL.
-**
** Parameters size - (input) number of bytes needed.
**
** Returns A pointer to the buffer, or NULL if none available
BUFFER_HDR_T *p_hdr = (BUFFER_HDR_T *) ((UINT8 *) p_buf - BUFFER_HDR_SIZE);
assert(p_hdr->status == BUF_STATUS_UNLINKED);
- GKI_disable();
+ mutex_global_lock();
/* Since the queue is exposed (C vs C++), keep the pointers in exposed format */
if (p_q->_p_last)
p_hdr->p_next = NULL;
p_hdr->status = BUF_STATUS_QUEUED;
- GKI_enable();
+ mutex_global_unlock();
}
/*******************************************************************************
{
BUFFER_HDR_T *p_hdr;
- GKI_disable();
+ mutex_global_lock();
if (!p_q || !p_q->_count)
{
- GKI_enable();
+ mutex_global_unlock();
return (NULL);
}
p_hdr->p_next = NULL;
p_hdr->status = BUF_STATUS_UNLINKED;
- GKI_enable();
+ mutex_global_unlock();
return ((UINT8 *)p_hdr + BUFFER_HDR_SIZE);
}
BUFFER_HDR_T *p_prev;
BUFFER_HDR_T *p_buf_hdr;
- GKI_disable();
+ mutex_global_lock();
if (p_buf == p_q->_p_first)
{
- GKI_enable();
+ mutex_global_unlock();
return (GKI_dequeue (p_q));
}
p_buf_hdr->p_next = NULL;
p_buf_hdr->status = BUF_STATUS_UNLINKED;
- GKI_enable();
+ mutex_global_unlock();
return (p_buf);
}
}
- GKI_enable();
+ mutex_global_unlock();
return (NULL);
}
#pragma once
-#include <pthread.h>
-
#include "gki_common.h"
typedef struct
{
- pthread_mutex_t lock;
tGKI_COM_CB com;
} tGKI_CB;
#define LOG_TAG "bt_gki"
#include <assert.h>
-#include <pthread.h>
#include <string.h>
#include "btcore/include/module.h"
static future_t *init(void) {
memset(&gki_cb, 0, sizeof(gki_cb));
- pthread_mutexattr_t attr;
- pthread_mutexattr_init(&attr);
- pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE_NP);
- pthread_mutex_init(&gki_cb.lock, &attr);
-
gki_buffer_init();
return NULL;
}
static future_t *clean_up(void) {
gki_buffer_cleanup();
- pthread_mutex_destroy(&gki_cb.lock);
return NULL;
}
NULL
}
};
-
-void GKI_enable(void) {
- pthread_mutex_unlock(&gki_cb.lock);
-}
-
-void GKI_disable(void) {
- pthread_mutex_lock(&gki_cb.lock);
-}
#define PORT_CREDIT_RX_LOW 8
#endif
-/* if application like BTA, Java or script test engine is running on other than BTU thread, */
-/* PORT_SCHEDULE_LOCK shall be defined as GKI_sched_lock() or GKI_disable() */
+/*
+ * If an application like BTA, Java or script test engine is running on other
+ * than BTU thread, PORT_SCHEDULE_LOCK shall be defined as mutex_global_lock()
+ */
#ifndef PORT_SCHEDULE_LOCK
-#define PORT_SCHEDULE_LOCK GKI_disable()
+#define PORT_SCHEDULE_LOCK mutex_global_lock()
#endif
-/* if application like BTA, Java or script test engine is running on other than BTU thread, */
-/* PORT_SCHEDULE_LOCK shall be defined as GKI_sched_unlock() or GKI_enable() */
+/*
+ * If an application like BTA, Java or script test engine is running on other
+ * than BTU thread, PORT_SCHEDULE_UNLOCK shall be defined as
+ * mutex_global_unlock()
+ */
#ifndef PORT_SCHEDULE_UNLOCK
-#define PORT_SCHEDULE_UNLOCK GKI_enable()
+#define PORT_SCHEDULE_UNLOCK mutex_global_unlock()
#endif
/******************************************************************************
./src/hash_map.c \
./src/hash_map_utils.c \
./src/list.c \
+ ./src/mutex.c \
./src/non_repeating_timer.c \
./src/reactor.c \
./src/ringbuffer.c \
"src/hash_map.c",
"src/hash_map_utils.c",
"src/list.c",
+ "src/mutex.c",
"src/non_repeating_timer.c",
"src/reactor.c",
"src/ringbuffer.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
+
+#include <stdint.h>
+
+// Mutex-related state init
+void mutex_init(void);
+
+// Mutex-related state cleanup
+void mutex_cleanup(void);
+
+// Lock the global mutex
+void mutex_global_lock(void);
+
+// Unlock the global mutex
+void mutex_global_unlock(void);
--- /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_mutex"
+
+#include <pthread.h>
+
+#include "osi/include/mutex.h"
+
+static pthread_mutex_t global_lock;
+
+void mutex_init(void) {
+ pthread_mutexattr_t attr;
+ pthread_mutexattr_init(&attr);
+ pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE_NP);
+ pthread_mutex_init(&global_lock, &attr);
+}
+
+void mutex_cleanup(void) {
+ pthread_mutex_destroy(&global_lock);
+}
+
+void mutex_global_lock(void) {
+ pthread_mutex_lock(&global_lock);
+}
+
+void mutex_global_unlock(void) {
+ pthread_mutex_unlock(&global_lock);
+}
#include "l2cdefs.h"
#include "l2c_int.h"
#include <string.h>
+#include "osi/include/mutex.h"
#if GAP_CONN_INCLUDED == TRUE
#include "btm_int.h"
if (!p_buf)
return (GAP_NO_DATA_AVAIL);
- GKI_disable();
+ mutex_global_lock();
while (max_len && p_buf)
{
p_ccb->rx_queue_size -= *p_len;
- GKI_enable();
+ mutex_global_unlock();
GAP_TRACE_EVENT ("GAP_ConnReadData - rx_queue_size left=%d, *p_len=%d",
p_ccb->rx_queue_size, *p_len);