58 cache->
hashtable = g_hash_table_new(0, 0);
64 for(GList *l = cache->
lru; l; l = g_list_next(l))
82 g_slice_free1(
sizeof(*entry), entry);
84 g_list_free(cache->
lru);
92 int32_t result = g_hash_table_contains(cache->
hashtable, GINT_TO_POINTER(
key));
99 int (*
process)(
const uint32_t
key,
const void *data,
void *user_data),
106 g_hash_table_iter_init (&iter, cache->
hashtable);
107 while (g_hash_table_iter_next (&iter, &
key, &
value))
110 const int err =
process(GPOINTER_TO_INT(
key), entry->
data, user_data);
125 gpointer orig_key,
value;
128 res = g_hash_table_lookup_extended(
143 cache->
lru = g_list_remove_link(cache->
lru, entry->
link);
144 cache->
lru = g_list_concat(cache->
lru, entry->
link);
166 gpointer orig_key,
value;
171 res = g_hash_table_lookup_extended(
186 cache->
lru = g_list_remove_link(cache->
lru, entry->
link);
187 cache->
lru = g_list_concat(cache->
lru, entry->
link);
191 const pthread_t writer = dt_pthread_rwlock_get_writer(&entry->
lock);
194 assert(pthread_equal(writer, pthread_self()));
198 assert(!pthread_equal(writer, pthread_self()));
228 entry->
link = g_list_append(0, entry);
245 if(ret) fprintf(stderr,
"rwlock init: %d\n", ret);
247 g_hash_table_insert(cache->
hashtable, GINT_TO_POINTER(
key), entry);
254 const int write = ((mode ==
'w') || cache->
allocate);
263 cache->
lru = g_list_concat(cache->
lru, entry->
link);
273 gpointer orig_key,
value;
280 res = g_hash_table_lookup_extended(
306 gboolean removed = g_hash_table_remove(cache->
hashtable, GINT_TO_POINTER(
key));
309 cache->
lru = g_list_delete_link(cache->
lru, entry->
link);
327 g_slice_free1(
sizeof(*entry), entry);
336 GList *l = cache->
lru;
340 assert(entry->
link->data == entry);
355 g_hash_table_remove(cache->
hashtable, GINT_TO_POINTER(entry->
key));
356 cache->
lru = g_list_delete_link(cache->
lru, entry->
link);
374 g_slice_free1(
sizeof(*entry), entry);
380#if((__has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__)) && 1)
384# if defined(HAVE_THREAD_RWLOCK_ARCH_T_READERS)
385 if (entry->
lock.lock.__data.__readers <= 1)
386# elif defined(HAVE_THREAD_RWLOCK_ARCH_T_NR_READERS)
387 if (entry->
lock.lock.__data.__nr_readers <= 1)
389# error "No valid reader member"
394# if defined(HAVE_THREAD_RWLOCK_ARCH_T_READERS)
395 if (entry->
lock.__data.__readers <= 1)
396# elif defined(HAVE_THREAD_RWLOCK_ARCH_T_NR_READERS)
397 if(entry->
lock.__data.__nr_readers <= 1)
399# error "No valid reader member"
414 gboolean aligned_alloc)
416 if(!cache || !data || data_size == 0)
return -1;
419 if(g_hash_table_contains(cache->
hashtable, GINT_TO_POINTER(
key)))
431 entry->
cost = cost ? cost : data_size;
432 entry->
link = g_list_append(0, entry);
439 g_slice_free1(
sizeof(*entry), entry);
447 if(ret) fprintf(stderr,
"rwlock init: %d\n", ret);
449 g_hash_table_insert(cache->
hashtable, GINT_TO_POINTER(
key), entry);
450 cache->
lru = g_list_concat(cache->
lru, entry->
link);
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)
Definition ashift.c:3304
int32_t dt_cache_contains(dt_cache_t *cache, const uint32_t key)
Definition common/cache.c:89
int dt_cache_seed(dt_cache_t *cache, const uint32_t key, const void *data, size_t data_size, size_t cost, gboolean aligned_alloc)
Definition common/cache.c:413
void dt_cache_gc(dt_cache_t *cache, const float fill_ratio)
Definition common/cache.c:334
void dt_cache_release_with_caller(dt_cache_t *cache, dt_cache_entry_t *entry, const char *file, int line)
Definition common/cache.c:378
dt_cache_entry_t * dt_cache_testget(dt_cache_t *cache, const uint32_t key, char mode)
Definition common/cache.c:123
void dt_cache_init(dt_cache_t *cache, size_t entry_size, size_t cost_quota)
Definition common/cache.c:44
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:164
int dt_cache_remove(dt_cache_t *cache, const uint32_t key)
Definition common/cache.c:271
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:97
void dt_cache_cleanup(dt_cache_t *cache)
Definition common/cache.c:61
typedef void((*dt_cache_allocate_t)(void *userdata, dt_cache_entry_t *entry))
#define ASAN_POISON_MEMORY_REGION(addr, size)
Definition config.cmake.h:98
#define ASAN_UNPOISON_MEMORY_REGION(addr, size)
Definition config.cmake.h:99
void * dt_alloc_align(size_t size)
Definition darktable.c:447
#define dt_free_align(ptr)
Definition darktable.h:405
#define dt_free(ptr)
Definition darktable.h:380
static const dt_aligned_pixel_simd_t value
Definition darktable.h:501
#define dt_pthread_rwlock_tryrdlock
Definition dtpthread.h:395
#define dt_pthread_rwlock_destroy
Definition dtpthread.h:391
#define dt_pthread_rwlock_wrlock_with_caller(A, B, C)
Definition dtpthread.h:399
#define dt_pthread_rwlock_trywrlock_with_caller(A, B, C)
Definition dtpthread.h:401
#define dt_pthread_rwlock_tryrdlock_with_caller(A, B, C)
Definition dtpthread.h:400
static int dt_pthread_mutex_unlock(dt_pthread_mutex_t *mutex) RELEASE(mutex) NO_THREAD_SAFETY_ANALYSIS
Definition dtpthread.h:374
static int dt_pthread_mutex_init(dt_pthread_mutex_t *mutex, const pthread_mutexattr_t *mutexattr)
Definition dtpthread.h:359
#define dt_pthread_rwlock_trywrlock
Definition dtpthread.h:396
static int dt_pthread_mutex_destroy(dt_pthread_mutex_t *mutex)
Definition dtpthread.h:379
#define dt_pthread_rwlock_init
Definition dtpthread.h:390
#define dt_pthread_rwlock_unlock
Definition dtpthread.h:392
static int dt_pthread_mutex_lock(dt_pthread_mutex_t *mutex) ACQUIRE(mutex) NO_THREAD_SAFETY_ANALYSIS
Definition dtpthread.h:364
#define dt_pthread_rwlock_rdlock_with_caller(A, B, C)
Definition dtpthread.h:398
Definition common/cache.h:33
uint32_t key
Definition common/cache.h:40
GList * link
Definition common/cache.h:37
size_t data_size
Definition common/cache.h:35
dt_pthread_rwlock_t lock
Definition common/cache.h:38
int _lock_demoting
Definition common/cache.h:39
void * data
Definition common/cache.h:34
size_t cost
Definition common/cache.h:36
Definition common/cache.h:48
size_t cost
Definition common/cache.h:52
GList * lru
Definition common/cache.h:56
size_t cost_quota
Definition common/cache.h:53
void * allocate_data
Definition common/cache.h:61
GHashTable * hashtable
Definition common/cache.h:55
dt_cache_allocate_t allocate
Definition common/cache.h:59
dt_pthread_mutex_t lock
Definition common/cache.h:49
size_t entry_size
Definition common/cache.h:51
dt_cache_allocate_t cleanup
Definition common/cache.h:60
void * cleanup_data
Definition common/cache.h:62