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...
This commit is contained in:
Bastien Montagne
2015-09-15 12:51:13 +02:00
parent 0c2be4d8e8
commit 860e25fe29

View File

@@ -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;