[Bf-blender-cvs] [f0cf15b5c6] master: Task scheduler: Remove counter of done tasks

Sergey Sharybin noreply at git.blender.org
Wed Mar 1 12:49:23 CET 2017


Commit: f0cf15b5c68a1332707fe88985d21e238736ab40
Author: Sergey Sharybin
Date:   Wed Mar 1 12:45:51 2017 +0100
Branches: master
https://developer.blender.org/rBf0cf15b5c68a1332707fe88985d21e238736ab40

Task scheduler: Remove counter of done tasks

This was only used for progress report, and it's wrong because:

- Pool might in theory be re-used by different tasks
- We should not make any decision based on scheduling stats

Proper way is to take care of progress by the task itself.

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

M	source/blender/blenlib/BLI_task.h
M	source/blender/blenlib/intern/task.c
M	source/blender/render/CMakeLists.txt
M	source/blender/render/intern/source/volume_precache.c

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

diff --git a/source/blender/blenlib/BLI_task.h b/source/blender/blenlib/BLI_task.h
index 967e0be6d0..08b9629610 100644
--- a/source/blender/blenlib/BLI_task.h
+++ b/source/blender/blenlib/BLI_task.h
@@ -113,9 +113,6 @@ void *BLI_task_pool_userdata(TaskPool *pool);
 /* optional mutex to use from run function */
 ThreadMutex *BLI_task_pool_user_mutex(TaskPool *pool);
 
-/* number of tasks done, for stats, don't use this to make decisions */
-size_t BLI_task_pool_tasks_done(TaskPool *pool);
-
 /* Parallel for routines */
 typedef void (*TaskParallelRangeFunc)(void *userdata, const int iter);
 typedef void (*TaskParallelRangeFuncEx)(void *userdata, void *userdata_chunk, const int iter, const int thread_id);
diff --git a/source/blender/blenlib/intern/task.c b/source/blender/blenlib/intern/task.c
index fc2d9674c2..c4761e9f7e 100644
--- a/source/blender/blenlib/intern/task.c
+++ b/source/blender/blenlib/intern/task.c
@@ -106,7 +106,6 @@ struct TaskPool {
 	TaskScheduler *scheduler;
 
 	volatile size_t num;
-	volatile size_t done;
 	size_t num_threads;
 	size_t currently_running_tasks;
 	ThreadMutex num_mutex;
@@ -238,7 +237,6 @@ static void task_pool_num_decrease(TaskPool *pool, size_t done)
 
 	pool->num -= done;
 	atomic_sub_and_fetch_z(&pool->currently_running_tasks, done);
-	pool->done += done;
 
 	if (pool->num == 0)
 		BLI_condition_notify_all(&pool->num_cond);
@@ -504,7 +502,6 @@ static TaskPool *task_pool_create_ex(TaskScheduler *scheduler, void *userdata, c
 
 	pool->scheduler = scheduler;
 	pool->num = 0;
-	pool->done = 0;
 	pool->num_threads = 0;
 	pool->currently_running_tasks = 0;
 	pool->do_cancel = false;
@@ -743,11 +740,6 @@ ThreadMutex *BLI_task_pool_user_mutex(TaskPool *pool)
 	return &pool->user_mutex;
 }
 
-size_t BLI_task_pool_tasks_done(TaskPool *pool)
-{
-	return pool->done;
-}
-
 /* Parallel range routines */
 
 /**
diff --git a/source/blender/render/CMakeLists.txt b/source/blender/render/CMakeLists.txt
index 9e40ab02ee..569b207c96 100644
--- a/source/blender/render/CMakeLists.txt
+++ b/source/blender/render/CMakeLists.txt
@@ -35,6 +35,7 @@ set(INC
 	../makesdna
 	../makesrna
 	../physics
+	../../../intern/atomic
 	../../../intern/guardedalloc
 	../../../intern/mikktspace
 	../../../intern/smoke/extern
diff --git a/source/blender/render/intern/source/volume_precache.c b/source/blender/render/intern/source/volume_precache.c
index 5377d0eba0..752a9df0b7 100644
--- a/source/blender/render/intern/source/volume_precache.c
+++ b/source/blender/render/intern/source/volume_precache.c
@@ -60,6 +60,8 @@
 #include "volumetric.h"
 #include "volume_precache.h"
 
+#include "atomic_ops.h"
+
 
 /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
 /* defined in pipeline.c, is hardcopy of active dynamic allocated Render */
@@ -509,7 +511,8 @@ static void *vol_precache_part_test(void *data)
  */
 typedef struct VolPrecacheState {
 	double lasttime;
-	int totparts;
+	unsigned int doneparts;
+	unsigned int totparts;
 } VolPrecacheState;
 
 static void vol_precache_part(TaskPool * __restrict pool, void *taskdata, int UNUSED(threadid))
@@ -574,13 +577,15 @@ static void vol_precache_part(TaskPool * __restrict pool, void *taskdata, int UN
 		}
 	}
 
+	unsigned int doneparts = atomic_add_and_fetch_u(&state->doneparts, 1);
+
 	time = PIL_check_seconds_timer();
 	if (time - state->lasttime > 1.0) {
 		ThreadMutex *mutex = BLI_task_pool_user_mutex(pool);
 
 		if (BLI_mutex_trylock(mutex)) {
 			char str[64];
-			float ratio = (float)BLI_task_pool_tasks_done(pool)/(float)state->totparts;
+			float ratio = (float)doneparts/(float)state->totparts;
 			BLI_snprintf(str, sizeof(str), IFACE_("Precaching volume: %d%%"), (int)(100.0f * ratio));
 			re->i.infostr = str;
 			re->stats_draw(re->sdh, &re->i);
@@ -631,6 +636,7 @@ static void precache_launch_parts(Render *re, RayObject *tree, ShadeInput *shi,
 	
 	/* setup task scheduler */
 	memset(&state, 0, sizeof(state));
+	state.doneparts = 0;
 	state.totparts = parts[0]*parts[1]*parts[2];
 	state.lasttime = PIL_check_seconds_timer();




More information about the Bf-blender-cvs mailing list