62 cache->
hashtable = g_hash_table_new(0, 0);
68 for(GList *l = cache->
lru; l; l = g_list_next(l))
86 g_slice_free1(
sizeof(*entry), entry);
88 g_list_free(cache->
lru);
96 int32_t result = g_hash_table_contains(cache->
hashtable, GINT_TO_POINTER(
key));
103 int (*
process)(
const uint32_t
key,
const void *
data,
void *user_data),
110 g_hash_table_iter_init (&iter, cache->
hashtable);
111 while (g_hash_table_iter_next (&iter, &
key, &
value))
114 const int err =
process(GPOINTER_TO_INT(
key), entry->
data, user_data);
129 gpointer orig_key,
value;
132 res = g_hash_table_lookup_extended(
147 cache->
lru = g_list_remove_link(cache->
lru, entry->
link);
148 cache->
lru = g_list_concat(cache->
lru, entry->
link);
170 gpointer orig_key,
value;
175 res = g_hash_table_lookup_extended(
190 cache->
lru = g_list_remove_link(cache->
lru, entry->
link);
191 cache->
lru = g_list_concat(cache->
lru, entry->
link);
220 entry->
link = g_list_append(0, entry);
233 g_list_free(entry->
link);
234 g_slice_free1(
sizeof(*entry), entry);
240 if(ret) fprintf(stderr,
"rwlock init: %d\n", ret);
242 g_hash_table_insert(cache->
hashtable, GINT_TO_POINTER(
key), entry);
249 const int write = ((mode ==
'w') || cache->
allocate);
258 cache->
lru = g_list_concat(cache->
lru, entry->
link);
268 gpointer orig_key,
value;
275 res = g_hash_table_lookup_extended(
301 gboolean removed = g_hash_table_remove(cache->
hashtable, GINT_TO_POINTER(
key));
304 cache->
lru = g_list_delete_link(cache->
lru, entry->
link);
322 g_slice_free1(
sizeof(*entry), entry);
331 const size_t before = cache->
cost;
333 const size_t reclaimed = before - cache->
cost;
342 GList *l = cache->
lru;
346 assert(entry->
link->data == entry);
361 g_hash_table_remove(cache->
hashtable, GINT_TO_POINTER(entry->
key));
362 cache->
lru = g_list_delete_link(cache->
lru, entry->
link);
380 g_slice_free1(
sizeof(*entry), entry);
386#if((__has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__)) && 1)
395# if defined(HAVE_THREAD_RWLOCK_ARCH_T_READERS)
396 if(entry->
lock.lock.__data.__readers <= 1)
397# elif defined(HAVE_THREAD_RWLOCK_ARCH_T_NR_READERS)
398 if(entry->
lock.lock.__data.__nr_readers <= 1)
423 if(g_hash_table_contains(cache->
hashtable, GINT_TO_POINTER(
key)))
435 entry->
cost = cost ? cost : data_size;
436 entry->
link = g_list_append(0, entry);
446 g_list_free(entry->
link);
447 g_slice_free1(
sizeof(*entry), entry);
455 if(ret) fprintf(stderr,
"rwlock init: %d\n", ret);
457 g_hash_table_insert(cache->
hashtable, GINT_TO_POINTER(
key), entry);
458 cache->
lru = g_list_concat(cache->
lru, entry->
link);
__DT_CLONE_TARGETS__ int process(struct dt_iop_module_t *self, const dt_dev_pixelpipe_t *pipe, const dt_dev_pixelpipe_iop_t *piece, const void *const ivoid, void *const ovoid)
typedef void((*dt_cache_allocate_t)(void *userdata, dt_cache_entry_t *entry))
#define ASAN_POISON_MEMORY_REGION(addr, size)
#define ASAN_UNPOISON_MEMORY_REGION(addr, size)
void * dt_alloc_align(size_t size)
Allocate cacheline-aligned memory.
static int dt_pthread_rwlock_trywrlock(dt_pthread_rwlock_t *rwlock) TRY_ACQUIRE(0
#define dt_pthread_rwlock_wrlock_with_caller(A, B, C)
#define dt_pthread_rwlock_trywrlock_with_caller(A, B, C)
static int dt_pthread_rwlock_unlock(dt_pthread_rwlock_t *rwlock) RELEASE_GENERIC(rwlock) NO_THREAD_SAFETY_ANALYSIS
#define dt_pthread_rwlock_tryrdlock_with_caller(A, B, C)
static int dt_pthread_mutex_unlock(dt_pthread_mutex_t *mutex) RELEASE(mutex) NO_THREAD_SAFETY_ANALYSIS
static int dt_pthread_mutex_init(dt_pthread_mutex_t *mutex, const pthread_mutexattr_t *mutexattr)
Initialise a mutex. With mutexattr NULL – which is how 54 of the 56 call sites in this tree spell it ...
static int dt_pthread_rwlock_destroy(dt_pthread_rwlock_t *lock)
static int dt_pthread_rwlock_tryrdlock(dt_pthread_rwlock_t *rwlock) TRY_ACQUIRE_SHARED(0
static int dt_pthread_mutex_destroy(dt_pthread_mutex_t *mutex)
static int dt_pthread_rwlock_init(dt_pthread_rwlock_t *lock, const pthread_rwlockattr_t *attr)
static int dt_pthread_mutex_lock(dt_pthread_mutex_t *mutex) ACQUIRE(mutex) NO_THREAD_SAFETY_ANALYSIS
#define dt_pthread_rwlock_rdlock_with_caller(A, B, C)
memcpy(roundtrip, origin, sizeof(roundtrip))
#define IS_NULL_PTR(p)
C is way too permissive with !=, == and if(var) checks, which can mean too many things depending on w...
#define dt_free_align(ptr)
Release memory from dt_alloc_align() and set ptr to NULL.
int32_t dt_cache_contains(dt_cache_t *cache, const uint32_t key)
void dt_cache_entry_free_detached(dt_cache_entry_t *entry)
Release an entry from dt_cache_entry_new_detached(), and its data. NULL-safe.
void dt_cache_release_with_caller(dt_cache_t *cache, dt_cache_entry_t *entry, const char *file, int line)
static void _cache_gc_locked(dt_cache_t *cache, const float fill_ratio)
dt_cache_entry_t * dt_cache_testget(dt_cache_t *cache, const uint32_t key, char mode)
int dt_cache_seed(dt_cache_t *cache, const uint32_t key, const void *data, size_t data_size, size_t cost)
dt_cache_entry_t * dt_cache_entry_new_detached(void)
Allocate a cache entry that belongs to NO cache, for a one-shot decode.
void dt_cache_init(dt_cache_t *cache, size_t entry_size, size_t cost_quota)
dt_cache_entry_t * dt_cache_get_with_caller(dt_cache_t *cache, const uint32_t key, char mode, const char *file, int line)
size_t dt_cache_gc(dt_cache_t *cache, const float fill_ratio)
int dt_cache_remove(dt_cache_t *cache, const uint32_t key)
int dt_cache_for_all(dt_cache_t *cache, int(*process)(const uint32_t key, const void *data, void *user_data), void *user_data)
void dt_cache_cleanup(dt_cache_t *cache)
dt_cache_allocate_t allocate
dt_cache_allocate_t cleanup