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:
authorSergey Sharybin <sergey.vfx@gmail.com>2014-06-24 18:43:08 +0400
committerSergey Sharybin <sergey.vfx@gmail.com>2014-06-24 21:35:17 +0400
commit04648767fabda7d9461e32c89afcd806d0227547 (patch)
treee7297fca0b6d623892b9a08aea9bbb0b4bb025b0 /source/blender/blenkernel/intern/library.c
parentfc1040cc47594e2a68d120cf08c0c3c70fbc44d1 (diff)
Make main library safe(er) for the threaded usage
Added a lock to the Main which is getting acquired and released when modifying it's lists. Should not be any functional changes now, it just means Main is now considered safe without worrying about locks in the callee.
Diffstat (limited to 'source/blender/blenkernel/intern/library.c')
-rw-r--r--source/blender/blenkernel/intern/library.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c
index fe2d1481581..9a74edb03c9 100644
--- a/source/blender/blenkernel/intern/library.c
+++ b/source/blender/blenkernel/intern/library.c
@@ -747,12 +747,14 @@ void *BKE_libblock_alloc(Main *bmain, short type, const char *name)
id = alloc_libblock_notest(type);
if (id) {
+ BLI_spin_lock(&bmain->lock);
BLI_addtail(lb, id);
id->us = 1;
id->icon_id = 0;
*( (short *)id->name) = type;
new_id(lb, id, name);
/* alphabetic insertion: is in new_id */
+ BLI_spin_unlock(&bmain->lock);
}
DAG_id_type_tag(bmain, type);
return id;
@@ -881,10 +883,8 @@ static void animdata_dtar_clear_cb(ID *UNUSED(id), AnimData *adt, void *userdata
}
}
-void BKE_libblock_free_data(ID *id)
+void BKE_libblock_free_data(Main *bmain, ID *id)
{
- Main *bmain = G.main; /* should eventually be an arg */
-
if (id->properties) {
IDP_FreeProperty(id->properties);
MEM_freeN(id->properties);
@@ -1008,12 +1008,15 @@ void BKE_libblock_free_ex(Main *bmain, void *idv, bool do_id_user)
}
/* avoid notifying on removed data */
+ BLI_spin_lock(&bmain->lock);
+
if (free_notifier_reference_cb)
free_notifier_reference_cb(id);
BLI_remlink(lb, id);
- BKE_libblock_free_data(id);
+ BKE_libblock_free_data(bmain, id);
+ BLI_spin_unlock(&bmain->lock);
MEM_freeN(id);
}
@@ -1043,7 +1046,9 @@ void BKE_libblock_free_us(Main *bmain, void *idv) /* test users */
Main *BKE_main_new(void)
{
Main *bmain = MEM_callocN(sizeof(Main), "new main");
- bmain->eval_ctx = MEM_callocN(sizeof(EvaluationContext), "EvaluationContext");
+ bmain->eval_ctx = MEM_callocN(sizeof(EvaluationContext),
+ "EvaluationContext");
+ BLI_spin_init(&bmain->lock);
return bmain;
}
@@ -1106,6 +1111,7 @@ void BKE_main_free(Main *mainvar)
}
}
+ BLI_spin_end(&mainvar->lock);
MEM_freeN(mainvar->eval_ctx);
MEM_freeN(mainvar);
}