[Bf-blender-cvs] [860e25f] master: Fix T46093: Thumbnails/previews of materials/textures not displaying in Blender filebrowser when only one thread is available.

Bastien Montagne noreply at git.blender.org
Tue Sep 15 13:59:23 CEST 2015


Commit: 860e25fe29c3f6732860c23dccb1f4813d4e387e
Author: Bastien Montagne
Date:   Tue Sep 15 12:51:13 2015 +0200
Branches: master
https://developer.blender.org/rB860e25fe29c3f6732860c23dccb1f4813d4e387e

Fix T46093: Thumbnails/previews of materials/textures not displaying in Blender filebrowser when only one thread is available.

Using the global scheduler here is not a really good idea - `filelist_cache_previewf()` is not a short task
that run once, but it's a loop that keeps cheking for work in a TODO queue. This means it won't quickly allow other tasks
to start, so it should not be in the global scheduler.

In fact, asynchronous tasks (that is, tasks that will live for quite a bit of time, and often sleep a lot) should never use
global scheduler, they would steal computing resources from heavy-duty, short-time living ones - and possibly even completely
stall threaded tasks (if all worker threads are executing long-life tasks...).

We could probably even completely bypass the scheduler/task thing here (and directly use threads), but it does not have
that much of an over-head, and still offers easy handling of threading stuff...

===================================================================

M	source/blender/editors/space_file/filelist.c

===================================================================

diff --git a/source/blender/editors/space_file/filelist.c b/source/blender/editors/space_file/filelist.c
index a4fe795..0d1aff0 100644
--- a/source/blender/editors/space_file/filelist.c
+++ b/source/blender/editors/space_file/filelist.c
@@ -250,6 +250,7 @@ typedef struct FileListEntryCache {
 	GHash *uuids;
 
 	/* Previews handling. */
+	TaskScheduler *previews_scheduler;
 	TaskPool *previews_pool;
 	ThreadQueue *previews_todo;
 	ThreadQueue *previews_done;
@@ -1100,10 +1101,11 @@ static void filelist_cache_previewf(TaskPool *pool, void *taskdata, int UNUSED(t
 static void filelist_cache_preview_ensure_running(FileListEntryCache *cache)
 {
 	if (!cache->previews_pool) {
-		TaskScheduler *scheduler = BLI_task_scheduler_get();
+		TaskScheduler *scheduler;
 		TaskPool *pool;
-		int num_tasks = max_ii(2, BLI_system_thread_count() / 2);
+		int num_tasks = max_ii(1, (BLI_system_thread_count() / 2) + 1);
 
+		scheduler = cache->previews_scheduler = BLI_task_scheduler_create(num_tasks + 1);
 		pool = cache->previews_pool = BLI_task_pool_create(scheduler, NULL);
 		cache->previews_todo = BLI_thread_queue_init();
 		cache->previews_done = BLI_thread_queue_init();
@@ -1150,6 +1152,8 @@ static void filelist_cache_previews_free(FileListEntryCache *cache, const bool s
 		BLI_thread_queue_free(cache->previews_done);
 		BLI_thread_queue_free(cache->previews_todo);
 		BLI_task_pool_free(cache->previews_pool);
+		BLI_task_scheduler_free(cache->previews_scheduler);
+		cache->previews_scheduler = NULL;
 		cache->previews_pool = NULL;
 		cache->previews_todo = NULL;
 		cache->previews_done = NULL;




More information about the Bf-blender-cvs mailing list