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-10-10 15:58:01 +0400
committerSergey Sharybin <sergey.vfx@gmail.com>2013-10-10 15:58:01 +0400
commit4bd40372769e9ebf078dadb0442366176e8990e6 (patch)
treef2b9aef273590b809a658df2072987261e96633c /source/creator
parent77a0b90cdf5d42b774f75b392aa0e3aeb7ed3452 (diff)
Lock-free memory allocator
Release builds will now use lock-free allocator by default without any internal locks happening. MemHead is also reduces to as minimum as it's possible. It still need to be size_t stored in a MemHead in order to make us keep track on memory we're requesting from the system, not memory which system is allocating. This is probably also faster than using a malloc's usable size function. Lock-free guarded allocator will say you whether all the blocks were freed, but wouldn't give you a list of unfreed blocks list. To have such a list use a --debug or --debug-memory command line arguments. Debug builds does have the same behavior as release builds. This is so tools like valgrind are not screwed up by guarded allocator as they're currently are. -- svn merge -r59941:59942 -r60072:60073 -r60093:60094 \ -r60095:60096 ^/branches/soc-2013-depsgraph_mt
Diffstat (limited to 'source/creator')
-rw-r--r--source/creator/creator.c43
1 files changed, 39 insertions, 4 deletions
diff --git a/source/creator/creator.c b/source/creator/creator.c
index a3bce79b6e7..1596fe5359c 100644
--- a/source/creator/creator.c
+++ b/source/creator/creator.c
@@ -300,6 +300,7 @@ static int print_help(int UNUSED(argc), const char **UNUSED(argv), void *data)
#ifdef WITH_LIBMV
BLI_argsPrintArgDoc(ba, "--debug-libmv");
#endif
+ BLI_argsPrintArgDoc(ba, "--debug-memory");
BLI_argsPrintArgDoc(ba, "--debug-jobs");
BLI_argsPrintArgDoc(ba, "--debug-python");
@@ -439,6 +440,12 @@ static int debug_mode_libmv(int UNUSED(argc), const char **UNUSED(argv), void *U
}
#endif
+static int debug_mode_memory(int UNUSED(argc), const char **UNUSED(argv), void *UNUSED(data))
+{
+ MEM_set_memory_debug();
+ return 0;
+}
+
static int set_debug_value(int argc, const char **argv, void *UNUSED(data))
{
if (argc > 1) {
@@ -1384,6 +1391,7 @@ static void setupArguments(bContext *C, bArgs *ba, SYS_SystemHandle *syshandle)
#ifdef WITH_LIBMV
BLI_argsAdd(ba, 1, NULL, "--debug-libmv", "\n\tEnable debug messages from libmv library", debug_mode_libmv, NULL);
#endif
+ BLI_argsAdd(ba, 1, NULL, "--debug-memory", "\n\tEnable fully guarded memory allocation and debugging", debug_mode_memory, NULL);
BLI_argsAdd(ba, 1, NULL, "--debug-value", "<value>\n\tSet debug value of <value> on startup\n", set_debug_value, NULL);
BLI_argsAdd(ba, 1, NULL, "--debug-jobs", "\n\tEnable time profiling for background jobs.", debug_mode_generic, (void *)G_DEBUG_JOBS);
@@ -1454,23 +1462,50 @@ int main(int argc, const char **UNUSED(argv_c)) /* Do not mess with const */
int main(int argc, const char **argv)
#endif
{
- bContext *C = CTX_create();
+ bContext *C;
SYS_SystemHandle syshandle;
#ifndef WITH_PYTHON_MODULE
bArgs *ba;
#endif
-#ifdef WIN32
+#ifdef WIN32 /* Win32 Unicode Args */
+ /* NOTE: cannot use guardedalloc malloc here, as it's not yet initialised
+ * (it depends on the args passed in, which is what we're getting here!)
+ */
wchar_t **argv_16 = CommandLineToArgvW(GetCommandLineW(), &argc);
+ char **argv = malloc(argc * sizeof(char *));
int argci = 0;
- char **argv = MEM_mallocN(argc * sizeof(char *), "argv array");
+
for (argci = 0; argci < argc; argci++) {
argv[argci] = alloc_utf_8_from_16(argv_16[argci], 0);
}
+
LocalFree(argv_16);
#endif
+ /* NOTE: Special exception for guarded allocator type switch:
+ * we need to perform switch from lock-free to fully
+ * guarded allocator before any allocation happened.
+ */
+ {
+ int i;
+ for (i = 0; i < argc; i++) {
+ if (STREQ(argv[i], "--debug") || STREQ(argv[i], "-d") ||
+ STREQ(argv[i], "--debug-memory"))
+ {
+ printf("Switching to fully guarded memory allocator.\n");
+ MEM_use_guarded_allocator();
+ break;
+ }
+ else if (STREQ(argv[i], "--")) {
+ break;
+ }
+ }
+ }
+
+ C = CTX_create();
+
#ifdef WITH_PYTHON_MODULE
#ifdef __APPLE__
environ = *_NSGetEnviron();
@@ -1641,7 +1676,7 @@ int main(int argc, const char **argv)
while (argci) {
free(argv[--argci]);
}
- MEM_freeN(argv);
+ free(argv);
argv = NULL;
#endif