Bluetooth: Rename bt_conn_get/put to bt_conn_ref/unref

We want to make the naming convention ref/unref rather than get/put.
So far the only reference counted objects are the buffers and the
connections. For the buffers the new generic buffer API will also use
ref/unref.

Change-Id: I9fe8b8a6a50a8baf06ba231e8f6717a5a47dd292
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit is contained in:
Johan Hedberg 2015-10-23 12:45:33 +03:00 committed by Anas Nashif
commit 49885879f2
6 changed files with 38 additions and 38 deletions

View file

@ -36,7 +36,7 @@ struct bt_conn;
*
* @return Connection object with incremented reference count.
*/
struct bt_conn *bt_conn_get(struct bt_conn *conn);
struct bt_conn *bt_conn_ref(struct bt_conn *conn);
/** @brief Decrement a connection's reference count.
*
@ -44,7 +44,7 @@ struct bt_conn *bt_conn_get(struct bt_conn *conn);
*
* @param conn Connection object.
*/
void bt_conn_put(struct bt_conn *conn);
void bt_conn_unref(struct bt_conn *conn);
/** @brief Look up an existing connection by address.
*
@ -54,7 +54,7 @@ void bt_conn_put(struct bt_conn *conn);
*
* @return Connection object or NULL if not found. The caller gets a
* new reference to the connection object which must be released with
* bt_conn_put() once done using the object.
* bt_conn_unref() once done using the object.
*/
struct bt_conn *bt_conn_lookup_addr_le(const bt_addr_le_t *peer);

View file

@ -419,7 +419,7 @@ static void conn_tx_fiber(int arg1, int arg2)
bt_conn_reset_rx_state(conn);
BT_DBG("handle %u exiting\n", conn->handle);
bt_conn_put(conn);
bt_conn_unref(conn);
}
struct bt_conn *bt_conn_add(const bt_addr_le_t *peer)
@ -458,7 +458,7 @@ static void timeout_fiber(int arg1, int arg2)
conn->timeout = NULL;
bt_conn_disconnect(conn, BT_HCI_ERR_REMOTE_USER_TERM_CONN);
bt_conn_put(conn);
bt_conn_unref(conn);
}
void bt_conn_set_state(struct bt_conn *conn, bt_conn_state_t state)
@ -482,7 +482,7 @@ void bt_conn_set_state(struct bt_conn *conn, bt_conn_state_t state)
* bt_conn_add() and keep it until reaching DISCONNECTED
* again.
*/
bt_conn_get(conn);
bt_conn_ref(conn);
break;
case BT_CONN_CONNECT:
if (conn->timeout) {
@ -490,7 +490,7 @@ void bt_conn_set_state(struct bt_conn *conn, bt_conn_state_t state)
conn->timeout = NULL;
/* Drop the reference taken by timeout fiber */
bt_conn_put(conn);
bt_conn_unref(conn);
}
break;
default:
@ -502,7 +502,7 @@ void bt_conn_set_state(struct bt_conn *conn, bt_conn_state_t state)
case BT_CONN_CONNECTED:
nano_fifo_init(&conn->tx_queue);
fiber_start(conn->stack, sizeof(conn->stack), conn_tx_fiber,
(int)bt_conn_get(conn), 0, 7, 0);
(int)bt_conn_ref(conn), 0, 7, 0);
bt_l2cap_connected(conn);
notify_connected(conn);
@ -522,7 +522,7 @@ void bt_conn_set_state(struct bt_conn *conn, bt_conn_state_t state)
/* Release the reference we took for the very first
* state transition.
*/
bt_conn_put(conn);
bt_conn_unref(conn);
break;
case BT_CONN_CONNECT_SCAN:
@ -532,7 +532,7 @@ void bt_conn_set_state(struct bt_conn *conn, bt_conn_state_t state)
conn->timeout = fiber_delayed_start(conn->stack,
sizeof(conn->stack),
timeout_fiber,
(int)bt_conn_get(conn),
(int)bt_conn_ref(conn),
0, 7, 0, CONN_TIMEOUT);
break;
case BT_CONN_DISCONNECT:
@ -560,7 +560,7 @@ struct bt_conn *bt_conn_lookup_handle(uint16_t handle)
}
if (conns[i].handle == handle) {
return bt_conn_get(&conns[i]);
return bt_conn_ref(&conns[i]);
}
}
@ -577,7 +577,7 @@ struct bt_conn *bt_conn_lookup_addr_le(const bt_addr_le_t *peer)
}
if (!bt_addr_le_cmp(peer, &conns[i].dst)) {
return bt_conn_get(&conns[i]);
return bt_conn_ref(&conns[i]);
}
}
@ -600,14 +600,14 @@ struct bt_conn *bt_conn_lookup_state(const bt_addr_le_t *peer,
}
if (conns[i].state == state) {
return bt_conn_get(&conns[i]);
return bt_conn_ref(&conns[i]);
}
}
return NULL;
}
struct bt_conn *bt_conn_get(struct bt_conn *conn)
struct bt_conn *bt_conn_ref(struct bt_conn *conn)
{
atomic_inc(&conn->ref);
@ -616,7 +616,7 @@ struct bt_conn *bt_conn_get(struct bt_conn *conn)
return conn;
}
void bt_conn_put(struct bt_conn *conn)
void bt_conn_unref(struct bt_conn *conn)
{
atomic_dec(&conn->ref);
@ -671,7 +671,7 @@ static int bt_hci_connect_le_cancel(struct bt_conn *conn)
conn->timeout = NULL;
/* Drop the reference took by timeout fiber */
bt_conn_put(conn);
bt_conn_unref(conn);
}
err = bt_hci_cmd_send(BT_HCI_OP_LE_CREATE_CONN_CANCEL, NULL);
@ -720,7 +720,7 @@ struct bt_conn *bt_conn_create_le(const bt_addr_le_t *peer)
case BT_CONN_CONNECTED:
return conn;
default:
bt_conn_put(conn);
bt_conn_unref(conn);
return NULL;
}
}

