]>
git.ipfire.org Git - thirdparty/linux.git/blob - io_uring/alloc_cache.h
1 #ifndef IOU_ALLOC_CACHE_H
2 #define IOU_ALLOC_CACHE_H
5 * Don't allow the cache to grow beyond this size.
7 #define IO_ALLOC_CACHE_MAX 512
9 struct io_cache_entry
{
10 struct hlist_node node
;
13 static inline bool io_alloc_cache_put(struct io_alloc_cache
*cache
,
14 struct io_cache_entry
*entry
)
16 if (cache
->nr_cached
< IO_ALLOC_CACHE_MAX
) {
18 hlist_add_head(&entry
->node
, &cache
->list
);
24 static inline struct io_cache_entry
*io_alloc_cache_get(struct io_alloc_cache
*cache
)
26 if (!hlist_empty(&cache
->list
)) {
27 struct hlist_node
*node
= cache
->list
.first
;
30 return container_of(node
, struct io_cache_entry
, node
);
36 static inline void io_alloc_cache_init(struct io_alloc_cache
*cache
)
38 INIT_HLIST_HEAD(&cache
->list
);
42 static inline void io_alloc_cache_free(struct io_alloc_cache
*cache
,
43 void (*free
)(struct io_cache_entry
*))
45 while (!hlist_empty(&cache
->list
)) {
46 struct hlist_node
*node
= cache
->list
.first
;
49 free(container_of(node
, struct io_cache_entry
, node
));