1 #ifndef IOU_ALLOC_CACHE_H 2 #define IOU_ALLOC_CACHE_H 3 4 struct io_cache_entry { 5 struct hlist_node node; 6 }; 7 8 static inline void io_alloc_cache_put(struct io_alloc_cache *cache, 9 struct io_cache_entry *entry) 10 { 11 hlist_add_head(&entry->node, &cache->list); 12 } 13 14 static inline struct io_cache_entry *io_alloc_cache_get(struct io_alloc_cache *cache) 15 { 16 if (!hlist_empty(&cache->list)) { 17 struct hlist_node *node = cache->list.first; 18 19 hlist_del(node); 20 return container_of(node, struct io_cache_entry, node); 21 } 22 23 return NULL; 24 } 25 26 static inline void io_alloc_cache_init(struct io_alloc_cache *cache) 27 { 28 INIT_HLIST_HEAD(&cache->list); 29 } 30 31 static inline void io_alloc_cache_free(struct io_alloc_cache *cache, 32 void (*free)(struct io_cache_entry *)) 33 { 34 while (!hlist_empty(&cache->list)) { 35 struct hlist_node *node = cache->list.first; 36 37 hlist_del(node); 38 free(container_of(node, struct io_cache_entry, node)); 39 } 40 } 41 #endif 42