ble_mesh: Rename ble mesh lock/unlock functions

Rename BLE Mesh internal lock/unlock functions, also seperate
the list, buf and atomic lock/unlock functions
This commit is contained in:
lly 2019-12-20 11:26:55 +08:00
parent 31a4738bd4
commit 619e606356
5 changed files with 69 additions and 39 deletions

View File

@ -268,8 +268,14 @@ s64_t k_uptime_get(void);
*/
void k_sleep(s32_t duration);
void bt_mesh_irq_lock(void);
void bt_mesh_irq_unlock(void);
void bt_mesh_list_lock(void);
void bt_mesh_list_unlock(void);
void bt_mesh_buf_lock(void);
void bt_mesh_buf_unlock(void);
void bt_mesh_atomic_lock(void);
void bt_mesh_atomic_unlock(void);
void bt_mesh_k_init(void);

View File

@ -57,12 +57,12 @@ bt_mesh_atomic_val_t bt_mesh_atomic_set(bt_mesh_atomic_t *target, bt_mesh_atomic
{
bt_mesh_atomic_val_t ret;
bt_mesh_irq_lock();
bt_mesh_atomic_lock();
ret = *target;
*target = value;
bt_mesh_irq_unlock();
bt_mesh_atomic_unlock();
return ret;
}
@ -84,12 +84,12 @@ bt_mesh_atomic_val_t bt_mesh_atomic_or(bt_mesh_atomic_t *target, bt_mesh_atomic_
{
bt_mesh_atomic_val_t ret;
bt_mesh_irq_lock();
bt_mesh_atomic_lock();
ret = *target;
*target |= value;
bt_mesh_irq_unlock();
bt_mesh_atomic_unlock();
return ret;
}
@ -111,12 +111,12 @@ bt_mesh_atomic_val_t bt_mesh_atomic_and(bt_mesh_atomic_t *target, bt_mesh_atomic
{
bt_mesh_atomic_val_t ret;
bt_mesh_irq_lock();
bt_mesh_atomic_lock();
ret = *target;
*target &= value;
bt_mesh_irq_unlock();
bt_mesh_atomic_unlock();
return ret;
}
@ -136,12 +136,12 @@ bt_mesh_atomic_val_t bt_mesh_atomic_dec(bt_mesh_atomic_t *target)
{
bt_mesh_atomic_val_t ret;
bt_mesh_irq_lock();
bt_mesh_atomic_lock();
ret = *target;
(*target)--;
bt_mesh_irq_unlock();
bt_mesh_atomic_unlock();
return ret;
}
@ -161,12 +161,12 @@ bt_mesh_atomic_val_t bt_mesh_atomic_inc(bt_mesh_atomic_t *target)
{
bt_mesh_atomic_val_t ret;
bt_mesh_irq_lock();
bt_mesh_atomic_lock();
ret = *target;
(*target)++;
bt_mesh_irq_unlock();
bt_mesh_atomic_unlock();
return ret;
}

View File

@ -241,9 +241,9 @@ void net_buf_slist_put(sys_slist_t *list, struct net_buf *buf)
tail->flags |= NET_BUF_FRAGS;
}
bt_mesh_irq_lock();
bt_mesh_list_lock();
sys_slist_append_list(list, &buf->node, &tail->node);
bt_mesh_irq_unlock();
bt_mesh_list_unlock();
}
struct net_buf *net_buf_slist_get(sys_slist_t *list)
@ -252,9 +252,9 @@ struct net_buf *net_buf_slist_get(sys_slist_t *list)
NET_BUF_ASSERT(list);
bt_mesh_irq_lock();
bt_mesh_list_lock();
buf = (void *)sys_slist_get(list);
bt_mesh_irq_unlock();
bt_mesh_list_unlock();
if (!buf) {
return NULL;
@ -262,9 +262,9 @@ struct net_buf *net_buf_slist_get(sys_slist_t *list)
/* Get any fragments belonging to this buffer */
for (frag = buf; (frag->flags & NET_BUF_FRAGS); frag = frag->frags) {
bt_mesh_irq_lock();
bt_mesh_list_lock();
frag->frags = (void *)sys_slist_get(list);
bt_mesh_irq_unlock();
bt_mesh_list_unlock();
NET_BUF_ASSERT(frag->frags);
@ -381,7 +381,7 @@ struct net_buf *net_buf_alloc_len(struct net_buf_pool *pool, size_t size,
/* We need to lock interrupts temporarily to prevent race conditions
* when accessing pool->uninit_count.
*/
bt_mesh_irq_lock();
bt_mesh_buf_lock();
/* If there are uninitialized buffers we're guaranteed to succeed
* with the allocation one way or another.
@ -391,13 +391,13 @@ struct net_buf *net_buf_alloc_len(struct net_buf_pool *pool, size_t size,
for (i = pool->buf_count; i > 0; i--) {
buf = pool_get_uninit(pool, i);
if (!buf->ref) {
bt_mesh_irq_unlock();
bt_mesh_buf_unlock();
goto success;
}
}
}
bt_mesh_irq_unlock();
bt_mesh_buf_unlock();
NET_BUF_ERR("%s, Failed to get free buffer", __func__);
return NULL;

View File

@ -24,7 +24,9 @@
#include "provisioner_prov.h"
static osi_mutex_t bm_alarm_lock;
static osi_mutex_t bm_irq_lock;
static osi_mutex_t bm_list_lock;
static osi_mutex_t bm_buf_lock;
static osi_mutex_t bm_atomic_lock;
static hash_map_t *bm_alarm_hash_map;
static const size_t BLE_MESH_GENERAL_ALARM_HASH_MAP_SIZE = 20 + CONFIG_BLE_MESH_PBA_SAME_TIME + \
CONFIG_BLE_MESH_PBG_SAME_TIME;
@ -37,14 +39,34 @@ typedef struct alarm_t {
int64_t deadline_us;
} osi_alarm_t;
void bt_mesh_irq_lock(void)
void bt_mesh_list_lock(void)
{
osi_mutex_lock(&bm_irq_lock, OSI_MUTEX_MAX_TIMEOUT);
osi_mutex_lock(&bm_list_lock, OSI_MUTEX_MAX_TIMEOUT);
}
void bt_mesh_irq_unlock(void)
void bt_mesh_list_unlock(void)
{
osi_mutex_unlock(&bm_irq_lock);
osi_mutex_unlock(&bm_list_lock);
}
void bt_mesh_buf_lock(void)
{
osi_mutex_lock(&bm_buf_lock, OSI_MUTEX_MAX_TIMEOUT);
}
void bt_mesh_buf_unlock(void)
{
osi_mutex_unlock(&bm_buf_lock);
}
void bt_mesh_atomic_lock(void)
{
osi_mutex_lock(&bm_atomic_lock, OSI_MUTEX_MAX_TIMEOUT);
}
void bt_mesh_atomic_unlock(void)
{
osi_mutex_unlock(&bm_atomic_lock);
}
s64_t k_uptime_get(void)
@ -72,7 +94,9 @@ void k_sleep(s32_t duration)
void bt_mesh_k_init(void)
{
osi_mutex_new(&bm_alarm_lock);
osi_mutex_new(&bm_irq_lock);
osi_mutex_new(&bm_list_lock);
osi_mutex_new(&bm_buf_lock);
osi_mutex_new(&bm_atomic_lock);
bm_alarm_hash_map = hash_map_new(BLE_MESH_GENERAL_ALARM_HASH_MAP_SIZE,
hash_function_pointer, NULL,
(data_free_fn)osi_alarm_free, NULL);

View File

@ -31,9 +31,9 @@ static bt_mesh_client_node_t *bt_mesh_client_pick_node(sys_slist_t *list, u16_t
bt_mesh_client_node_t *node = NULL;
sys_snode_t *cur = NULL;
bt_mesh_irq_lock();
bt_mesh_list_lock();
if (sys_slist_is_empty(list)) {
bt_mesh_irq_unlock();
bt_mesh_list_unlock();
return NULL;
}
@ -41,12 +41,12 @@ static bt_mesh_client_node_t *bt_mesh_client_pick_node(sys_slist_t *list, u16_t
cur != NULL; cur = sys_slist_peek_next(cur)) {
node = (bt_mesh_client_node_t *)cur;
if (node->ctx.addr == tx_dst) {
bt_mesh_irq_unlock();
bt_mesh_list_unlock();
return node;
}
}
bt_mesh_irq_unlock();
bt_mesh_list_unlock();
return NULL;
}
@ -125,9 +125,9 @@ static bool bt_mesh_client_check_node_in_list(sys_slist_t *list, u16_t tx_dst)
bt_mesh_client_node_t *node = NULL;
sys_snode_t *cur = NULL;
bt_mesh_irq_lock();
bt_mesh_list_lock();
if (sys_slist_is_empty(list)) {
bt_mesh_irq_unlock();
bt_mesh_list_unlock();
return false;
}
@ -135,12 +135,12 @@ static bool bt_mesh_client_check_node_in_list(sys_slist_t *list, u16_t tx_dst)
cur != NULL; cur = sys_slist_peek_next(cur)) {
node = (bt_mesh_client_node_t *)cur;
if (node->ctx.addr == tx_dst) {
bt_mesh_irq_unlock();
bt_mesh_list_unlock();
return true;
}
}
bt_mesh_irq_unlock();
bt_mesh_list_unlock();
return false;
}
@ -212,9 +212,9 @@ int bt_mesh_client_send_msg(struct bt_mesh_model *model,
if ((err = bt_mesh_model_send(model, ctx, msg, cb, cb_data)) != 0) {
osi_free(node);
} else {
bt_mesh_irq_lock();
bt_mesh_list_lock();
sys_slist_append(&internal->queue, &node->client_node);
bt_mesh_irq_unlock();
bt_mesh_list_unlock();
k_delayed_work_init(&node->timer, timer_handler);
k_delayed_work_submit(&node->timer, timeout ? timeout : CONFIG_BLE_MESH_CLIENT_MSG_TIMEOUT);
}
@ -307,9 +307,9 @@ int bt_mesh_client_free_node(bt_mesh_client_node_t *node)
}
// Release the client node from the queue
bt_mesh_irq_lock();
bt_mesh_list_lock();
sys_slist_find_and_remove(&internal->queue, &node->client_node);
bt_mesh_irq_unlock();
bt_mesh_list_unlock();
// Free the node
osi_free(node);