63 return cache_entry->
size / (1024 * 1024);
82 if(cache_entry == NULL)
93 if((!used || force) && !locked)
96 g_hash_table_remove(cache->
entries, GINT_TO_POINTER(hash));
170 lru->
max_age = g_get_monotonic_time();
202 if(remaining_mem < safety_margin)
207 fprintf(stdout,
"new pipeline cache size : %lu MiB\n", cache->
max_memory / (1024 * 1024));
210 "Processing full-resolution images may not "
211 "possible anymore.\n"));
227 if(!cache_entry)
return NULL;
233 while(cache_entry->
data == NULL && g_hash_table_size(cache->
entries) > 0)
239 if(!cache_entry->
data)
246 cache_entry->
age = 0;
247 cache_entry->
dsc = dsc;
248 cache_entry->
hash = hash;
249 cache_entry->
id = id;
255 g_hash_table_insert(cache->
entries, GINT_TO_POINTER(hash), cache_entry);
264 if(!cache_entry)
return;
267 cache_entry->
data = NULL;
269 g_free(cache_entry->
name);
290 g_hash_table_destroy(cache->
entries);
296 const size_t size,
const char *
name,
const int id,
306 gboolean cache_entry_found = (cache_entry != NULL);
315 cache_entry->
age = g_get_monotonic_time();
316 *data = cache_entry->
data;
317 *dsc = &cache_entry->
dsc;
329 if(entry) *entry = cache_entry;
332 return !cache_entry_found;
342 if(cache_entry) cache->
hits++;
346 cache_entry->
age = g_get_monotonic_time();
347 *data = cache_entry->
data;
348 *dsc = &cache_entry->
dsc;
355 if(entry) *entry = cache_entry;
358 return cache_entry != NULL;
365 const int id = GPOINTER_TO_INT(user_data);
373 return (cache_entry->
id ==
id ||
id == -1) && !used && !locked;
396 if(entry) *entry = NULL;
398 g_hash_table_iter_init(&iter, cache->
entries);
399 while(g_hash_table_iter_next(&iter, &
key, &value))
402 if(cache_entry->
data == data)
404 hash = cache_entry->
hash;
405 if(entry) *entry = cache_entry;
443 if(cache_entry == NULL)
475 if(cache_entry == NULL)
499 if(cache_entry == NULL)
523 if(cache_entry == NULL)
535 if(cache_entry == NULL)
538 if(cache_entry && cache_entry->
auto_destroy &&
id == cache_entry->
id)
541 g_hash_table_remove(cache->
entries, GINT_TO_POINTER(hash));
static void error(char *msg)
Definition ashift_lsd.c:191
#define TRUE
Definition ashift_lsd.c:151
#define FALSE
Definition ashift_lsd.c:147
int dt_atomic_get_int(dt_atomic_int *var)
Definition atomic.h:46
int dt_atomic_sub_int(dt_atomic_int *var, int decr)
Definition atomic.h:48
int dt_atomic_add_int(dt_atomic_int *var, int incr)
Definition atomic.h:47
atomic_int dt_atomic_int
Definition atomic.h:44
void dt_control_log(const char *msg,...)
Definition control.c:424
darktable_t darktable
Definition darktable.c:111
size_t dt_get_singlebuffer_mem()
Definition darktable.c:1548
size_t dt_get_available_mem()
Definition darktable.c:1535
void dt_print(dt_debug_thread_t thread, const char *msg,...)
Definition darktable.c:1395
@ DT_DEBUG_PIPE
Definition darktable.h:497
@ DT_DEBUG_VERBOSE
Definition darktable.h:499
#define dt_free_align(A)
Definition darktable.h:334
#define dt_pthread_rwlock_destroy
Definition dtpthread.h:338
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_wrlock
Definition dtpthread.h:341
#define dt_pthread_rwlock_t
Definition dtpthread.h:336
#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
Definition dtpthread.h:340
size_t size
Definition mipmap_cache.c:3
int dt_dev_pixelpipe_cache_remove(dt_dev_pixelpipe_cache_t *cache, const uint64_t hash, const gboolean force, dt_pixel_cache_entry_t *cache_entry)
Arbitrarily remove the cache entry matching hash. Entries having a reference count > 0 (inter-thread ...
Definition pixelpipe_cache.c:112
void dt_dev_pixelpipe_cache_ref_count_entry(dt_dev_pixelpipe_cache_t *cache, const uint64_t hash, gboolean lock, dt_pixel_cache_entry_t *cache_entry)
Increase/Decrease the reference count on the cache line as to prevent LRU item removal....
Definition pixelpipe_cache.c:462
size_t dt_pixel_cache_get_size(dt_pixel_cache_entry_t *cache_entry)
Definition pixelpipe_cache.c:61
void dt_dev_pixelpipe_cache_rdlock_entry(dt_dev_pixelpipe_cache_t *cache, const uint64_t hash, gboolean lock, dt_pixel_cache_entry_t *cache_entry)
Lock or release the read lock on the entry.
Definition pixelpipe_cache.c:495
void dt_dev_pixelpipe_cache_cleanup(dt_dev_pixelpipe_cache_t *cache)
Definition pixelpipe_cache.c:286
void _cache_get_oldest(gpointer key, gpointer value, gpointer user_data)
Definition pixelpipe_cache.c:130
dt_dev_pixelpipe_cache_t * dt_dev_pixelpipe_cache_init(size_t max_memory)
Definition pixelpipe_cache.c:274
void dt_dev_pixelpipe_cache_wrlock_entry(dt_dev_pixelpipe_cache_t *cache, const uint64_t hash, gboolean lock, dt_pixel_cache_entry_t *cache_entry)
Lock or release the write lock on the entry.
Definition pixelpipe_cache.c:471
void dt_dev_pixelpipe_cache_print(dt_dev_pixelpipe_cache_t *cache)
Definition pixelpipe_cache.c:547
void dt_dev_pixelpipe_cache_flush(dt_dev_pixelpipe_cache_t *cache, const int id)
Remove cache lines matching id. Entries locked in read/write or having reference count greater than 0...
Definition pixelpipe_cache.c:376
void dt_dev_pixel_pipe_cache_auto_destroy_apply(dt_dev_pixelpipe_cache_t *cache, const uint64_t hash, const int id, dt_pixel_cache_entry_t *cache_entry)
Definition pixelpipe_cache.c:531
static int _non_thread_safe_pixel_pipe_cache_remove_lru(dt_dev_pixelpipe_cache_t *cache)
Definition pixelpipe_cache.c:167
uint64_t dt_dev_pixelpipe_cache_get_hash_data(dt_dev_pixelpipe_cache_t *cache, void *data, dt_pixel_cache_entry_t **entry)
Find the hash of the cache entry holding the buffer data.
Definition pixelpipe_cache.c:414
static dt_pixel_cache_entry_t * dt_pixel_cache_new_entry(const uint64_t hash, const size_t size, const dt_iop_buffer_dsc_t dsc, const char *name, const int id, dt_dev_pixelpipe_cache_t *cache)
Definition pixelpipe_cache.c:195
void dt_dev_pixelpipe_cache_flag_auto_destroy(dt_dev_pixelpipe_cache_t *cache, uint64_t hash, dt_pixel_cache_entry_t *cache_entry)
Flag the cache entry matching hash as "auto_destroy". This is useful for short-lived/disposable cache...
Definition pixelpipe_cache.c:519
int dt_dev_pixel_pipe_cache_remove_lru(dt_dev_pixelpipe_cache_t *cache)
Definition pixelpipe_cache.c:186
dt_pixel_cache_entry_t * dt_dev_pixelpipe_cache_get_entry_from_data(dt_dev_pixelpipe_cache_t *cache, void *data)
Return a reference to the cache entry holding the data buffer, or NULL if not found.
Definition pixelpipe_cache.c:423
int dt_dev_pixelpipe_cache_get_existing(dt_dev_pixelpipe_cache_t *cache, const uint64_t hash, void **data, dt_iop_buffer_dsc_t **dsc, dt_pixel_cache_entry_t **entry)
Get an existing cache line from the cache. This is similar to dt_dev_pixelpipe_cache_get,...
Definition pixelpipe_cache.c:335
static void _free_cache_entry(dt_pixel_cache_entry_t *cache_entry)
Definition pixelpipe_cache.c:262
dt_pixel_cache_entry_t * dt_dev_pixelpipe_cache_get_entry(dt_dev_pixelpipe_cache_t *cache, const uint64_t hash)
Get an internal reference to the cache entry matching hash. If you are going to access this entry mor...
Definition pixelpipe_cache.c:52
dt_pixel_cache_entry_t * _non_threadsafe_cache_get_entry(dt_dev_pixelpipe_cache_t *cache, const uint64_t hash)
Definition pixelpipe_cache.c:46
void _non_thread_safe_cache_ref_count_entry(dt_dev_pixelpipe_cache_t *cache, const uint64_t hash, gboolean lock, dt_pixel_cache_entry_t *cache_entry)
Definition pixelpipe_cache.c:440
void dt_pixel_cache_message(dt_pixel_cache_entry_t *cache_entry, const char *message, gboolean verbose)
Definition pixelpipe_cache.c:67
int _non_thread_safe_cache_remove(dt_dev_pixelpipe_cache_t *cache, const uint64_t hash, const gboolean force, dt_pixel_cache_entry_t *cache_entry)
Definition pixelpipe_cache.c:79
gboolean _for_each_remove(gpointer key, gpointer value, gpointer user_data)
Definition pixelpipe_cache.c:362
uint64_t _non_thread_safe_cache_get_hash_data(dt_dev_pixelpipe_cache_t *cache, void *data, dt_pixel_cache_entry_t **entry)
Definition pixelpipe_cache.c:391
int dt_dev_pixelpipe_cache_get(dt_dev_pixelpipe_cache_t *cache, const uint64_t hash, const size_t size, const char *name, const int id, void **data, dt_iop_buffer_dsc_t **dsc, dt_pixel_cache_entry_t **entry)
Get a cache line from the cache. This internally increases the reference count, so you have to manual...
Definition pixelpipe_cache.c:295
Pixelpipe cache for storing intermediate results in the pixelpipe.
unsigned __int64 uint64_t
Definition strptime.c:71
Definition pixelpipe_cache.c:385
size_t size
Definition pixelpipe_cache.c:387
void * data
Definition pixelpipe_cache.c:386
Definition pixelpipe_cache.c:122
int64_t max_age
Definition pixelpipe_cache.c:123
dt_pixel_cache_entry_t * cache_entry
Definition pixelpipe_cache.c:125
uint64_t hash
Definition pixelpipe_cache.c:124
struct dt_dev_pixelpipe_cache_t * pixelpipe_cache
Definition darktable.h:556
int32_t unmuted
Definition darktable.h:526
Definition pixelpipe_cache.h:40
size_t current_memory
Definition pixelpipe_cache.h:45
GHashTable * entries
Definition pixelpipe_cache.h:41
dt_pthread_mutex_t lock
Definition pixelpipe_cache.h:46
size_t max_memory
Definition pixelpipe_cache.h:44
uint64_t queries
Definition pixelpipe_cache.h:42
uint64_t hits
Definition pixelpipe_cache.h:43
Definition develop/format.h:36
Definition pixelpipe_cache.c:29
uint64_t hash
Definition pixelpipe_cache.c:30
gboolean auto_destroy
Definition pixelpipe_cache.c:39
dt_atomic_int refcount
Definition pixelpipe_cache.c:37
void * data
Definition pixelpipe_cache.c:31
dt_iop_buffer_dsc_t dsc
Definition pixelpipe_cache.c:33
size_t size
Definition pixelpipe_cache.c:32
int64_t age
Definition pixelpipe_cache.c:34
dt_pthread_rwlock_t lock
Definition pixelpipe_cache.c:38
char * name
Definition pixelpipe_cache.c:35
int id
Definition pixelpipe_cache.c:36
#define dt_alloc_align(B)
Definition tests/cache.c:22
#define MIN(a, b)
Definition thinplate.c:23
#define MAX(a, b)
Definition thinplate.c:20