[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [50126] branches/soc-2011-tomato/source/ blender/imbuf/intern/moviecache.c: Movie cache: made it thread safe to operate with memory limitor
Sergey Sharybin
sergey.vfx at gmail.com
Wed Aug 22 17:13:15 CEST 2012
Revision: 50126
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=50126
Author: nazgul
Date: 2012-08-22 15:13:14 +0000 (Wed, 22 Aug 2012)
Log Message:
-----------
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
bu 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.
Modified Paths:
--------------
branches/soc-2011-tomato/source/blender/imbuf/intern/moviecache.c
Modified: branches/soc-2011-tomato/source/blender/imbuf/intern/moviecache.c
===================================================================
--- branches/soc-2011-tomato/source/blender/imbuf/intern/moviecache.c 2012-08-22 15:10:07 UTC (rev 50125)
+++ branches/soc-2011-tomato/source/blender/imbuf/intern/moviecache.c 2012-08-22 15:13:14 UTC (rev 50126)
@@ -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];
@@ -334,16 +336,20 @@
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);
@@ -364,7 +370,10 @@
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;
More information about the Bf-blender-cvs
mailing list