[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [31421] branches/particles-2010/source/ blender/nodes/intern/node_tree_simulation.c: Modified the job search priorities: Instead of just taking the right-most job available, jobs with a lower start index are now preferred ( with the node level as a secondary order).

Lukas Toenne lukas.toenne at googlemail.com
Tue Aug 17 16:48:03 CEST 2010


Revision: 31421
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=31421
Author:   lukastoenne
Date:     2010-08-17 16:48:03 +0200 (Tue, 17 Aug 2010)

Log Message:
-----------
Modified the job search priorities: Instead of just taking the right-most job available, jobs with a lower start index are now preferred (with the node level as a secondary order). This ensures that jobs don't generate the full data set on their outputs before others nodes get a chance to process it, so data does not pile up unnecessarily. The "lower start index first" rule is arbitrary, any other order would be just as good.

Modified Paths:
--------------
    branches/particles-2010/source/blender/nodes/intern/node_tree_simulation.c

Modified: branches/particles-2010/source/blender/nodes/intern/node_tree_simulation.c
===================================================================
--- branches/particles-2010/source/blender/nodes/intern/node_tree_simulation.c	2010-08-17 14:32:14 UTC (rev 31420)
+++ branches/particles-2010/source/blender/nodes/intern/node_tree_simulation.c	2010-08-17 14:48:03 UTC (rev 31421)
@@ -370,7 +370,7 @@
 /* Not threadsafe! ctx->mutex must be locked during this function! */
 static SimNodeJob *node_thread_find_job(SimNodeThreadContext *ctx)
 {
-	SimNodeJob *job=NULL;
+	SimNodeJob *job, *best_job=NULL;
 	SimNodeInstance *node;
 	int n;
 	
@@ -458,57 +458,31 @@
 		}
 		#endif
 		
-		/* starting at the right-most nodes helps making data freeable ASAP */
-//		printf("----------------------\n");
-		for (n=ctx->totnode-1, node=ctx->nodestack + ctx->totnode-1; n >= 0; --n, --node) {
-//			printf("node %s:\n", node->node->name);
+		for (n=0, node=ctx->nodestack; n < ctx->totnode; ++n, ++node) {
 			for (job=node->jobs.first; job; job = job->next) {
-				#if 0
-				{
-					printf("\tjob %d, ", job->input_start);
-					switch (job->state) {
-					case SIM_JOB_PREPARING:		printf("preparing"); break;
-					case SIM_JOB_READY:			printf("ready"); break;
-					case SIM_JOB_RUNNING:		printf("running"); break;
-					case SIM_JOB_SUSPENDED:		printf("suspended"); break;
-					case SIM_JOB_DONE:			printf("done"); break;
-					case SIM_JOB_CANCEL:		printf("cancel"); break;
+				if (best_job==NULL) {
+					if (job->state == SIM_JOB_READY || job->state == SIM_JOB_SUSPENDED)
+						best_job = job;
+				}
+				else {
+					if (job->input_start > best_job->input_start)
+						break;
+					else if (job->state == SIM_JOB_READY || (job->state == SIM_JOB_SUSPENDED && best_job->state == SIM_JOB_SUSPENDED)) {
+						best_job = job;
+						break;	/* following jobs have higher start index and would break anyway, just a little shortcut */
 					}
-					printf("\n");
 				}
-				#endif
-				if (job->state == SIM_JOB_READY) {
-					if (job->node->node->typeinfo->sim_initjobfunc)
-						job->node->node->typeinfo->sim_initjobfunc(job);
-					job->state = SIM_JOB_RUNNING;
-					++ctx->active;
-					break;
-				}
-				else if (job->state == SIM_JOB_SUSPENDED) {
-					job->state = SIM_JOB_RUNNING;
-					++ctx->active;
-					break;
-				}
 			}
-			if (job!=NULL)
-				break;
 		}
-		#if 0
-		if (job != NULL)
-			printf("chose job for node %s: start=%d\n", job->node->node->name, job->input_start);
-		else
-			printf("no job available\n");
-		printf("active==%d\n", ctx->active);
-		printf("----------------------\n");
-		#endif
 		
-		if (job == NULL && ctx->active > 0)
+		
+		if (best_job == NULL && ctx->active > 0)
 			pthread_cond_wait(&ctx->cond, &ctx->mutex);
 		else
 			break;
 	}
 	
-	return job;
+	return best_job;
 }
 
 /* Not threadsafe! ctx->mutex must be locked during this function! */
@@ -787,9 +761,14 @@
 		pthread_mutex_lock(&ctx->mutex);
 		job = node_thread_find_job(ctx);
 		if (job != NULL) {
+			if (job->state == SIM_JOB_READY && job->node->node->typeinfo->sim_initjobfunc)
+				job->node->node->typeinfo->sim_initjobfunc(job);
+			job->state = SIM_JOB_RUNNING;
+			++ctx->active;
+			
 			pthread_mutex_unlock(&ctx->mutex);	/* unlock mutex during job execution */
+			
 			#if 0
-			/* ========= DEBUG ========= */
 			{
 				int i;
 				printf("=============================\n");
@@ -817,7 +796,6 @@
 				}
 				printf("=============================\n");
 			}
-			/* ========================= */
 			#endif
 			
 			if (job->node->node->typeinfo->sim_execfunc)
@@ -826,7 +804,6 @@
 				suspend = NODE_EXEC_FINISHED;
 			
 			#if 0
-			/* ========= DEBUG ========= */
 			{
 				int i, k;
 				SimNodeBatch *batch;
@@ -863,7 +840,6 @@
 				}
 				printf("............................\n");
 			}
-			/* ========================= */
 			#endif
 
 			pthread_mutex_lock(&ctx->mutex);





More information about the Bf-blender-cvs mailing list