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>2013-08-19 14:02:18 +0400
committerSergey Sharybin <sergey.vfx@gmail.com>2013-08-19 14:02:18 +0400
commit59dfb05c72a6cbbeed6e545488e3e4fe9f25d061 (patch)
tree300915f1ac895092f753f8d8f9497bea3fdca5da /source/blender/blenkernel/intern/font.c
parent6bdff7e2ad27bd38ee8c419bc66ea20a95fa24b3 (diff)
Make fonts safe(r) for threading
Getting vfont data wasn't safe for threading, because it was modifying font data which is in bmain and could be shared by multiple objects. For now made it so getting vfont uses critical section, meaning vfont->data is initializing from inside a locked mutex. -- svn merge -r58168:58169 ^/branches/soc-2013-depsgraph_mt
Diffstat (limited to 'source/blender/blenkernel/intern/font.c')
-rw-r--r--source/blender/blenkernel/intern/font.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/source/blender/blenkernel/intern/font.c b/source/blender/blenkernel/intern/font.c
index 9700066be94..c899ae1f16c 100644
--- a/source/blender/blenkernel/intern/font.c
+++ b/source/blender/blenkernel/intern/font.c
@@ -1,4 +1,5 @@
/*
+
* ***** BEGIN GPL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
@@ -41,6 +42,7 @@
#include "BLI_math.h"
#include "BLI_blenlib.h"
+#include "BLI_threads.h"
#include "BLI_vfontdata.h"
#include "BLI_utildefines.h"
@@ -59,6 +61,7 @@
#include "BKE_curve.h"
#include "BKE_displist.h"
+static ThreadMutex vfont_mutex = BLI_MUTEX_INITIALIZER;
/* The vfont code */
void BKE_vfont_free_data(struct VFont *vfont)
@@ -138,6 +141,18 @@ static VFontData *vfont_get_data(Main *bmain, VFont *vfont)
if (!vfont->data) {
PackedFile *pf;
+ BLI_mutex_lock(&vfont_mutex);
+
+ if (vfont->data) {
+ /* Check data again, since it might have been already
+ * initialized from other thread (previous check is
+ * not accurate or threading, just prevents unneeded
+ * lock if all the data is here for sure).
+ */
+ BLI_mutex_unlock(&vfont_mutex);
+ return vfont->data;
+ }
+
if (BKE_vfont_is_builtin(vfont)) {
pf = get_builtin_packedfile();
}
@@ -175,8 +190,10 @@ static VFontData *vfont_get_data(Main *bmain, VFont *vfont)
freePackedFile(pf);
}
}
+
+ BLI_mutex_unlock(&vfont_mutex);
}
-
+
return vfont->data;
}