1 #ifndef IOU_ALLOC_CACHE_H
2 #define IOU_ALLOC_CACHE_H
4 struct io_cache_entry {
5 struct hlist_node node;
8 static inline void io_alloc_cache_put(struct io_alloc_cache *cache,
9 struct io_cache_entry *entry)
11 hlist_add_head(&entry->node, &cache->list);
14 static inline struct io_cache_entry *io_alloc_cache_get(struct io_alloc_cache *cache)
16 if (!hlist_empty(&cache->list)) {
17 struct hlist_node *node = cache->list.first;
20 return container_of(node, struct io_cache_entry, node);
26 static inline void io_alloc_cache_init(struct io_alloc_cache *cache)
28 INIT_HLIST_HEAD(&cache->list);
31 static inline void io_alloc_cache_free(struct io_alloc_cache *cache,
32 void (*free)(struct io_cache_entry *))
34 while (!hlist_empty(&cache->list)) {
35 struct hlist_node *node = cache->list.first;
38 free(container_of(node, struct io_cache_entry, node));