Skip to content

Commit ef0d622

Browse files
committed
Update peer_id
Updates peer_id. Signed-off-by: Mirko Covizzi <[email protected]>
1 parent 80141ae commit ef0d622

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

lib/peer_manager/modules/peer_id.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,21 @@
77

88
#include <stdint.h>
99
#include <string.h>
10+
#include <limits.h>
11+
#include <zephyr/sys/atomic.h>
1012
#include <nrf_error.h>
1113
#include <bluetooth/peer_manager/peer_manager_types.h>
1214
#include <modules/peer_id.h>
1315

16+
#define BITS_SIZEOF(type) (sizeof(type) * CHAR_BIT)
17+
#define ATOMIC_BITMAP(name) \
18+
atomic_t name[(PM_PEER_ID_N_AVAILABLE_IDS - 1) / BITS_SIZEOF(atomic_t) + 1] \
19+
1420
typedef struct {
1521
/** Bitmap designating which peer IDs are in use. */
16-
NRF_ATFLAGS_DEF_MEMBER(used_peer_ids, PM_PEER_ID_N_AVAILABLE_IDS);
22+
ATOMIC_BITMAP(used_peer_ids);
1723
/** Bitmap designating which peer IDs are marked for deletion. */
18-
NRF_ATFLAGS_DEF_MEMBER(deleted_peer_ids, PM_PEER_ID_N_AVAILABLE_IDS);
24+
ATOMIC_BITMAP(deleted_peer_ids);
1925
} pi_t;
2026

2127
static pi_t m_pi = {{0}, {0}};
@@ -30,7 +36,7 @@ void peer_id_init(void)
3036
internal_state_reset(&m_pi);
3137
}
3238

33-
static pm_peer_id_t claim(pm_peer_id_t peer_id, nrf_atflags_t *p_peer_id_flags)
39+
static pm_peer_id_t claim(pm_peer_id_t peer_id, atomic_t *p_peer_id_flags)
3440
{
3541
pm_peer_id_t allocated_peer_id = PM_PEER_ID_INVALID;
3642

@@ -48,7 +54,7 @@ static pm_peer_id_t claim(pm_peer_id_t peer_id, nrf_atflags_t *p_peer_id_flags)
4854
return allocated_peer_id;
4955
}
5056

51-
static void release(pm_peer_id_t peer_id, nrf_atflags_t *p_peer_id_flags)
57+
static void release(pm_peer_id_t peer_id, atomic_t *p_peer_id_flags)
5258
{
5359
if (peer_id < PM_PEER_ID_N_AVAILABLE_IDS) {
5460
nrf_atflags_clear(p_peer_id_flags, peer_id);
@@ -95,7 +101,7 @@ bool peer_id_is_deleted(pm_peer_id_t peer_id)
95101
return false;
96102
}
97103

98-
pm_peer_id_t next_id_get(pm_peer_id_t prev_peer_id, nrf_atflags_t *p_peer_id_flags)
104+
pm_peer_id_t next_id_get(pm_peer_id_t prev_peer_id, atomic_t *p_peer_id_flags)
99105
{
100106
pm_peer_id_t i = (prev_peer_id == PM_PEER_ID_INVALID) ? 0 : (prev_peer_id + 1);
101107

0 commit comments

Comments
 (0)