Skip to content

Commit

Permalink
bt:Modify the member variable *arg in struct btc_msg to arg[0]
Browse files Browse the repository at this point in the history
  • Loading branch information
xiongweichao committed Nov 30, 2022
1 parent 40f6239 commit 3268075
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 78 deletions.
19 changes: 2 additions & 17 deletions components/bt/common/btc/core/btc_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,6 @@ static void btc_thread_handler(void *arg)
break;
}

if (msg->arg) {
osi_free(msg->arg);
}
osi_free(msg);
}

Expand Down Expand Up @@ -247,35 +244,25 @@ bt_status_t btc_transfer_context(btc_msg_t *msg, void *arg, int arg_len, btc_arg

BTC_TRACE_DEBUG("%s msg %u %u %u %p\n", __func__, msg->sig, msg->pid, msg->act, arg);

lmsg = (btc_msg_t *)osi_malloc(sizeof(btc_msg_t));
lmsg = (btc_msg_t *)osi_malloc(sizeof(btc_msg_t) + arg_len);
if (lmsg == NULL) {
return BT_STATUS_NOMEM;
}

memcpy(lmsg, msg, sizeof(btc_msg_t));
if (arg) {
lmsg->arg = (void *)osi_malloc(arg_len);
if (lmsg->arg == NULL) {
osi_free(lmsg);
return BT_STATUS_NOMEM;
}
memset(lmsg->arg, 0x00, arg_len); //important, avoid arg which have no length
memcpy(lmsg->arg, arg, arg_len);
if (copy_func) {
copy_func(lmsg, lmsg->arg, arg);
}
} else {
lmsg->arg = NULL;
}

ret = btc_task_post(lmsg, OSI_THREAD_MAX_TIMEOUT);
if (ret != BT_STATUS_SUCCESS) {
if (copy_func && free_func) {
free_func(lmsg);
}
if (lmsg->arg) {
osi_free(lmsg->arg);
}
osi_free(lmsg);
}

Expand All @@ -285,17 +272,15 @@ bt_status_t btc_transfer_context(btc_msg_t *msg, void *arg, int arg_len, btc_arg
/**
* transfer an message to another module in tha same task.
* @param msg message
* @param arg paramter
* @return BT_STATUS_SUCCESS: success
* others: fail
*/
bt_status_t btc_inter_profile_call(btc_msg_t *msg, void *arg)
bt_status_t btc_inter_profile_call(btc_msg_t *msg)
{
if (msg == NULL) {
return BT_STATUS_PARM_INVALID;
}

msg->arg = arg;
switch (msg->sig) {
case BTC_SIG_API_CALL:
profile_tab[msg->pid].btc_call(msg);
Expand Down
5 changes: 2 additions & 3 deletions components/bt/common/btc/include/btc/btc_task.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ typedef struct btc_msg {
uint8_t aid; //application id
uint8_t pid; //profile id
uint8_t act; //profile action, defined in seprerate header files
void *arg; //param for btc function or function param
UINT8 arg[0]; //param for btc function or function param
} btc_msg_t;

typedef struct btc_adv_packet {
Expand Down Expand Up @@ -116,11 +116,10 @@ bt_status_t btc_transfer_context(btc_msg_t *msg, void *arg, int arg_len, btc_arg
/**
* transfer an message to another module in tha same task.
* @param msg message
* @param arg paramter
* @return BT_STATUS_SUCCESS: success
* others: fail
*/
bt_status_t btc_inter_profile_call(btc_msg_t *msg, void *arg);
bt_status_t btc_inter_profile_call(btc_msg_t *msg);

bt_status_t btc_init(void);
void btc_deinit(void);
Expand Down
Loading

0 comments on commit 3268075

Please sign in to comment.