Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender')
-rw-r--r--source/blender/blenkernel/BKE_cachefile.h2
-rw-r--r--source/blender/blenkernel/intern/cachefile.c20
-rw-r--r--source/blender/blenloader/intern/readfile.c2
-rw-r--r--source/blender/makesdna/DNA_cachefile_types.h1
4 files changed, 25 insertions, 0 deletions
diff --git a/source/blender/blenkernel/BKE_cachefile.h b/source/blender/blenkernel/BKE_cachefile.h
index 51b161f1a06..7a9744ef9d6 100644
--- a/source/blender/blenkernel/BKE_cachefile.h
+++ b/source/blender/blenkernel/BKE_cachefile.h
@@ -38,6 +38,8 @@ struct CacheFile;
struct Main;
struct Scene;
+void BKE_cachefiles_init(void);
+
void *BKE_cachefile_add(struct Main *bmain, const char *name);
void BKE_cachefile_init(struct CacheFile *cache_file);
diff --git a/source/blender/blenkernel/intern/cachefile.c b/source/blender/blenkernel/intern/cachefile.c
index 16f263791db..502f1d53ab2 100644
--- a/source/blender/blenkernel/intern/cachefile.c
+++ b/source/blender/blenkernel/intern/cachefile.c
@@ -35,6 +35,7 @@
#include "BLI_listbase.h"
#include "BLI_path_util.h"
#include "BLI_string.h"
+#include "BLI_threads.h"
#include "BLI_utildefines.h"
#include "BKE_animsys.h"
@@ -48,6 +49,13 @@
# include "ABC_alembic.h"
#endif
+static SpinLock spin;
+
+void BKE_cachefiles_init(void)
+{
+ BLI_spin_init(&spin);
+}
+
void *BKE_cachefile_add(Main *bmain, const char *name)
{
CacheFile *cache_file = BKE_libblock_alloc(bmain, ID_CF, name);
@@ -65,6 +73,7 @@ void BKE_cachefile_init(CacheFile *cache_file)
cache_file->frame = 0.0f;
cache_file->is_sequence = false;
cache_file->scale = 1.0f;
+ cache_file->handle_mutex = BLI_mutex_alloc();
}
/** Free (or release) any data used by this cachefile (does not free the cachefile itself). */
@@ -76,6 +85,7 @@ void BKE_cachefile_free(CacheFile *cache_file)
ABC_free_handle(cache_file->handle);
#endif
+ BLI_mutex_free(cache_file->handle_mutex);
BLI_freelistN(&cache_file->object_paths);
}
@@ -114,9 +124,19 @@ void BKE_cachefile_reload(const Main *bmain, CacheFile *cache_file)
void BKE_cachefile_ensure_handle(const Main *bmain, CacheFile *cache_file)
{
+ BLI_spin_lock(&spin);
+ if (cache_file->handle_mutex == NULL) {
+ cache_file->handle_mutex = BLI_mutex_alloc();
+ }
+ BLI_spin_unlock(&spin);
+
+ BLI_mutex_lock(cache_file->handle_mutex);
+
if (cache_file->handle == NULL) {
BKE_cachefile_reload(bmain, cache_file);
}
+
+ BLI_mutex_unlock(cache_file->handle_mutex);
}
void BKE_cachefile_update_frame(Main *bmain, Scene *scene, const float ctime, const float fps)
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 7d65dbc2e17..f5bfe1f4de6 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -2707,6 +2707,7 @@ static void lib_link_cachefiles(FileData *fd, Main *bmain)
BLI_listbase_clear(&cache_file->object_paths);
cache_file->handle = NULL;
+ cache_file->handle_mutex = NULL;
if (cache_file->adt) {
lib_link_animdata(fd, &cache_file->id, cache_file->adt);
@@ -2717,6 +2718,7 @@ static void lib_link_cachefiles(FileData *fd, Main *bmain)
static void direct_link_cachefile(FileData *fd, CacheFile *cache_file)
{
cache_file->handle = NULL;
+ cache_file->handle_mutex = NULL;
/* relink animdata */
cache_file->adt = newdataadr(fd, cache_file->adt);
diff --git a/source/blender/makesdna/DNA_cachefile_types.h b/source/blender/makesdna/DNA_cachefile_types.h
index 1cda0233aa8..dd47d63fc19 100644
--- a/source/blender/makesdna/DNA_cachefile_types.h
+++ b/source/blender/makesdna/DNA_cachefile_types.h
@@ -58,6 +58,7 @@ typedef struct CacheFile {
struct AnimData *adt;
struct AbcArchiveHandle *handle;
+ void *handle_mutex;
/* Paths of the objects inside of the Alembic archive referenced by this
* CacheFile. */