diff --git a/src/common/cache.c b/src/common/cache.c index f478cf126311..83a2652c1a79 100644 --- a/src/common/cache.c +++ b/src/common/cache.c @@ -48,7 +48,7 @@ typedef struct dt_cache_bucket_t int16_t write; // number of writers (0 or 1) int32_t lru; // for garbage collection: lru list int32_t mru; - int32_t cost; // cost associated with this entry (such as byte size) + size_t cost; // cost associated with this entry (such as byte size) uint32_t hash; // hash of the element uint32_t key; // key of the element // due to alignment, we waste 32 bits here @@ -120,7 +120,7 @@ get_start_cacheline_bucket(const dt_cache_t *const cache, dt_cache_bucket_t *con static void add_cost(dt_cache_t *cache, - const int32_t cost) + const size_t cost) { __sync_fetch_and_add(&cache->cost, cost); } @@ -223,7 +223,7 @@ add_key_to_beginning_of_list( const uint32_t hash, const uint32_t key) { - int32_t cost = 1; + size_t cost = 1; if(cache->allocate) { // upgrade to a write lock in case the user requests it: @@ -263,7 +263,7 @@ add_key_to_end_of_list( const uint32_t key, dt_cache_bucket_t *const last_bucket) { - int32_t cost = 1; + size_t cost = 1; if(cache->allocate) { if(cache->allocate(cache->allocate_data, key, &cost, &free_bucket->data)) @@ -1096,7 +1096,7 @@ dt_cache_write_get(dt_cache_t *cache, const uint32_t key) } void -dt_cache_realloc(dt_cache_t *cache, const uint32_t key, const int32_t cost, void *data) +dt_cache_realloc(dt_cache_t *cache, const uint32_t key, const size_t cost, void *data) { // just to support different keys: const uint32_t hash = key; @@ -1118,7 +1118,7 @@ dt_cache_realloc(dt_cache_t *cache, const uint32_t key, const int32_t cost, void assert(compare_bucket->write == 1); assert(compare_bucket->read == 1); compare_bucket->data = data; - const int32_t cost_diff = cost - compare_bucket->cost; + const size_t cost_diff = cost - compare_bucket->cost; compare_bucket->cost = cost; add_cost(cache, cost_diff); dt_cache_unlock(&segment->lock); diff --git a/src/common/cache.h b/src/common/cache.h index 05a4c98f91e0..d1de98e948d7 100644 --- a/src/common/cache.h +++ b/src/common/cache.h @@ -45,7 +45,7 @@ typedef struct dt_cache_t // allocate should return != 0 if a write lock on alloc is needed. // this might be useful for cases where the allocation takes a lot of time and you don't want // the hashtable spinlocks to block and wait for it. - int32_t (*allocate)(void *userdata, const uint32_t key, int32_t *cost, void **payload); + int32_t (*allocate)(void *userdata, const uint32_t key, size_t *cost, void **payload); void (*cleanup) (void *userdata, const uint32_t key, void *payload); void *allocate_data; void *cleanup_data; @@ -64,7 +64,7 @@ void dt_cache_static_allocation(dt_cache_t *cache, uint8_t *buf, const uint32_t static inline void dt_cache_set_allocate_callback( dt_cache_t *cache, - int32_t (*allocate)(void*, const uint32_t, int32_t*, void**), + int32_t (*allocate)(void*, const uint32_t, size_t*, void**), void *allocate_data) { cache->allocate = allocate; @@ -115,7 +115,7 @@ void dt_cache_print(dt_cache_t *cache); void dt_cache_print_locked(dt_cache_t *cache); // replace data pointer, cleanup has to be done by the user. -void dt_cache_realloc(dt_cache_t *cache, const uint32_t key, const int32_t cost, void *data); +void dt_cache_realloc(dt_cache_t *cache, const uint32_t key, const size_t cost, void *data); // iterate over all currently contained data blocks. // not thread safe! only use this for init/cleanup! diff --git a/src/common/image_cache.c b/src/common/image_cache.c index 4af97746e7ce..7dc70199fbdc 100644 --- a/src/common/image_cache.c +++ b/src/common/image_cache.c @@ -27,7 +27,7 @@ #include int32_t -dt_image_cache_allocate(void *data, const uint32_t key, int32_t *cost, void **buf) +dt_image_cache_allocate(void *data, const uint32_t key, size_t *cost, void **buf) { dt_image_cache_t *c = (dt_image_cache_t *)data; const uint32_t hash = key; // == image id diff --git a/src/common/mipmap_cache.c b/src/common/mipmap_cache.c index 37c40b9bf6a6..fcf8ed992919 100644 --- a/src/common/mipmap_cache.c +++ b/src/common/mipmap_cache.c @@ -485,7 +485,7 @@ static void _init_f(float *buf, uint32_t *width, uint32_t *height, const uint3 static void _init_8(uint8_t *buf, uint32_t *width, uint32_t *height, const uint32_t imgid, const dt_mipmap_size_t size); static int32_t -scratchmem_allocate(void *data, const uint32_t key, int32_t *cost, void **buf) +scratchmem_allocate(void *data, const uint32_t key, size_t *cost, void **buf) { dt_mipmap_cache_one_t *c = (dt_mipmap_cache_one_t *)data; // slot is exactly aligned with encapsulated cache's position and already allocated @@ -494,7 +494,7 @@ scratchmem_allocate(void *data, const uint32_t key, int32_t *cost, void **buf) } int32_t -dt_mipmap_cache_allocate(void *data, const uint32_t key, int32_t *cost, void **buf) +dt_mipmap_cache_allocate(void *data, const uint32_t key, size_t *cost, void **buf) { dt_mipmap_cache_one_t *c = (dt_mipmap_cache_one_t *)data; // slot is exactly aligned with encapsulated cache's position and already allocated @@ -565,7 +565,7 @@ dt_mipmap_cache_alloc(dt_image_t *img, dt_mipmap_size_t size, dt_mipmap_cache_al // callback for the cache backend to initialize payload pointers int32_t -dt_mipmap_cache_allocate_dynamic(void *data, const uint32_t key, int32_t *cost, void **buf) +dt_mipmap_cache_allocate_dynamic(void *data, const uint32_t key, size_t *cost, void **buf) { dt_mipmap_cache_one_t *cache = (dt_mipmap_cache_one_t *)data; // for full image buffers