46 cache->
hashtable = g_hash_table_new(0, 0);
52 for(GList *l = cache->
lru; l; l = g_list_next(l))
67 g_slice_free1(
sizeof(*entry), entry);
69 g_list_free(cache->
lru);
76 int32_t result = g_hash_table_contains(cache->
hashtable, GINT_TO_POINTER(
key));
83 int (*
process)(
const uint32_t
key,
const void *data,
void *user_data),
90 g_hash_table_iter_init (&iter, cache->
hashtable);
91 while (g_hash_table_iter_next (&iter, &
key, &value))
94 const int err =
process(GPOINTER_TO_INT(
key), entry->
data, user_data);
109 gpointer orig_key, value;
112 res = g_hash_table_lookup_extended(
113 cache->
hashtable, GINT_TO_POINTER(
key), &orig_key, &value);
127 cache->
lru = g_list_remove_link(cache->
lru, entry->
link);
128 cache->
lru = g_list_concat(cache->
lru, entry->
link);
150 gpointer orig_key, value;
155 res = g_hash_table_lookup_extended(
156 cache->
hashtable, GINT_TO_POINTER(
key), &orig_key, &value);
170 cache->
lru = g_list_remove_link(cache->
lru, entry->
link);
171 cache->
lru = g_list_concat(cache->
lru, entry->
link);
175 const pthread_t writer = dt_pthread_rwlock_get_writer(&entry->
lock);
178 assert(pthread_equal(writer, pthread_self()));
182 assert(!pthread_equal(writer, pthread_self()));
212 entry->
link = g_list_append(0, entry);
229 if(ret) fprintf(stderr,
"rwlock init: %d\n", ret);
231 g_hash_table_insert(cache->
hashtable, GINT_TO_POINTER(
key), entry);
238 const int write = ((mode ==
'w') || cache->
allocate);
247 cache->
lru = g_list_concat(cache->
lru, entry->
link);
257 gpointer orig_key, value;
264 res = g_hash_table_lookup_extended(
265 cache->
hashtable, GINT_TO_POINTER(
key), &orig_key, &value);
290 gboolean removed = g_hash_table_remove(cache->
hashtable, GINT_TO_POINTER(
key));
293 cache->
lru = g_list_delete_link(cache->
lru, entry->
link);
308 g_slice_free1(
sizeof(*entry), entry);
317 GList *l = cache->
lru;
321 assert(entry->
link->data == entry);
336 g_hash_table_remove(cache->
hashtable, GINT_TO_POINTER(entry->
key));
337 cache->
lru = g_list_delete_link(cache->
lru, entry->
link);
352 g_slice_free1(
sizeof(*entry), entry);
358#if((__has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__)) && 1)
362# if defined(HAVE_THREAD_RWLOCK_ARCH_T_READERS)
363 if (entry->
lock.lock.__data.__readers <= 1)
364# elif defined(HAVE_THREAD_RWLOCK_ARCH_T_NR_READERS)
365 if (entry->
lock.lock.__data.__nr_readers <= 1)
367# error "No valid reader member"
372# if defined(HAVE_THREAD_RWLOCK_ARCH_T_READERS)
373 if (entry->
lock.__data.__readers <= 1)
374# elif defined(HAVE_THREAD_RWLOCK_ARCH_T_NR_READERS)
375 if(entry->
lock.__data.__nr_readers <= 1)
377# error "No valid reader member"
void process(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const void *const ivoid, void *const ovoid, const dt_iop_roi_t *const roi_in, const dt_iop_roi_t *const roi_out)
Definition ashift.c:3088
typedef void((*dt_cache_allocate_t)(void *userdata, dt_cache_entry_t *entry))
int32_t dt_cache_contains(dt_cache_t *cache, const uint32_t key)
Definition common/cache.c:73
void dt_cache_gc(dt_cache_t *cache, const float fill_ratio)
Definition common/cache.c:315
void dt_cache_release_with_caller(dt_cache_t *cache, dt_cache_entry_t *entry, const char *file, int line)
Definition common/cache.c:356
dt_cache_entry_t * dt_cache_testget(dt_cache_t *cache, const uint32_t key, char mode)
Definition common/cache.c:107
void dt_cache_init(dt_cache_t *cache, size_t entry_size, size_t cost_quota)
Definition common/cache.c:32
dt_cache_entry_t * dt_cache_get_with_caller(dt_cache_t *cache, const uint32_t key, char mode, const char *file, int line)
Definition common/cache.c:148
int dt_cache_remove(dt_cache_t *cache, const uint32_t key)
Definition common/cache.c:255
int dt_cache_for_all(dt_cache_t *cache, int(*process)(const uint32_t key, const void *data, void *user_data), void *user_data)
Definition common/cache.c:81
void dt_cache_cleanup(dt_cache_t *cache)
Definition common/cache.c:49
#define ASAN_POISON_MEMORY_REGION(addr, size)
Definition config.cmake.h:67
#define ASAN_UNPOISON_MEMORY_REGION(addr, size)
Definition config.cmake.h:68
#define dt_free_align(A)
Definition darktable.h:334
#define dt_pthread_rwlock_tryrdlock
Definition dtpthread.h:342
#define dt_pthread_rwlock_destroy
Definition dtpthread.h:338
#define dt_pthread_rwlock_wrlock_with_caller(A, B, C)
Definition dtpthread.h:346
#define dt_pthread_rwlock_trywrlock_with_caller(A, B, C)
Definition dtpthread.h:348
#define dt_pthread_rwlock_tryrdlock_with_caller(A, B, C)
Definition dtpthread.h:347
static int dt_pthread_mutex_unlock(dt_pthread_mutex_t *mutex) RELEASE(mutex) NO_THREAD_SAFETY_ANALYSIS
Definition dtpthread.h:321
static int dt_pthread_mutex_init(dt_pthread_mutex_t *mutex, const pthread_mutexattr_t *mutexattr)
Definition dtpthread.h:306
#define dt_pthread_rwlock_trywrlock
Definition dtpthread.h:343
static int dt_pthread_mutex_destroy(dt_pthread_mutex_t *mutex)
Definition dtpthread.h:326
#define dt_pthread_rwlock_init
Definition dtpthread.h:337
#define dt_pthread_rwlock_unlock
Definition dtpthread.h:339
static int dt_pthread_mutex_lock(dt_pthread_mutex_t *mutex) ACQUIRE(mutex) NO_THREAD_SAFETY_ANALYSIS
Definition dtpthread.h:311
#define dt_pthread_rwlock_rdlock_with_caller(A, B, C)
Definition dtpthread.h:345
uint32_t key
Definition cache.h:34
GList * link
Definition cache.h:31
size_t data_size
Definition cache.h:29
dt_pthread_rwlock_t lock
Definition cache.h:32
int _lock_demoting
Definition cache.h:33
void * data
Definition cache.h:28
size_t cost
Definition cache.h:30
size_t cost
Definition cache.h:46
GList * lru
Definition cache.h:50
size_t cost_quota
Definition cache.h:47
void * allocate_data
Definition cache.h:55
GHashTable * hashtable
Definition cache.h:49
dt_cache_allocate_t allocate
Definition cache.h:53
dt_pthread_mutex_t lock
Definition cache.h:43
size_t entry_size
Definition cache.h:45
dt_cache_allocate_t cleanup
Definition cache.h:54
void * cleanup_data
Definition cache.h:56
#define dt_alloc_align(B)
Definition tests/cache.c:22