From 8791eaa5b0548e93634fe6287a42815a8469e406 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Fri, 14 Sep 2012 14:55:59 +0000 Subject: Movie cache: made it thread safe to operate with memory limitor Movie cache is using global memory limitor, which isn't thread safe in some of operations, so it required to add mutex around limitor operations in movie cache. It's probably could be solved in a way with less locks involved by using different limitor for different areas (like use own limitor for clips, own limitor for sequencer and so), but that wouldn't be so easy to control overall memory usage. -- svn merge -r50125:50126 ^/branches/soc-2011-tomato --- source/blender/imbuf/intern/moviecache.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'source') diff --git a/source/blender/imbuf/intern/moviecache.c b/source/blender/imbuf/intern/moviecache.c index f91f648bb7b..78a989ad48f 100644 --- a/source/blender/imbuf/intern/moviecache.c +++ b/source/blender/imbuf/intern/moviecache.c @@ -41,6 +41,7 @@ #include "BLI_utildefines.h" #include "BLI_ghash.h" #include "BLI_mempool.h" +#include "BLI_threads.h" #include "IMB_moviecache.h" @@ -58,6 +59,7 @@ #endif static MEM_CacheLimiterC *limitor = NULL; +static pthread_mutex_t limitor_lock = BLI_MUTEX_INITIALIZER; typedef struct MovieCache { char name[64]; @@ -335,16 +337,20 @@ void IMB_moviecache_put(MovieCache *cache, void *userkey, ImBuf *ibuf) BLI_ghash_remove(cache->hash, key, moviecache_keyfree, moviecache_valfree); BLI_ghash_insert(cache->hash, key, item); - item->c_handle = MEM_CacheLimiter_insert(limitor, item); - if (cache->last_userkey) { memcpy(cache->last_userkey, userkey, cache->keysize); } + BLI_mutex_lock(&limitor_lock); + + item->c_handle = MEM_CacheLimiter_insert(limitor, item); + MEM_CacheLimiter_ref(item->c_handle); MEM_CacheLimiter_enforce_limits(limitor); MEM_CacheLimiter_unref(item->c_handle); + BLI_mutex_unlock(&limitor_lock); + /* cache limiter can't remove unused keys which points to destoryed values */ check_unused_keys(cache); @@ -365,7 +371,10 @@ ImBuf *IMB_moviecache_get(MovieCache *cache, void *userkey) if (item) { if (item->ibuf) { + BLI_mutex_lock(&limitor_lock); MEM_CacheLimiter_touch(item->c_handle); + BLI_mutex_unlock(&limitor_lock); + IMB_refImBuf(item->ibuf); return item->ibuf; -- cgit v1.2.3