*/
typedef struct fr_fifo_t fr_fifo_t;
typedef void (*fr_fifo_free_t)(void *);
-fr_fifo_t *fr_fifo_create(TALLOC_CTX *ctx, int max_entries, fr_fifo_free_t freeNode);
+
+/** Creates a fifo that verifies elements are of a specific talloc type
+ *
+ * @param[in] _ctx to tie fifo lifetime to.
+ * If ctx is freed, fifo will free any nodes, calling the
+ * free function if set.
+ * @param[in] _max_entries Maximum number of entries.
+ * @param[in] _talloc_type of elements.
+ * @param[in] _node_free Optional function used to free data if tree nodes are
+ * deleted or replaced.
+ * @return
+ * - A new fifo on success.
+ * - NULL on failure.
+ */
+#define fr_fifo_talloc_create(_ctx, _talloc_type, _max_entries, _free_node) \
+ _fr_fifo_create(_ctx, #_talloc_type, _max_entries, _free_node)
+
+/** Creates a fifo
+ *
+ * @param[in] _ctx to tie fifo lifetime to.
+ * If ctx is freed, fifo will free any nodes, calling the
+ * free function if set.
+ * @param[in] _max_entries Maximum number of entries.
+ * @param[in] _node_free Optional function used to free data if tree nodes are
+ * deleted or replaced.
+ * @return
+ * - A new fifo on success.
+ * - NULL on failure.
+ */
+#define fr_fifo_create(_ctx, _max_entries, _free_node) \
+ _fr_fifo_create(_ctx, NULL, _max_entries, _free_node)
+
+fr_fifo_t *_fr_fifo_create(TALLOC_CTX *ctx, char const *type, int max_entries, fr_fifo_free_t free_node);
int fr_fifo_push(fr_fifo_t *fi, void *data);
void *fr_fifo_pop(fr_fifo_t *fi);
void *fr_fifo_peek(fr_fifo_t *fi);
* @param[in] _node_free Optional function used to free data if tree nodes are
* deleted or replaced.
* @param[in] _flags To modify tree behaviour.
+ * @return
+ * - A new rbtree on success.
+ * - NULL on failure.
*/
#define rbtree_talloc_create(_ctx, _cmp, _talloc_type, _node_free, _flags) \
_rbtree_create(_ctx, _cmp, #_talloc_type, _node_free, _flags)
unsigned int max; //!< How many elements were created in the fifo.
fr_fifo_free_t free_node; //!< Function to call to free nodes when the fifo is freed.
+ char const *type; //!< Type of elements.
+
void *data[1];
};
* the callers must synchronise their access.
*
* @param[in] ctx to allocate fifo array in.
+ * @param[in] type Talloc type of elements (may be NULL).
* @param[in] max The maximum number of elements allowed.
* @param[in] free_node Function to use to free node data if the fifo is freed.
* @return
* - A new fifo queue.
* - NULL on error.
*/
-fr_fifo_t *fr_fifo_create(TALLOC_CTX *ctx, int max, fr_fifo_free_t free_node)
+fr_fifo_t *_fr_fifo_create(TALLOC_CTX *ctx, char const *type, int max, fr_fifo_free_t free_node)
{
fr_fifo_t *fi;
talloc_set_destructor(fi, _fifo_free);
fi->max = max;
+ fi->type = type;
fi->free_node = free_node;
return fi;
if (fi->num >= fi->max) return -1;
+#ifndef TALLOC_GET_TYPE_ABORT_NOOP
+ if (fi->type) _talloc_get_type_abort(data, fi->type, __location__);
+#endif
+
fi->data[fi->last++] = data;
if (fi->last >= fi->max) fi->last = 0;
fi->num++;