diff options
Diffstat (limited to 'source/blender/imbuf/intern/cache.c')
-rw-r--r-- | source/blender/imbuf/intern/cache.c | 49 |
1 files changed, 29 insertions, 20 deletions
diff --git a/source/blender/imbuf/intern/cache.c b/source/blender/imbuf/intern/cache.c index 77e01d8ebef..23f0dd87b1a 100644 --- a/source/blender/imbuf/intern/cache.c +++ b/source/blender/imbuf/intern/cache.c @@ -22,12 +22,13 @@ #include "MEM_guardedalloc.h" +#include "BLI_utildefines.h" #include "BLI_ghash.h" #include "BLI_listbase.h" #include "BLI_memarena.h" #include "BLI_threads.h" -#include "BKE_utildefines.h" + #include "IMB_imbuf.h" #include "IMB_imbuf_types.h" @@ -82,40 +83,42 @@ typedef struct ImGlobalTileCache { int totthread; ThreadMutex mutex; + + int initialized; } ImGlobalTileCache; static ImGlobalTileCache GLOBAL_CACHE; /***************************** Hash Functions ********************************/ -static unsigned int imb_global_tile_hash(void *gtile_p) +static unsigned int imb_global_tile_hash(const void *gtile_p) { - ImGlobalTile *gtile= gtile_p; + const ImGlobalTile *gtile= gtile_p; return ((unsigned int)(intptr_t)gtile->ibuf)*769 + gtile->tx*53 + gtile->ty*97; } -static int imb_global_tile_cmp(void *a_p, void *b_p) +static int imb_global_tile_cmp(const void *a_p, const void *b_p) { - ImGlobalTile *a= a_p; - ImGlobalTile *b= b_p; + const ImGlobalTile *a= a_p; + const ImGlobalTile *b= b_p; if(a->ibuf == b->ibuf && a->tx == b->tx && a->ty == b->ty) return 0; else if(a->ibuf < b->ibuf || a->tx < b->tx || a->ty < b->ty) return -1; else return 1; } -static unsigned int imb_thread_tile_hash(void *ttile_p) +static unsigned int imb_thread_tile_hash(const void *ttile_p) { - ImThreadTile *ttile= ttile_p; + const ImThreadTile *ttile= ttile_p; return ((unsigned int)(intptr_t)ttile->ibuf)*769 + ttile->tx*53 + ttile->ty*97; } -static int imb_thread_tile_cmp(void *a_p, void *b_p) +static int imb_thread_tile_cmp(const void *a_p, const void *b_p) { - ImThreadTile *a= a_p; - ImThreadTile *b= b_p; + const ImThreadTile *a= a_p; + const ImThreadTile *b= b_p; if(a->ibuf == b->ibuf && a->tx == b->tx && a->ty == b->ty) return 0; else if(a->ibuf < b->ibuf || a->tx < b->tx || a->ty < b->ty) return -1; @@ -203,6 +206,8 @@ void imb_tile_cache_init(void) /* initialize for one thread, for places that access textures outside of rendering (displace modifier, painting, ..) */ IMB_tile_cache_params(0, 0); + + GLOBAL_CACHE.initialized = 1; } void imb_tile_cache_exit(void) @@ -210,19 +215,23 @@ void imb_tile_cache_exit(void) ImGlobalTile *gtile; int a; - for(gtile=GLOBAL_CACHE.tiles.first; gtile; gtile=gtile->next) - imb_global_cache_tile_unload(gtile); + if(GLOBAL_CACHE.initialized) { + for(gtile=GLOBAL_CACHE.tiles.first; gtile; gtile=gtile->next) + imb_global_cache_tile_unload(gtile); + + for(a=0; a<GLOBAL_CACHE.totthread; a++) + imb_thread_cache_exit(&GLOBAL_CACHE.thread_cache[a]); - for(a=0; a<GLOBAL_CACHE.totthread; a++) - imb_thread_cache_exit(&GLOBAL_CACHE.thread_cache[a]); + if(GLOBAL_CACHE.memarena) + BLI_memarena_free(GLOBAL_CACHE.memarena); - if(GLOBAL_CACHE.memarena) - BLI_memarena_free(GLOBAL_CACHE.memarena); + if(GLOBAL_CACHE.tilehash) + BLI_ghash_free(GLOBAL_CACHE.tilehash, NULL, NULL); - if(GLOBAL_CACHE.tilehash) - BLI_ghash_free(GLOBAL_CACHE.tilehash, NULL, NULL); + BLI_mutex_end(&GLOBAL_CACHE.mutex); - BLI_mutex_end(&GLOBAL_CACHE.mutex); + memset(&GLOBAL_CACHE, 0, sizeof(ImGlobalTileCache)); + } } /* presumed to be called when no threads are running */ |