Bluetooth: Make ref on connection object atomic

This makes it possible to perform these operations without
locking once per-conn locking is added in the future.

Change-Id: I342d55856116d9c87daeda4088b65e78e8ef0768
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
This commit is contained in:
Arkadiusz Lichwa 2015-06-23 14:38:24 +02:00 committed by Anas Nashif
commit e57984e3be
2 changed files with 6 additions and 7 deletions

View file

@ -281,7 +281,7 @@ struct bt_conn *bt_conn_add(struct bt_dev *dev, const bt_addr_le_t *peer,
memset(conn, 0, sizeof(*conn));
conn->ref = 1;
atomic_set(&conn->ref, 1);
conn->dev = dev;
conn->role = role;
bt_addr_le_copy(&conn->dst, peer);
@ -361,20 +361,18 @@ struct bt_conn *bt_conn_lookup_addr_le(const bt_addr_le_t *peer)
struct bt_conn *bt_conn_get(struct bt_conn *conn)
{
conn->ref++;
BT_DBG("handle %u ref %u\n", conn->handle, conn->ref);
atomic_inc(&conn->ref);
return conn;
}
void bt_conn_put(struct bt_conn *conn)
{
conn->ref--;
BT_DBG("handle %u ref %u\n", conn->handle, conn->ref);
if (conn->ref) {
if (atomic_dec(&conn->ref) > 1) {
return;
}

View file

@ -32,6 +32,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <atomic.h>
#include <bluetooth/conn.h>
typedef enum {
@ -71,7 +72,7 @@ struct bt_conn {
uint8_t le_conn_interval;
uint8_t ref;
atomic_t ref;
bt_conn_state_t state;