Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bluetooth: GMAP: Replace busy bool with atomic #78127

Merged
merged 1 commit into from
Sep 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions subsys/bluetooth/audio/gmap_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <zephyr/logging/log.h>
#include <zephyr/net_buf.h>
#include <zephyr/sys/__assert.h>
#include <zephyr/sys/atomic.h>
#include <zephyr/sys/check.h>

#include "audio_internal.h"
Expand All @@ -34,6 +35,12 @@ static const struct bt_uuid *gmap_bgr_feat_uuid = BT_UUID_GMAP_BGR_FEAT;

static const struct bt_gmap_cb *gmap_cb;

enum gmap_client_flag {
GMAP_CLIENT_FLAG_BUSY,

GMAP_CLIENT_FLAG_NUM_FLAGS, /* keep as last */
};

static struct bt_gmap_client {
/** Profile connection reference */
struct bt_conn *conn;
Expand All @@ -45,13 +52,13 @@ static struct bt_gmap_client {
uint16_t svc_start_handle;
uint16_t svc_end_handle;

bool busy;

/* GATT procedure parameters */
union {
struct bt_gatt_read_params read;
struct bt_gatt_discover_params discover;
} params;

ATOMIC_DEFINE(flags, GMAP_CLIENT_FLAG_NUM_FLAGS);
} gmap_insts[CONFIG_BT_MAX_CONN];

static void gmap_reset(struct bt_gmap_client *gmap_cli)
Expand Down Expand Up @@ -92,7 +99,7 @@ static void discover_complete(struct bt_gmap_client *gmap_cli)
{
LOG_DBG("conn %p", (void *)gmap_cli->conn);

gmap_cli->busy = false;
atomic_clear_bit(gmap_cli->flags, GMAP_CLIENT_FLAG_BUSY);

if (gmap_cb->discover != NULL) {
gmap_cb->discover(gmap_cli->conn, 0, gmap_cli->role, gmap_cli->feat);
Expand Down Expand Up @@ -648,7 +655,7 @@ int bt_gmap_discover(struct bt_conn *conn)

gmap_cli = &gmap_insts[bt_conn_index(conn)];

if (gmap_cli->busy) {
if (atomic_test_and_set_bit(gmap_cli->flags, GMAP_CLIENT_FLAG_BUSY)) {
Comment on lines -651 to +658
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where was gmap_cli->busy getting set to true previously? I can't see you modify that place in this PR. You're adding the analogue to that here (set_bit()), but seems like the original bool was never actually set anywhere?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you are correct. It was, incorrectly, never set to true it seems.

Arguably we should add BSIM tests for this behavior as well

LOG_DBG("Busy");

return -EBUSY;
Expand All @@ -666,6 +673,8 @@ int bt_gmap_discover(struct bt_conn *conn)
if (err != 0) {
LOG_DBG("Failed to initiate discovery: %d", err);

atomic_clear_bit(gmap_cli->flags, GMAP_CLIENT_FLAG_BUSY);

return -ENOEXEC;
}

Expand Down
Loading