/** Allocate a slab list to manage slabs of allocated memory \
* \
* @param[in] ctx in which to allocate the slab list. \
- * @param[out] out slab_list that has been allocated. \
* @param[in] el Event list in which to run clean up function. \
* @param[in] config Slab config parameters. \
* @param[in] alloc Optional callback to use when allocating new elements. \
* @param[in] uctx to pass to callbacks. \
* @param[in] release_reset Should elements be reset and children freed when the element is released.\
* @param[in] reserve_mru If true, the most recently used element will be returned when an element is reserved. \
+ * @return \
+ * - A new slab. \
+ * - NULL on error. \
*/ \
- static inline CC_HINT(nonnull(2)) int _name ## _slab_list_alloc(TALLOC_CTX *ctx, \
- _name ## _slab_list_t **out, \
- fr_event_list_t *el, \
- fr_slab_config_t const *config, \
- _type ## _slab_alloc_t alloc, \
- _type ## _slab_reserve_t reserve, \
- void *uctx, \
- bool release_reset, \
- bool reserve_mru) \
+ static inline _name ## _slab_list_t *_name ## _slab_list_alloc(TALLOC_CTX *ctx, \
+ fr_event_list_t *el, \
+ fr_slab_config_t const *config, \
+ _type ## _slab_alloc_t alloc, \
+ _type ## _slab_reserve_t reserve, \
+ void *uctx, \
+ bool release_reset, \
+ bool reserve_mru) \
{ \
- MEM(*out = talloc_zero(ctx, _name ## _slab_list_t)); \
- (*out)->el = el; \
- (*out)->config = *config; \
- if ((*out)->config.elements_per_slab == 0) \
- (*out)->config.elements_per_slab = (config->min_elements ? config->min_elements : 1); \
- (*out)->alloc = alloc; \
- (*out)->reserve = reserve; \
- (*out)->uctx = uctx; \
- (*out)->release_reset = release_reset; \
- (*out)->reserve_mru = reserve_mru; \
- _name ## _slab_init(&(*out)->reserved); \
- _name ## _slab_init(&(*out)->avail); \
- if (el) (void) fr_event_timer_in(*out, el, &(*out)->ev, config->interval, _ ## _name ## _slab_cleanup, *out); \
- return 0; \
+ _name ## _slab_list_t *slab; \
+ MEM(slab = talloc_zero(ctx, _name ## _slab_list_t)); \
+ slab->el = el; \
+ slab->config = *config; \
+ if (slab->config.elements_per_slab == 0) { \
+ slab->config.elements_per_slab = (config->min_elements ? config->min_elements : 1); \
+ } \
+ slab->alloc = alloc; \
+ slab->reserve = reserve; \
+ slab->uctx = uctx; \
+ slab->release_reset = release_reset; \
+ slab->reserve_mru = reserve_mru; \
+ _name ## _slab_init(&slab->reserved); \
+ _name ## _slab_init(&slab->avail); \
+ if (el) { \
+ if (unlikely(fr_event_timer_in(slab, el, &slab->ev, config->interval, _ ## _name ## _slab_cleanup, slab) < 0)) { \
+ talloc_free(slab); \
+ return NULL; \
+ }; \
+ } \
+ return slab; \
} \
\
/** Callback for talloc freeing a slab element \
test_slab_list_t *test_slab_list;
test_element_t *test_elements[5];
test_uctx_t test_uctx, test_uctx2;
- int ret = -1;
/*
* Each slab will contain 2 elements, maximum of 4 elements allocated from slabs.
*/
- ret = test_slab_list_alloc(NULL, &test_slab_list, NULL, &def_slab_config, NULL, NULL, NULL, true, false);
- TEST_CHECK(ret == 0);
+ test_slab_list = test_slab_list_alloc(NULL, NULL, &def_slab_config, NULL, NULL, NULL, true, false);
TEST_CHECK(test_slab_list != NULL);
if (!test_slab_list) return;
{
test_slab_list_t *test_slab_list;
test_element_t *test_elements[5];
- int ret = -1;
fr_slab_config_t slab_config = def_slab_config;
/*
* Each slab will contain 2 elements, maximum of 4 elements allocated from slabs.
*/
slab_config.at_max_fail = true;
- ret = test_slab_list_alloc(NULL, &test_slab_list, NULL, &slab_config, NULL, NULL, NULL, true, false);
- TEST_CHECK(ret == 0);
+ test_slab_list = test_slab_list_alloc(NULL, NULL, &slab_config, NULL, NULL, NULL, true, false);
TEST_CHECK(test_slab_list != NULL);
if (!test_slab_list) return;
test_slab_list_t *test_slab_list;
test_element_t *test_elements[5];
test_uctx_t test_uctx;
- int ret = -1;
- ret = test_slab_list_alloc(NULL, &test_slab_list, NULL, &def_slab_config, NULL, NULL, NULL, true, false);
- TEST_CHECK(ret == 0);
+ test_slab_list = test_slab_list_alloc(NULL, NULL, &def_slab_config, NULL, NULL, NULL, true, false);
TEST_CHECK(test_slab_list != NULL);
if (!test_slab_list) return;
test_slab_list_t *test_slab_list;
test_element_t *test_elements[3];
test_uctx_t test_uctx;
- int ret = -1;
- ret = test_slab_list_alloc(NULL, &test_slab_list, NULL, &def_slab_config, NULL, NULL, NULL, false, false);
- TEST_CHECK(ret == 0);
+ test_slab_list = test_slab_list_alloc(NULL, NULL, &def_slab_config, NULL, NULL, NULL, false, false);
TEST_CHECK(test_slab_list != NULL);
if (!test_slab_list) return;
{
test_slab_list_t *test_slab_list;
test_element_t *test_elements[2];
- int ret = -1;
/*
* First use a slab list with reserve_mru = false to verify that the two reservations
* result in different elements being returned
*/
- ret = test_slab_list_alloc(NULL, &test_slab_list, NULL, &def_slab_config, NULL, NULL, NULL, true, false);
- TEST_CHECK(ret == 0);
+ test_slab_list = test_slab_list_alloc(NULL, NULL, &def_slab_config, NULL, NULL, NULL, true, false);
TEST_CHECK(test_slab_list != NULL);
if (!test_slab_list) return;
/*
* Now use a slab list with reserve_mru = true
*/
- ret = test_slab_list_alloc(NULL, &test_slab_list, NULL, &def_slab_config, NULL, NULL, NULL, true, true);
- TEST_CHECK(ret == 0);
+ test_slab_list = test_slab_list_alloc(NULL, NULL, &def_slab_config, NULL, NULL, NULL, true, true);
TEST_CHECK(test_slab_list != NULL);
if (!test_slab_list) return;
test_slab_list_t *test_slab_list;
test_element_t *test_element;
test_uctx_t test_uctx;
- int ret = -1;
- ret = test_slab_list_alloc(NULL, &test_slab_list, NULL, &def_slab_config, NULL, NULL, NULL, true, false);
- TEST_CHECK(ret == 0);
+ test_slab_list = test_slab_list_alloc(NULL, NULL, &def_slab_config, NULL, NULL, NULL, true, false);
TEST_CHECK(test_slab_list != NULL);
if (!test_slab_list) return;
test_slab_list_t *test_slab_list;
test_element_t *test_elements[2];
test_conf_t test_conf = { .initial = 10 };
- int ret = -1;
fr_slab_config_t slab_config = def_slab_config;
slab_config.elements_per_slab = 1;
- ret = test_slab_list_alloc(NULL, &test_slab_list, NULL, &slab_config, test_element_alloc, NULL, &test_conf, false, false);
- TEST_CHECK(ret == 0);
+ test_slab_list = test_slab_list_alloc(NULL, NULL, &slab_config, test_element_alloc, NULL, &test_conf, false, false);
TEST_CHECK(test_slab_list != NULL);
if (!test_slab_list) return;
test_slab_list_t *test_slab_list;
test_element_t *test_elements[2];
test_conf_t test_conf = { .initial = 10 };
- int ret = -1;
fr_slab_config_t slab_config = def_slab_config;
slab_config.elements_per_slab = 1;
- ret = test_slab_list_alloc(NULL, &test_slab_list, NULL, &slab_config, NULL, test_element_alloc, &test_conf, false, false);
- TEST_CHECK(ret == 0);
+ test_slab_list = test_slab_list_alloc(NULL, NULL, &slab_config, NULL, test_element_alloc, &test_conf, false, false);
TEST_CHECK(test_slab_list != NULL);
if (!test_slab_list) return;
test_slab_list_t *test_slab_list;
test_element_t *test_elements[2];
test_conf_t test_conf = { .initial = 10 };
- int ret = -1;
fr_slab_config_t slab_config = def_slab_config;
slab_config.elements_per_slab = 1;
- ret = test_slab_list_alloc(NULL, &test_slab_list, NULL, &slab_config, test_element_alloc, test_element_reserve, &test_conf, false, false);
- TEST_CHECK(ret == 0);
+ test_slab_list = test_slab_list_alloc(NULL, NULL, &slab_config, test_element_alloc, test_element_reserve, &test_conf, false, false);
TEST_CHECK(test_slab_list != NULL);
if (!test_slab_list) return;
fr_event_list_t *el;
test_slab_list_t *test_slab_list;
test_element_t *test_elements[6];
- int i, events, ret = -1;
+ int i, events;
fr_slab_config_t slab_config = def_slab_config;
el = fr_event_list_alloc(ctx, NULL, NULL);
fr_event_list_set_time_func(el, test_time);
slab_config.max_elements = 6;
- ret = test_slab_list_alloc(NULL, &test_slab_list, el, &slab_config, NULL, NULL, NULL, true, false);
- TEST_CHECK(ret == 0);
+ test_slab_list = test_slab_list_alloc(NULL, el, &slab_config, NULL, NULL, NULL, true, false);
TEST_CHECK(test_slab_list != NULL);
if (!test_slab_list) return;
fr_event_list_t *el;
test_slab_list_t *test_slab_list;
test_element_t *test_elements[20];
- int i, events, ret = -1;
+ int i, events;
fr_slab_config_t slab_config = def_slab_config;
el = fr_event_list_alloc(ctx, NULL, NULL);
slab_config.min_elements = 16;
slab_config.max_elements = 20;
- ret = test_slab_list_alloc(NULL, &test_slab_list, el, &slab_config, NULL, NULL, NULL, true, false);
- TEST_CHECK(ret == 0);
+ test_slab_list = test_slab_list_alloc(NULL, el, &slab_config, NULL, NULL, NULL, true, false);
TEST_CHECK(test_slab_list != NULL);
if (!test_slab_list) return;
fr_event_list_t *el;
test_slab_list_t *test_slab_list;
test_element_t *test_elements[20];
- int i, events, ret = -1;
+ int i, events;
fr_slab_config_t slab_config = def_slab_config;
el = fr_event_list_alloc(ctx, NULL, NULL);
slab_config.min_elements = 0;
slab_config.max_elements = 20;
- ret = test_slab_list_alloc(NULL, &test_slab_list, el, &slab_config, NULL, NULL, NULL, true, false);
- TEST_CHECK(ret == 0);
+ test_slab_list = test_slab_list_alloc(NULL, el, &slab_config, NULL, NULL, NULL, true, false);
TEST_CHECK(test_slab_list != NULL);
if (!test_slab_list) return;
fr_event_list_t *el;
test_slab_list_t *test_slab_list;
test_element_t *test_elements[20];
- int i, events, ret = -1;
+ int i, events;
fr_slab_config_t slab_config = def_slab_config;
el = fr_event_list_alloc(ctx, NULL, NULL);
slab_config.min_elements = 0;
slab_config.max_elements = 20;
- ret = test_slab_list_alloc(NULL, &test_slab_list, el, &slab_config, NULL, NULL, NULL, true, false);
- TEST_CHECK(ret == 0);
+ test_slab_list = test_slab_list_alloc(NULL, el, &slab_config, NULL, NULL, NULL, true, false);
TEST_CHECK(test_slab_list != NULL);
if (!test_slab_list) return;
{
test_slab_list_t *test_slab_list;
test_element_t *test_elements[2];
- int ret = -1;
fr_slab_config_t slab_config = def_slab_config;
slab_config.max_elements = 2;
slab_config.num_children = 1;
slab_config.child_pool_size = 128;
- ret = test_slab_list_alloc(NULL, &test_slab_list, NULL, &slab_config, NULL, NULL, NULL, false, false);
- TEST_CHECK(ret == 0);
+ test_slab_list = test_slab_list_alloc(NULL, NULL, &slab_config, NULL, NULL, NULL, false, false);
TEST_CHECK(test_slab_list != NULL);
if (!test_slab_list) return;