[Bf-blender-cvs] [6c8e34e] asset-experiments: Filebrowser internal listing & UUIDs: simpler & safer UUIDs generation.
Bastien Montagne
noreply at git.blender.org
Fri Jun 19 14:34:19 CEST 2015
Commit: 6c8e34e59b8d4a95861d486c21df50591e2fe165
Author: Bastien Montagne
Date: Fri Jun 19 14:31:00 2015 +0200
Branches: asset-experiments
https://developer.blender.org/rB6c8e34e59b8d4a95861d486c21df50591e2fe165
Filebrowser internal listing & UUIDs: simpler & safer UUIDs generation.
Instead of computing MD5sum of paths, just use incremental UUIDs!
There meaning and lifetime for internal listing is very limited anyway,
they shall only be unique for a given listing.
Note about using atomic op here: did it because it's nice use case,
not sure it's worth adding atomic stuff to /editors area though?
===================================================================
M source/blender/editors/space_file/CMakeLists.txt
M source/blender/editors/space_file/SConscript
M source/blender/editors/space_file/filelist.c
===================================================================
diff --git a/source/blender/editors/space_file/CMakeLists.txt b/source/blender/editors/space_file/CMakeLists.txt
index 4c33499..56f2754 100644
--- a/source/blender/editors/space_file/CMakeLists.txt
+++ b/source/blender/editors/space_file/CMakeLists.txt
@@ -30,6 +30,7 @@ set(INC
../../makesrna
../../render/extern/include
../../windowmanager
+ ../../../../intern/atomic
../../../../intern/guardedalloc
../../../../intern/glew-mx
)
diff --git a/source/blender/editors/space_file/SConscript b/source/blender/editors/space_file/SConscript
index 85c3e07..62e8f5d 100644
--- a/source/blender/editors/space_file/SConscript
+++ b/source/blender/editors/space_file/SConscript
@@ -29,6 +29,7 @@ Import ('env')
sources = env.Glob('*.c')
incs = [
+ '#/intern/atomic',
'#/intern/guardedalloc',
env['BF_GLEW_INC'],
'#/intern/glew-mx',
diff --git a/source/blender/editors/space_file/filelist.c b/source/blender/editors/space_file/filelist.c
index 54a0a72..76f7d6f 100644
--- a/source/blender/editors/space_file/filelist.c
+++ b/source/blender/editors/space_file/filelist.c
@@ -89,6 +89,8 @@
#include "UI_resources.h"
#include "UI_interface_icons.h"
+#include "atomic_ops.h"
+
#include "filelist.h"
@@ -219,9 +221,10 @@ typedef struct FileListInternEntry {
} FileListInternEntry;
typedef struct FileListIntern {
- /* XXX This will be reworked to keep 'all entries' storage to a minimum memory space! */
ListBase entries; /* FileListInternEntry items. */
FileListInternEntry **filtered;
+
+ char curr_uuid[16]; /* Used to generate uuid during internal listing. */
} FileListIntern;
#define FILELIST_ENTRYCACHESIZE_DEFAULT 1024 /* Keep it a power of two! */
@@ -2399,9 +2402,12 @@ static void filelist_readjob_do(
BLI_join_dirfile(dir, sizeof(dir), subdir, entry->relpath);
BLI_cleanup_file(root, dir);
- /* We use the mere md5sum of path as entry UUID here.
- * entry->uuid is 16 bytes len, so we can use it directly! */
- BLI_hash_md5_buffer(dir, strlen(dir), entry->uuid);
+ /* Generate our entry uuid. Abusing uuid as an uint64, shall be more than enough here,
+ * things would crash way before we overflow that counter!
+ * Using an atomic operation to avoid having to lock thread...
+ * Note that we do not really need this here currently, since there is a single listing thread, but better
+ * remain consistent about threading! */
+ *((uint64_t *)entry->uuid) = atomic_add_uint64((uint64_t *)filelist->filelist_intern.curr_uuid, 1);
BLI_path_rel(dir, root);
/* Only thing we change in direntry here, so we need to free it first. */
@@ -2496,16 +2502,19 @@ static void filelist_readjob_startjob(void *flrjv, short *stop, short *do_update
flrj->tmp_filelist = MEM_dupallocN(flrj->filelist);
- BLI_mutex_unlock(&flrj->lock);
-
BLI_listbase_clear(&flrj->tmp_filelist->filelist.entries);
flrj->tmp_filelist->filelist.nbr_entries = 0;
+
flrj->tmp_filelist->filelist_intern.filtered = NULL;
BLI_listbase_clear(&flrj->tmp_filelist->filelist_intern.entries);
+ memset(flrj->tmp_filelist->filelist_intern.curr_uuid, 0, sizeof(flrj->tmp_filelist->filelist_intern.curr_uuid));
+
flrj->tmp_filelist->libfiledata = NULL;
- memset(&flrj->tmp_filelist->filelist_cache, 0, sizeof(FileListEntryCache));
+ memset(&flrj->tmp_filelist->filelist_cache, 0, sizeof(flrj->tmp_filelist->filelist_cache));
flrj->tmp_filelist->selection_state = NULL;
+ BLI_mutex_unlock(&flrj->lock);
+
flrj->tmp_filelist->read_jobf(flrj->tmp_filelist, flrj->main_name, stop, do_update, progress, &flrj->lock);
}
More information about the Bf-blender-cvs
mailing list