diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2012-09-14 18:55:59 +0400 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2012-09-14 18:55:59 +0400 |
commit | 8791eaa5b0548e93634fe6287a42815a8469e406 (patch) | |
tree | 0d3505d74589595b09a2ad695ad94f6e1de9aa99 /source | |
parent | cd4ffe496aa63e78b46f332ec24873cd0fce3061 (diff) |
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
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/imbuf/intern/moviecache.c | 13 |
1 files changed, 11 insertions, 2 deletions
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; |