38 int objpool_init(
objpool_t *
const objpool, uint32_t nbr_subpools)
40 if (nbr_subpools > OBJSUBPOOLS_MAX)
41 nbr_subpools = OBJSUBPOOLS_MAX;
43 objpool->nbr_subpools = nbr_subpools;
45 for (uint32_t i = 0; i < nbr_subpools; i++) {
48 env_spinlock_init(&subpool->lock);
49 list_init(&subpool->list_head);
55 void objpool_add(
objpool_t *
const objpool, uint32_t subpool_idx,
58 const uint32_t idx = subpool_idx % objpool->nbr_subpools;
61 elem->subpool_idx = idx;
63 env_spinlock_lock(&subpool->lock);
64 list_add(&subpool->list_head, &elem->list_node);
66 env_spinlock_unlock(&subpool->lock);
70 objpool_rem(
objpool_t *
const objpool, uint32_t subpool_idx)
74 for (uint32_t i = 0; i < objpool->nbr_subpools; i++) {
75 const uint32_t idx = (subpool_idx + i) % objpool->nbr_subpools;
78 env_spinlock_lock(&subpool->lock);
80 list_node_t *
const node = list_rem_first(&subpool->list_head);
83 elem = objpool_node2elem(node);
87 env_spinlock_unlock(&subpool->lock);
98 const uint32_t idx = elem->subpool_idx;
102 env_spinlock_lock(&subpool->lock);
104 list_rem(&subpool->list_head, &elem->list_node);
108 env_spinlock_unlock(&subpool->lock);