1 /* 2 * Copyright 2021 Google LLC 3 * SPDX-License-Identifier: MIT 4 */ 5 6 #ifndef VN_RENDERER_INTERNAL_H 7 #define VN_RENDERER_INTERNAL_H 8 9 #include "vn_renderer.h" 10 11 typedef void (*vn_renderer_shmem_cache_destroy_func)( 12 struct vn_renderer *renderer, struct vn_renderer_shmem *shmem); 13 14 struct vn_renderer_shmem_cache { 15 bool initialized; 16 17 struct vn_renderer *renderer; 18 vn_renderer_shmem_cache_destroy_func destroy_func; 19 20 simple_mtx_t mutex; 21 22 /* cache shmems up to 2^26 in size (see choose_bucket) */ 23 struct vn_renderer_shmem_bucket { 24 struct list_head shmems; 25 } buckets[27]; 26 27 /* which buckets have shmems */ 28 uint32_t bucket_mask; 29 30 struct { 31 uint32_t cache_skip_count; 32 uint32_t cache_hit_count; 33 uint32_t cache_miss_count; 34 } debug; 35 }; 36 37 void 38 vn_renderer_shmem_cache_init( 39 struct vn_renderer_shmem_cache *cache, 40 struct vn_renderer *renderer, 41 vn_renderer_shmem_cache_destroy_func destroy_func); 42 43 void 44 vn_renderer_shmem_cache_fini(struct vn_renderer_shmem_cache *cache); 45 46 bool 47 vn_renderer_shmem_cache_add(struct vn_renderer_shmem_cache *cache, 48 struct vn_renderer_shmem *shmem); 49 50 struct vn_renderer_shmem * 51 vn_renderer_shmem_cache_get(struct vn_renderer_shmem_cache *cache, 52 size_t size); 53 54 void 55 vn_renderer_shmem_cache_debug_dump(struct vn_renderer_shmem_cache *cache); 56 57 #endif /* VN_RENDERER_INTERNAL_H */ 58