View file

@ -362,11 +362,11 @@ static uint8_t notify_cb(const struct bt_gatt_attr *attr, void *user_data)
}
if (att_notify(conn, data->handle, data->data, data->len) < 0) {
bt_conn_put(conn);
bt_conn_unref(conn);
return BT_GATT_ITER_STOP;
}
bt_conn_put(conn);
bt_conn_unref(conn);
}
return BT_GATT_ITER_CONTINUE;
@ -459,7 +459,7 @@ static uint8_t disconnected_cb(const struct bt_gatt_attr *attr, void *user_data)
/* Skip if there is another peer connected */
tmp = bt_conn_lookup_addr_le(&ccc->cfg[i].peer);
if (tmp && tmp->state == BT_CONN_CONNECTED) {
bt_conn_put(tmp);
bt_conn_unref(tmp);
return BT_GATT_ITER_CONTINUE;
}
}

View file

@ -287,7 +287,7 @@ static void hci_acl(struct bt_buf *buf)
}
bt_conn_recv(conn, buf, flags);
bt_conn_put(conn);
bt_conn_unref(conn);
}
static void hci_num_completed_packets(struct bt_buf *buf)
@ -320,7 +320,7 @@ static void hci_num_completed_packets(struct bt_buf *buf)
conn->pending_pkts = 0;
}
bt_conn_put(conn);
bt_conn_unref(conn);
while (count--) {
nano_fiber_sem_give(&bt_dev.le_pkts_sem);
@ -385,7 +385,7 @@ static void hci_disconn_complete(struct bt_buf *buf)
bt_le_scan_update();
}
bt_conn_put(conn);
bt_conn_unref(conn);
if (atomic_test_bit(bt_dev.flags, BT_DEV_ADVERTISING)) {
struct bt_buf *buf;
@ -472,7 +472,7 @@ static void le_conn_complete(struct bt_buf *buf)
* We are now in DISCONNECTED state since no successful LE
* link been made.
*/
bt_conn_put(conn);
bt_conn_unref(conn);
return;
}
@ -518,7 +518,7 @@ static void le_conn_complete(struct bt_buf *buf)
update_conn_params(conn);
done:
bt_conn_put(conn);
bt_conn_unref(conn);
bt_le_scan_update();
}
@ -541,7 +541,7 @@ static void le_remote_feat_complete(struct bt_buf *buf)
update_conn_params(conn);
bt_conn_put(conn);
bt_conn_unref(conn);
}
static int le_conn_param_neg_reply(uint16_t handle, uint8_t reason)
@ -604,7 +604,7 @@ static int le_conn_param_req(struct bt_buf *buf)
BT_HCI_ERR_UNKNOWN_CONN_ID);
}
bt_conn_put(conn);
bt_conn_unref(conn);
if (!bt_le_conn_params_valid(min, max, latency, timeout)) {
return le_conn_param_neg_reply(handle,
@ -637,7 +637,7 @@ static void le_conn_update_complete(struct bt_buf *buf)
/* TODO Notify about connection */
bt_conn_put(conn);
bt_conn_unref(conn);
}
static void check_pending_conn(const bt_addr_le_t *id_addr,
@ -666,7 +666,7 @@ static void check_pending_conn(const bt_addr_le_t *id_addr,
bt_conn_set_state(conn, BT_CONN_CONNECT);
done:
bt_conn_put(conn);
bt_conn_unref(conn);
}
static int set_flow_control(void)
@ -747,7 +747,7 @@ static void hci_encrypt_change(struct bt_buf *buf)
/* TODO report error */
/* reset required security level in case of error */
conn->required_sec_level = conn->sec_level;
bt_conn_put(conn);
bt_conn_unref(conn);
return;
}
@ -757,7 +757,7 @@ static void hci_encrypt_change(struct bt_buf *buf)
bt_l2cap_encrypt_change(conn);
bt_conn_security_changed(conn);
bt_conn_put(conn);
bt_conn_unref(conn);
}
static void hci_encrypt_key_refresh_complete(struct bt_buf *buf)
@ -783,7 +783,7 @@ static void hci_encrypt_key_refresh_complete(struct bt_buf *buf)
update_sec_level(conn);
bt_l2cap_encrypt_change(conn);
bt_conn_security_changed(conn);
bt_conn_put(conn);
bt_conn_unref(conn);
}
static void le_ltk_request(struct bt_buf *buf)
@ -847,7 +847,7 @@ static void le_ltk_request(struct bt_buf *buf)
}
done:
bt_conn_put(conn);
bt_conn_unref(conn);
}
#endif /* CONFIG_BLUETOOTH_SMP */
@ -1034,7 +1034,7 @@ int bt_le_scan_update(void)
return 0;
}
bt_conn_put(conn);
bt_conn_unref(conn);
return bt_hci_start_scanning(BT_LE_SCAN_PASSIVE);
}

View file

@ -215,7 +215,7 @@ static void disconnected(struct bt_conn *conn)
return;
}
bt_conn_put(default_conn);
bt_conn_unref(default_conn);
default_conn = NULL;
err = bt_start_scanning(BT_SCAN_FILTER_DUP_DISABLE, device_found);

View file

@ -98,7 +98,7 @@ static void connected(struct bt_conn *conn)
printk("Connected: %s\n", addr);
if (!default_conn) {
default_conn = bt_conn_get(conn);
default_conn = bt_conn_ref(conn);
}
}
@ -111,7 +111,7 @@ static void disconnected(struct bt_conn *conn)
printk("Disconnected: %s\n", addr);
if (default_conn == conn) {
bt_conn_put(default_conn);
bt_conn_unref(default_conn);
default_conn = NULL;
}
}
@ -239,7 +239,7 @@ static void cmd_connect_le(int argc, char *argv[])
printk("Connection pending\n");
/* unref connection obj in advance as app user */
bt_conn_put(conn);
bt_conn_unref(conn);
}
}