forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
io_uring: add abstraction around apoll cache
In preparation for adding limits, and one more user, abstract out the core bits of the allocation+free cache. Signed-off-by: Jens Axboe <[email protected]>
- Loading branch information
Showing
5 changed files
with
62 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#ifndef IOU_ALLOC_CACHE_H | ||
#define IOU_ALLOC_CACHE_H | ||
|
||
struct io_cache_entry { | ||
struct hlist_node node; | ||
}; | ||
|
||
static inline void io_alloc_cache_put(struct io_alloc_cache *cache, | ||
struct io_cache_entry *entry) | ||
{ | ||
hlist_add_head(&entry->node, &cache->list); | ||
} | ||
|
||
static inline struct io_cache_entry *io_alloc_cache_get(struct io_alloc_cache *cache) | ||
{ | ||
if (!hlist_empty(&cache->list)) { | ||
struct hlist_node *node = cache->list.first; | ||
|
||
hlist_del(node); | ||
return container_of(node, struct io_cache_entry, node); | ||
} | ||
|
||
return NULL; | ||
} | ||
|
||
static inline void io_alloc_cache_init(struct io_alloc_cache *cache) | ||
{ | ||
INIT_HLIST_HEAD(&cache->list); | ||
} | ||
|
||
static inline void io_alloc_cache_free(struct io_alloc_cache *cache, | ||
void (*free)(struct io_cache_entry *)) | ||
{ | ||
while (!hlist_empty(&cache->list)) { | ||
struct hlist_node *node = cache->list.first; | ||
|
||
hlist_del(node); | ||
free(container_of(node, struct io_cache_entry, node)); | ||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters